5 * Setup the core values in the database
10 require_once 'Pman.php';
11 class Pman_Xtuple_UpdateDatabase extends Pman
14 static $cli_desc = "Update SQL - Beta";
16 static $cli_opts = array(
18 'desc' => 'Source directory for json files.',
28 'desc' => 'Base Currency',
36 'json-accnt' => array(
37 'desc' => 'Accounts JSON file',
43 'json-curr-symbol' => array(
44 'desc' => 'Currency Symbols JSON file',
51 'json-location' => array(
52 'desc' => 'Location JSON file',
58 'json-terms' => array(
59 'desc' => 'Terms JSON file',
72 $ff = HTML_FlexyFramework::get();
73 if (!empty($ff->cli)) {
80 // called to ensure options are correct.
81 // before any data is imported / started..
82 function checkOpts($opts)
84 $opts = HTML_FlexyFramework::get()->page->opts;
85 if (!empty($opts['init']) && empty($opts['base'])) {
86 die("--base=XXX must be set when using --init ");
89 foreach($opts as $o=>$v) {
90 if (preg_match('/^json-/', $o) || empty($v)) {
93 if (!file_exists($v)) {
94 die("File does not exist : OPTION --{$o} = {$v} \n");
100 function importFromArray($db, $file)
104 $data= json_decode(file_get_contents($file),true);
106 DB_DataObject::factory('$db')->importFromArray($this);
112 function get($k = '',$opt)
119 foreach($this->opts as $o=>$v) {
120 if (preg_match('/^json-/', $o) || empty($v)) {
123 $type = str_replace('_', '-', substr($o,6));
124 $this->importFromArray($type, $v);
131 $this->updateData($k);
138 function updateData($k='') {
139 //DB_DataObject::debugLevel(1);
140 $tables = empty($k) ? array(
142 // 'curr_symbol', //?? fixme
154 // 'location', //?? just check hat one exists.
158 $core_opts = HTML_FlexyFramework::get()->page->opts;
159 if (!empty($core_opts['init'])) {
160 DB_DataObject::factory('curr_symbol')->setBase($this, $core_opt['base']);
166 foreach($tables as $t) {
167 $cs = DB_DataObject::factory($t);
168 $cs->initDatabase($this);
172 // update data is called from main