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..
84 $core_opts = HTML_FlexyFramework::get()->page->opts;
85 if (!empty($core_opts['init']) && empty($core_opts['base'])) {
86 die("--base=XXX must be set when using --init ");
94 function get($k = '',$opt)
105 if(empty($opt['source'])){
106 die("Missing Source directory for account json files! Try -f [JSON file path] \n");
109 if (!file_exists($opt['source'])) {
110 die("can not found account json file : {$opt['source']} \n");
113 $accounts = json_decode(file_get_contents($opt['source']),true);
115 DB_DataObject::factory('accnt')->importFromArray($this, $accounts);
120 if($k == 'curr_symbol'){
121 if(!empty($opt['base'])){
122 DB_DataObject::factory('curr_symbol')->setBase($this, $opt['base']);
126 if(!empty($opt['source'])){
128 if (!file_exists($opt['source'])) {
129 die("can not found currency json file : {$opt['source']} \n");
132 $currencies = json_decode(file_get_contents($opt['source']),true);
134 DB_DataObject::factory('curr_symbol')->importFromArray($this, $currencies);
138 die("Missing Base Currency or Source directory for Currency json files! Try -b [base currency] or -f [JSON file path]\n");
141 if($k == 'location'){
142 if(empty($opt['source'])){
143 die("Missing Source directory for location json file! Try -f [JSON file path] \n");
146 if (!file_exists($opt['source'])) {
147 die("can not found location json file : {$opt['source']} \n");
150 $locations = json_decode(file_get_contents($opt['source']),true);
152 DB_DataObject::factory('location')->importFromArray($this, $locations);
158 if(empty($opt['source'])){
159 die("Missing Source directory for terms json file! Try -f [JSON file path] \n");
162 if (!file_exists($opt['source'])) {
163 die("can not found terms json file : {$opt['source']} \n");
166 $terms = json_decode(file_get_contents($opt['source']),true);
168 DB_DataObject::factory('terms')->importFromArray($this, $terms);
174 $this->updateData($k);
181 function updateData($k='') {
182 //DB_DataObject::debugLevel(1);
183 $tables = empty($k) ? array(
185 // 'curr_symbol', //?? fixme
197 // 'location', //?? just check hat one exists.
201 $core_opts = HTML_FlexyFramework::get()->page->opts;
202 if (!empty($core_opts['init'])) {
203 DB_DataObject::factory('curr_symbol')->setBase($this, $core_opt['base']);
209 foreach($tables as $t) {
210 $cs = DB_DataObject::factory($t);
211 $cs->initDatabase($this);
215 // update data is called from main