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)
101 foreach($this->opts as $o=>$v) {
102 if (!empty(preg_match('/^json-/', $o)) {
105 $type = str_replace('_', '-', substr($o,6));
106 $this->loadFromFile,$
111 if(empty($opt['source'])){
112 die("Missing Source directory for account json files! Try -f [JSON file path] \n");
115 if (!file_exists($opt['source'])) {
116 die("can not found account json file : {$opt['source']} \n");
119 $accounts = json_decode(file_get_contents($opt['source']),true);
121 DB_DataObject::factory('accnt')->importFromArray($this, $accounts);
126 if($k == 'curr_symbol'){
127 if(!empty($opt['base'])){
128 DB_DataObject::factory('curr_symbol')->setBase($this, $opt['base']);
132 if(!empty($opt['source'])){
134 if (!file_exists($opt['source'])) {
135 die("can not found currency json file : {$opt['source']} \n");
138 $currencies = json_decode(file_get_contents($opt['source']),true);
140 DB_DataObject::factory('curr_symbol')->importFromArray($this, $currencies);
144 die("Missing Base Currency or Source directory for Currency json files! Try -b [base currency] or -f [JSON file path]\n");
147 if($k == 'location'){
148 if(empty($opt['source'])){
149 die("Missing Source directory for location json file! Try -f [JSON file path] \n");
152 if (!file_exists($opt['source'])) {
153 die("can not found location json file : {$opt['source']} \n");
156 $locations = json_decode(file_get_contents($opt['source']),true);
158 DB_DataObject::factory('location')->importFromArray($this, $locations);
164 if(empty($opt['source'])){
165 die("Missing Source directory for terms json file! Try -f [JSON file path] \n");
168 if (!file_exists($opt['source'])) {
169 die("can not found terms json file : {$opt['source']} \n");
172 $terms = json_decode(file_get_contents($opt['source']),true);
174 DB_DataObject::factory('terms')->importFromArray($this, $terms);
180 $this->updateData($k);
187 function updateData($k='') {
188 //DB_DataObject::debugLevel(1);
189 $tables = empty($k) ? array(
191 // 'curr_symbol', //?? fixme
203 // 'location', //?? just check hat one exists.
207 $core_opts = HTML_FlexyFramework::get()->page->opts;
208 if (!empty($core_opts['init'])) {
209 DB_DataObject::factory('curr_symbol')->setBase($this, $core_opt['base']);
215 foreach($tables as $t) {
216 $cs = DB_DataObject::factory($t);
217 $cs->initDatabase($this);
221 // update data is called from main