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..
57 $core_opts = HTML_FlexyFramework::get()->page->opts;
58 if (!empty($core_opts['init']) && empty($core_opts['base'])) {
59 die("init must be used before base!");
67 function get($k = '',$opt)
78 if(empty($opt['source'])){
79 die("Missing Source directory for account json files! Try -f [JSON file path] \n");
82 if (!file_exists($opt['source'])) {
83 die("can not found account json file : {$opt['source']} \n");
86 $accounts = json_decode(file_get_contents($opt['source']),true);
88 DB_DataObject::factory('accnt')->importFromArray($this, $accounts);
93 if($k == 'curr_symbol'){
94 if(!empty($opt['base'])){
95 DB_DataObject::factory('curr_symbol')->setBase($this, $opt['base']);
99 if(!empty($opt['source'])){
101 if (!file_exists($opt['source'])) {
102 die("can not found currency json file : {$opt['source']} \n");
105 $currencies = json_decode(file_get_contents($opt['source']),true);
107 DB_DataObject::factory('curr_symbol')->importFromArray($this, $currencies);
111 die("Missing Base Currency or Source directory for Currency json files! Try -b [base currency] or -f [JSON file path]\n");
114 if($k == 'location'){
115 if(empty($opt['source'])){
116 die("Missing Source directory for location json file! Try -f [JSON file path] \n");
119 if (!file_exists($opt['source'])) {
120 die("can not found location json file : {$opt['source']} \n");
123 $locations = json_decode(file_get_contents($opt['source']),true);
125 DB_DataObject::factory('location')->importFromArray($this, $locations);
131 if(empty($opt['source'])){
132 die("Missing Source directory for terms json file! Try -f [JSON file path] \n");
135 if (!file_exists($opt['source'])) {
136 die("can not found terms json file : {$opt['source']} \n");
139 $terms = json_decode(file_get_contents($opt['source']),true);
141 DB_DataObject::factory('terms')->importFromArray($this, $terms);
147 $this->updateData($k);
154 function updateData($k='') {
155 //DB_DataObject::debugLevel(1);
156 $tables = empty($k) ? array(
158 // 'curr_symbol', //?? fixme
170 // 'location', //?? just check hat one exists.
174 $core_opts = HTML_FlexyFramework::get()->page->opts;
175 if (!empty($core_opts['init']) && empty($core_opts['base'])) {
176 die("init must be used before base!");
180 foreach($tables as $t) {
181 $cs = DB_DataObject::factory($t);
182 $cs->initDatabase($this);
186 // update data is called from main