DataObjects/Core_notify.php
[Pman.Core] / UpdateDatabase.php
index 905a4cd..b2bbfda 100644 (file)
@@ -17,7 +17,37 @@ class Pman_Core_UpdateDatabase extends Pman
     
     static $cli_desc = "Update SQL - Beta (it will run updateData of all modules)";
  
+    static $cli_opts = array(
+        'source' => array(
+            'desc' => 'Source directory for json files.',
+            'short' => 'f',
+            'default' => '',
+            'min' => 1,
+            'max' => 1,
+        ),
+        'prefix' => array(
+            'desc' => 'prefix for the passwrod',
+            'short' => 'p',
+            'default' => '',
+            '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,
+        )
+        
+    );
     
     var $cli = false;
     function getAuth() {
@@ -38,8 +68,32 @@ class Pman_Core_UpdateDatabase extends Pman
         return true;
     }
      
-    function get()
+    function get($args, $opt)
     {
+        if($args == 'Person'){
+            if(empty($opt['source']) || empty($opt['prefix'])){
+                die("Missing Source directory for person json files or prefix for the passwrod! Try -f [JSON file path] -p [prefix] \n");
+            }
+            if (!file_exists($opt['source'])) {
+                die("can not found person json file : {$opt['source']} \n");
+            }
+            
+            $persons = json_decode(file_get_contents($opt['source']),true);
+            
+            DB_DataObject::factory('person')->importFromArray($this, $persons, $opt['prefix']);
+            die("DONE! \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");
+            }
+            
+            DB_DataObject::factory('companies')->initCompanies($this, $opt['name'], $opt['comptype']);
+            
+            die("DONE! \n");
+        }
+        
         $this->importSQL();
         $this->runUpdateModulesData();
          
@@ -158,7 +212,7 @@ class Pman_Core_UpdateDatabase extends Pman
         $psql = System::which('psql');
         
         $ar = $this->modulesList();
-        print_r($ar);exit;
+        
         if (!empty($url['pass'])) { 
             putenv("PGPASSWORD=". $url['pass']);
         }
@@ -290,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)){
@@ -330,6 +388,9 @@ class Pman_Core_UpdateDatabase extends Pman
                 )
             )
         ); 
+        
+        $groups = DB_DataObject::factory('groups');
+        $groups->initGroups();
     }