DataObjects/Core_curr_rate.php
[Pman.Core] / UpdateDatabase.php
index 9bf0edc..62bb5d8 100644 (file)
@@ -173,12 +173,12 @@ class Pman_Core_UpdateDatabase extends Pman
         
         $ff = HTML_Flexyframework::get();
         
-        $url = parse_url($ff->DB_DataObject['database']);
+        $dburl = parse_url($ff->DB_DataObject['database']);
         
-        $this->{'import' . $url['scheme']}($url);
+        //$this->{'import' . $url['scheme']}($url);
         
-        $dbtype = $url['scheme'];
-        $dirmethod = 'import' . $url['scheme'] . '.dir';
+        $dbtype = $dburl['scheme'];
+        $dirmethod = 'import' . $dburl['scheme'] . 'dir';
         
         
        
@@ -191,7 +191,30 @@ class Pman_Core_UpdateDatabase extends Pman
             if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
                 continue;
             }
+            
+            
+            // check to see if the class has
+            
+            
+            
+            $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
+            if($m != 'Core' && file_exists($file)){
+                
+                require_once $file;
+                $class = "Pman_{$m}_UpdateDatabase";
+                $x = new $class;
+                if(method_exists($x, 'importModuleSQL')){
+                    echo "Importing SQL from module $m using Module::importModuleSQL\n";
+                    $x->opts = $this->opts;
+                    $x->rootDir = $this->rootDir;
+                    $x->importModuleSQL($dburl);
+                    continue;
+                }
+            };
+
             echo "Importing SQL from module $m\n";
+            
+            
             // if init has been called
             // look in pgsql.ini
             if (!empty($this->opts['init'])) {
@@ -229,100 +252,14 @@ class Pman_Core_UpdateDatabase extends Pman
     
     
     
-    
-    function importmysql($dburl)
-    {
-        
-        // hide stuff for web..
-        $ar = $this->modulesList();
-        
-         
-        
-        // old -- DAtaObjects/*.sql
-        
-        foreach($ar as $m) {
-            
-            if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
-                continue;
-            }
-            
-            $fd = $this->rootDir. "/Pman/$m/DataObjects";
-            
-            $this->importmysqldir($dburl, $fd);
-            
-            // new -- sql directory..
-            // new style will not support migrate ... they have to go into mysql-migrate.... directories..
-            // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
-            
-            $this->importmysqldir($dburl, $this->rootDir. "/Pman/$m/sql");
-            $this->importmysqldir($dburl, $this->rootDir. "/Pman/$m/mysql");
-              
-            
-        }
-        
-        
-        
-    }
-    /**
-     * postgresql import..
-     */
-    function importpgsql($dburl)
-    {
-        
-        // hide stuff for web..
-        
-        
-       
-        
-        $ar = $this->modulesList();
-       
-        print_R($ar);
-        foreach($ar as $m) {
-             echo "Importing SQL from module $m\n";
-            if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
-                continue;
-            }
-            echo "Importing SQL from module $m\n";
-            // if init has been called
-            // look in pgsql.ini
-            if (!empty($this->opts['init'])) {
-                $this->importpgsqldir($dburl, $this->rootDir. "/Pman/$m/pgsql.init");
-                
-            }
-            
-            
-            
-            $fd = $this->rootDir. "/Pman/$m/DataObjects";
-            
-            $this->importpgsqldir($dburl, $fd);
-            
-            // new -- sql directory..
-            // new style will not support migrate ... they have to go into mysql-migrate.... directories..
-            // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
-            
-            $this->importpgsqldir($dburl, $this->rootDir. "/Pman/$m/sql");
-            $this->importpgsqldir($dburl, $this->rootDir. "/Pman/$m/pgsql");
-            
-            
-            
-            if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/pgsql.initdata")) {
-                HTML_FlexyFramework::get()->generateDataobjectsCache(true);
-                
-                $this->importpgsqldir($dburl, $this->rootDir. "/Pman/$m/pgsql.initdata");
-                $this->fixSequencesPgsql();
-                
-            }
-              
-            
-        }
-       
-          
-    }
+     
     /** -------------- code to handle importing a whole directory of files into the database  -------  **/
     
     
     function importpgsqldir($url, $dir, $disable_triggers = false)
     {
+        $ff = HTML_FlexyFramework::get();
+        
         require_once 'System.php';
         $cat = System::which('cat');
         $psql = System::which('psql');
@@ -340,9 +277,15 @@ class Pman_Core_UpdateDatabase extends Pman
         
         echo $psql_cmd . "\n" ;
         echo "scan : $dir\n";
+        if (is_file($dir)) {
+            $files = array($dir);
+
+        } else {
         
-        $files = glob($dir.'/*.sql');
-        uksort($files, 'strcasecmp');
+        
+            $files = glob($dir.'/*.sql');
+            uksort($files, 'strcasecmp');
+        }
         //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
         //usort($files, $lsort);
         
@@ -372,7 +315,7 @@ class Pman_Core_UpdateDatabase extends Pman
 
             $cmd = "$psql_cmd  < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
 
-            echo "$bfn:   $cmd ". ($this->cli ? "\n" : "<BR>\n");
+            echo "$bfn:   $cmd ". ($ff->cli ? "\n" : "<BR>\n");
 
 
             passthru($cmd);
@@ -772,6 +715,9 @@ class Pman_Core_UpdateDatabase extends Pman
         
         
     }
+    
+    /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
+    
     function fixSequencesMysql()
     {
         // not required...