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)) {
52 function get($k = '',$opt)
63 if(empty($opt['source'])){
64 die("Missing Source directory for account json files! Try -f [JSON file path] \n");
67 if (!file_exists($opt['source'])) {
68 die("can not found account json file : {$opt['source']} \n");
71 $accounts = json_decode(file_get_contents($opt['source']),true);
73 DB_DataObject::factory('accnt')->importFromArray($this, $accounts);
78 if($k == 'curr_symbol'){
79 if(!empty($opt['base'])){
80 DB_DataObject::factory('curr_symbol')->setBase($this, $opt['base']);
84 if(!empty($opt['source'])){
86 if (!file_exists($opt['source'])) {
87 die("can not found currency json file : {$opt['source']} \n");
90 $currencies = json_decode(file_get_contents($opt['source']),true);
92 DB_DataObject::factory('curr_symbol')->importFromArray($this, $currencies);
96 die("Missing Base Currency or Source directory for Currency json files! Try -b [base currency] or -f [JSON file path]\n");
100 if(empty($opt['source'])){
101 die("Missing Source directory for location json file! Try -f [JSON file path] \n");
104 if (!file_exists($opt['source'])) {
105 die("can not found location json file : {$opt['source']} \n");
108 $locations = json_decode(file_get_contents($opt['source']),true);
110 DB_DataObject::factory('location')->importFromArray($this, $locations);
116 if(empty($opt['source'])){
117 die("Missing Source directory for terms json file! Try -f [JSON file path] \n");
120 if (!file_exists($opt['source'])) {
121 die("can not found terms json file : {$opt['source']} \n");
124 $terms = json_decode(file_get_contents($opt['source']),true);
126 DB_DataObject::factory('terms')->importFromArray($this, $terms);
132 $this->updateData($k);
139 function updateData($k='') {
140 //DB_DataObject::debugLevel(1);
141 $tables = empty($k) ? array(
143 // 'curr_symbol', //?? fixme
155 // 'location', //?? just check hat one exists.
159 $core_opts = HTML_FlexyFramework::get()->page->opts;
160 if (!empty($core_opts['init'])) {
165 foreach($tables as $t) {
166 $cs = DB_DataObject::factory($t);
167 $cs->initDatabase($this);
171 // update data is called from main