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',
45 $ff = HTML_FlexyFramework::get();
46 if (!empty($ff->cli)) {
53 // called to ensure options are correct.
54 // before any data is imported / started..
63 function get($k = '',$opt)
74 if(empty($opt['source'])){
75 die("Missing Source directory for account json files! Try -f [JSON file path] \n");
78 if (!file_exists($opt['source'])) {
79 die("can not found account json file : {$opt['source']} \n");
82 $accounts = json_decode(file_get_contents($opt['source']),true);
84 DB_DataObject::factory('accnt')->importFromArray($this, $accounts);
89 if($k == 'curr_symbol'){
90 if(!empty($opt['base'])){
91 DB_DataObject::factory('curr_symbol')->setBase($this, $opt['base']);
95 if(!empty($opt['source'])){
97 if (!file_exists($opt['source'])) {
98 die("can not found currency json file : {$opt['source']} \n");
101 $currencies = json_decode(file_get_contents($opt['source']),true);
103 DB_DataObject::factory('curr_symbol')->importFromArray($this, $currencies);
107 die("Missing Base Currency or Source directory for Currency json files! Try -b [base currency] or -f [JSON file path]\n");
110 if($k == 'location'){
111 if(empty($opt['source'])){
112 die("Missing Source directory for location json file! Try -f [JSON file path] \n");
115 if (!file_exists($opt['source'])) {
116 die("can not found location json file : {$opt['source']} \n");
119 $locations = json_decode(file_get_contents($opt['source']),true);
121 DB_DataObject::factory('location')->importFromArray($this, $locations);
127 if(empty($opt['source'])){
128 die("Missing Source directory for terms json file! Try -f [JSON file path] \n");
131 if (!file_exists($opt['source'])) {
132 die("can not found terms json file : {$opt['source']} \n");
135 $terms = json_decode(file_get_contents($opt['source']),true);
137 DB_DataObject::factory('terms')->importFromArray($this, $terms);
143 $this->updateData($k);
150 function updateData($k='') {
151 //DB_DataObject::debugLevel(1);
152 $tables = empty($k) ? array(
154 // 'curr_symbol', //?? fixme
166 // 'location', //?? just check hat one exists.
170 $core_opts = HTML_FlexyFramework::get()->page->opts;
171 if (!empty($core_opts['init']) && empty($core_opts['base'])) {
172 die("init must be used before base!");
176 foreach($tables as $t) {
177 $cs = DB_DataObject::factory($t);
178 $cs->initDatabase($this);
182 // update data is called from main