DataObjects/core.sql
[Pman.Core] / UpdateDatabase.php
index b9c5bae..3e34258 100644 (file)
@@ -32,6 +32,20 @@ class Pman_Core_UpdateDatabase extends Pman
             'min' => 1,
             'max' => 1,
         ),
+        'name' => array(
+            'desc' => 'name of the company',
+            'short' => 'n',
+            'default' => '',
+            'min' => 1,
+            'max' => 1,
+        ),
+        'comptype' => array(
+            'desc' => 'the type of company',
+            'short' => 't',
+            'default' => '',
+            'min' => 1,
+            'max' => 1,
+        )
         
     );
     
@@ -64,24 +78,19 @@ class Pman_Core_UpdateDatabase extends Pman
                 die("can not found person json file : {$opt['source']} \n");
             }
             
-            $persons = json_decode(file_get_contents($source),true);
+            $persons = json_decode(file_get_contents($opt['source']),true);
             
-            DB_DataObject::factory('person')->importFromArray(HTML_Flexyframework::get()->page, $persons, $opt['prefix']);
+            DB_DataObject::factory('person')->importFromArray($this, $persons, $opt['prefix']);
             die("DONE! \n");
         }
         
-        if($args == 'Account'){
-            if(empty($opt['source'])){
-                die("Missing Source directory for account json files! Try -f [JSON file path] \n");
+        if($args == 'Company'){
+            if(empty($opt['name']) || empty($opt['comptype'])){
+                die("Missing company name or type! Try --name=[the name of company] -- comptype=[the type of company] \n");
             }
             
-            if (!file_exists($opt['source'])) {
-                die("can not found account json file : {$opt['source']} \n");
-            }
-
-            $accounts = json_decode(file_get_contents($source),true);
+            DB_DataObject::factory('companies')->initCompanies($this, $opt['name'], $opt['comptype']);
             
-            DB_DataObject::factory('accnt')->importFromJson($opt['source']);
             die("DONE! \n");
         }
         
@@ -335,8 +344,12 @@ class Pman_Core_UpdateDatabase extends Pman
     
     function runUpdateModulesData()
     {
-        $this->updateData();
-        $modules = $this->modulesList();
+        // runs core...
+        $this->updateData(); 
+        $modules = array_reverse($this->modulesList());
+        
+        // move 'project' one to the end...
+        
         foreach ($modules as $module){
             $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
             if($module == 'Core' || !file_exists($file)){
@@ -378,6 +391,48 @@ class Pman_Core_UpdateDatabase extends Pman
         
         $groups = DB_DataObject::factory('groups');
         $groups->initGroups();
+        
+        $groups->initDatabase($this,array(
+            array(
+                'name' => 'bcc-email', // group who are bcc'ed on all requests.
+                'type' => 0, // system
+            ),
+            
+        ));
+        
+        
+        
+        // fix comptypes enums..
+        $c = DB_DataObject::Factory('Companies');
+        $c->selectAdd();
+        $c->selectAdd('distinct(comptype) as comptype');
+        foreach($c->fetchAll('comptype') as $cts) {
+           $ctb[0]['cn'][] = array( 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
+        
+        }
+        
+         
+        $c = DB_DataObject::Factory('core_enum');
+         
+        $c->initEnums($ctb);
+        //DB_DataObject::debugLevel(1);
+        // fix comptypeid
+        $c = DB_DataObject::Factory('Companies');
+        $c->query("
+            UPDATE Companies 
+                SET
+                    comptype_id = (SELECT id FROM core_enum where etype='comptype' and name=Companies.comptype)
+                WHERE
+                    comptype_id = 0
+                    AND
+                    LENGTH(comptype) > 0
+                  
+                  
+                  ");
+         
+        
+        
+        
     }