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',
59 $ff = HTML_FlexyFramework::get();
60 if (!empty($ff->cli)) {
67 // called to ensure options are correct.
68 // before any data is imported / started..
71 $core_opts = HTML_FlexyFramework::get()->page->opts;
72 if (!empty($core_opts['init']) && empty($core_opts['base'])) {
73 die("--base=XXX must be set when using --init ");
81 function get($k = '',$opt)
92 if(empty($opt['source'])){
93 die("Missing Source directory for account json files! Try -f [JSON file path] \n");
96 if (!file_exists($opt['source'])) {
97 die("can not found account json file : {$opt['source']} \n");
100 $accounts = json_decode(file_get_contents($opt['source']),true);
102 DB_DataObject::factory('accnt')->importFromArray($this, $accounts);
107 if($k == 'curr_symbol'){
108 if(!empty($opt['base'])){
109 DB_DataObject::factory('curr_symbol')->setBase($this, $opt['base']);
113 if(!empty($opt['source'])){
115 if (!file_exists($opt['source'])) {
116 die("can not found currency json file : {$opt['source']} \n");
119 $currencies = json_decode(file_get_contents($opt['source']),true);
121 DB_DataObject::factory('curr_symbol')->importFromArray($this, $currencies);
125 die("Missing Base Currency or Source directory for Currency json files! Try -b [base currency] or -f [JSON file path]\n");
128 if($k == 'location'){
129 if(empty($opt['source'])){
130 die("Missing Source directory for location json file! Try -f [JSON file path] \n");
133 if (!file_exists($opt['source'])) {
134 die("can not found location json file : {$opt['source']} \n");
137 $locations = json_decode(file_get_contents($opt['source']),true);
139 DB_DataObject::factory('location')->importFromArray($this, $locations);
145 if(empty($opt['source'])){
146 die("Missing Source directory for terms json file! Try -f [JSON file path] \n");
149 if (!file_exists($opt['source'])) {
150 die("can not found terms json file : {$opt['source']} \n");
153 $terms = json_decode(file_get_contents($opt['source']),true);
155 DB_DataObject::factory('terms')->importFromArray($this, $terms);
161 $this->updateData($k);
168 function updateData($k='') {
169 //DB_DataObject::debugLevel(1);
170 $tables = empty($k) ? array(
172 // 'curr_symbol', //?? fixme
184 // 'location', //?? just check hat one exists.
188 $core_opts = HTML_FlexyFramework::get()->page->opts;
189 if (!empty($core_opts['init'])) {
190 DB_DataObject::factory('curr_symbol')->setBase($this, $core_opt['base']);
196 foreach($tables as $t) {
197 $cs = DB_DataObject::factory($t);
198 $cs->initDatabase($this);
202 // update data is called from main