DataObjects/core.sql
[Pman.Core] / UpdateDatabase.php
index 7992d3e..6fd3216 100644 (file)
@@ -45,10 +45,20 @@ class Pman_Core_UpdateDatabase extends Pman
             'default' => '',
             'min' => 1,
             'max' => 1,
-        )
+        ),
+        'init' => array(
+            'desc' => 'Initialize the database (pg only supported)',
+            'short' => 'i',
+            'default' => '',
+            'min' => 1,
+            'max' => 1,
+        ),
+        
         
     );
     
+    var $cli_options = false;
+    
     var $cli = false;
     function getAuth() {
         
@@ -70,6 +80,9 @@ class Pman_Core_UpdateDatabase extends Pman
      
     function get($args, $opt)
     {
+        
+        $this->cli_options = $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");
@@ -84,6 +97,8 @@ class Pman_Core_UpdateDatabase extends Pman
             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");
@@ -206,7 +221,7 @@ class Pman_Core_UpdateDatabase extends Pman
     /**
      * postgresql import..
      */
-    function importpgsql($url)
+    function importpgsql($dburl)
     {
         
         // hide stuff for web..
@@ -216,7 +231,16 @@ class Pman_Core_UpdateDatabase extends Pman
         
         $ar = $this->modulesList();
        
-         foreach($ar as $m) {
+        foreach($ar as $m) {
+            
+            // if init has been called
+            // look in pgsql.ini
+            if (!empty($this->cli_options['init'])) {
+                $this->importpgsqldir($dburl, $this->rootDir. "/Pman/$m/pgsql.init");
+                $this->importpgsqldir($dburl, $this->rootDir. "/Pman/$m/pgsql.initdata");
+            }
+            
+            
             
             $fd = $this->rootDir. "/Pman/$m/DataObjects";
             
@@ -234,7 +258,7 @@ class Pman_Core_UpdateDatabase extends Pman
        
           
     }
-    function importpgsqldir($url, $dir)
+    function importpgsqldir($url, $dir, $disable_triggers = false)
     {
         require_once 'System.php';
         $cat = System::which('cat');
@@ -249,7 +273,10 @@ class Pman_Core_UpdateDatabase extends Pman
             ' -h ' . $url['host'] .
             ' -U' . escapeshellarg($url['user']) .
              ' ' . basename($url['path']);
+        
+        
         echo $psql_cmd . "\n" ;
+        echo "scan : $dir\n";
         foreach(glob($dir.'/*.sql') as $bfn) {
 
 
@@ -263,7 +290,7 @@ class Pman_Core_UpdateDatabase extends Pman
             }
             $fn = false;
 
-            if (basename($dir) != 'pgsql') {
+            if (!preg_match('/pgsql/', basename($dir) )) {
                  if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
                     $fn = $this->convertToPG($bfn);
                 }
@@ -381,7 +408,7 @@ class Pman_Core_UpdateDatabase extends Pman
         }
         
         $ret = array_merge($extra,$ret);
-        echo implode("\n", $ret); exit;
+//        echo implode("\n", $ret); exit;
         
         file_put_contents($fn, implode("\n", $ret));
         
@@ -537,7 +564,8 @@ class Pman_Core_UpdateDatabase extends Pman
         $this->updateDataGroups();
         $this->updateDataCompanies();
         
-       
+        $c = DB_DataObject::Factory('I18n');
+        $c->buildDB();