UpdateDatabase.php
[Pman.Xtuple] / UpdateDatabase.php
1 <?php
2
3 /**
4  *
5  * Setup the core values in the database
6  *
7  *
8  */
9
10 require_once 'Pman.php';
11 class Pman_Xtuple_UpdateDatabase extends Pman
12 {
13     
14     static $cli_desc = "Update SQL - Beta";
15     
16     static $cli_opts = array(
17         'source' => array(
18             'desc' => 'Source directory for json files.',
19             'short' => 'f',
20             'default' => '',
21             'min' => 1,
22             'max' => 1,
23         ),
24         
25         
26         
27         'base' => array(
28             'desc' => 'Base Currency',
29             'default' => '',
30             'short' => 'b',
31             'min' => 1,
32             'max' => 1,
33             
34         ),
35  
36         'json-accnt' => array(
37             'desc' => 'Accounts JSON file',
38             'default' => '',
39             'min' => 1,
40             'max' => 1,
41             
42         ),
43         'json-curr-symbol' => array(
44             'desc' => 'Currency Symbols JSON file',
45             'default' => '',
46             'min' => 1,
47             'max' => 1,
48             
49         ),
50
51         'json-location' => array(
52             'desc' => 'Location JSON file',
53             'default' => '',
54             'min' => 1,
55             'max' => 1,
56             
57         ),
58         'json-terms' => array(
59             'desc' => 'Terms  JSON file',
60             'default' => '',
61             'min' => 1,
62             'max' => 1,
63             
64         ),
65         
66     );
67     
68     var $cli = false; 
69     function getAuth() {
70         
71         
72         $ff = HTML_FlexyFramework::get();
73         if (!empty($ff->cli)) {
74             $this->cli = true;
75             return true;
76         }
77         die("NOT ALLOWED");
78     }
79     
80     // called to ensure options are correct.
81     // before any data is imported / started..
82     function checkOpts($opts)
83     {
84         $opts = HTML_FlexyFramework::get()->page->opts;
85         if (
86                 (!empty($opts['init']) && empty($opts['base']) )
87                 ||
88                 (empty($opts['init']) && !empty($opts['base']) )
89            ) {
90                     
91             die("--base=XXX  and --init =1 must be used together.");
92         }
93         
94        
95         
96         
97     }
98     
99     }
100     
101     
102     function get($k = '',$opts)
103     {
104         $k = strtolower($k);
105         
106         $this->opts = $opts;
107         
108         require_once 'Pman/Core/UpdateDatabase.php';
109         
110         Pman_Core_UpdateDatabase::jsonImportFromArray($opts);
111           
112         $this->updateData($k);
113         
114     }
115     
116     
117     
118     
119     function updateData($k='') {
120         //DB_DataObject::debugLevel(1);
121         $tables = empty($k) ? array(
122                 
123 //                'curr_symbol', //?? fixme
124                 'custtype',
125                 'plancode',
126                 'prodcat',
127                 'classcode',
128                 'curr_rate',
129                 'char',
130                 'taxzone',
131                 'taxtype',
132                 'expcat',
133 //                'terms', //?? add
134                 
135 //                'location', //?? just check hat one exists.
136         ) : array($k);
137         
138         
139         $core_opts = HTML_FlexyFramework::get()->page->opts;
140         if (!empty($core_opts['init'])) {
141             DB_DataObject::factory('curr_symbol')->setBase($this, $core_opts['base']);
142         }
143         
144         
145         
146         
147         foreach($tables as $t) {
148             $cs = DB_DataObject::factory($t);
149             $cs->initDatabase($this);
150         
151         }
152         
153         // update data is called from main
154         
155         
156         
157         
158     }
159     
160     
161     
162 }