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)
61 if(empty($opt['source'])){
62 die("Missing Source directory for account json files! Try -f [JSON file path] \n");
65 if (!file_exists($opt['source'])) {
66 die("can not found account json file : {$opt['source']} \n");
69 $accounts = json_decode(file_get_contents($opt['source']),true);
71 DB_DataObject::factory('accnt')->importFromArray($this, $accounts);
76 if($k == 'curr_symbol'){
77 if(!empty($opt['base'])){
78 DB_DataObject::factory('curr_symbol')->setBase($this, $opt['base']);
82 if(!empty($opt['source'])){
84 if (!file_exists($opt['source'])) {
85 die("can not found currency json file : {$opt['source']} \n");
88 $currencies = json_decode(file_get_contents($opt['source']),true);
90 DB_DataObject::factory('curr_symbol')->importFromArray($this, $currencies);
94 die("Missing Base Currency or Source directory for Currency json files! Try -b [base currency] or -f [JSON file path]\n");
98 if(empty($opt['source'])){
99 die("Missing Source directory for location json file! Try -f [JSON file path] \n");
102 if (!file_exists($opt['source'])) {
103 die("can not found location json file : {$opt['source']} \n");
106 $locations = json_decode(file_get_contents($opt['source']),true);
108 DB_DataObject::factory('location')->importFromArray($this, $locations);
114 if(empty($opt['source'])){
115 die("Missing Source directory for terms json file! Try -f [JSON file path] \n");
118 if (!file_exists($opt['source'])) {
119 die("can not found terms json file : {$opt['source']} \n");
122 $terms = json_decode(file_get_contents($opt['source']),true);
124 DB_DataObject::factory('terms')->importFromArray($this, $terms);
130 $this->updateData($k);
137 function updateData($k='') {
138 //DB_DataObject::debugLevel(1);
139 $tables = empty($k) ? array(
141 // 'curr_symbol', //?? fixme
153 // 'location', //?? just check hat one exists.
158 foreach($tables as $t) {
159 $cs = DB_DataObject::factory($t);
160 $cs->initDatabase($this);