DataObjects/core.sql
[Pman.Core] / UpdateDatabase.php
index d9d8e97..3bb92ef 100644 (file)
@@ -101,8 +101,8 @@ class Pman_Core_UpdateDatabase extends Pman
                     continue;
                 }
                 // .my.sql but not .pg.sql
-                if (preg_match('/#.[a-z]{2}\.sql#i', basename($bfn))
-                    && !preg_match('/#\.my\.sql#i', basename($bfn))
+                if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
+                    && !preg_match('#\.my\.sql#i', basename($fn))
                 ) { // skip migration scripts at present..
                     continue;
                 }
@@ -120,16 +120,16 @@ class Pman_Core_UpdateDatabase extends Pman
             $fd = $this->rootDir. "/Pman/$m/sql";
             
             foreach(glob($fd.'/*.sql') as $fn) {
-                
-                
-                
                 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ;
-                
                 echo $cmd. ($this->cli ? "\n" : "<BR>\n");
-                
                 passthru($cmd);
+            }
+            $fd = $this->rootDir. "/Pman/$m/mysql";
             
-                
+            foreach(glob($fd.'/*.sql') as $fn) {
+                $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ;
+                echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+                passthru($cmd);
             }
               
             
@@ -139,12 +139,6 @@ class Pman_Core_UpdateDatabase extends Pman
             
         }
         
-       
-        
-        foreach($ar as $m) {
-            
-            
-        }
         
         
     }
@@ -192,7 +186,7 @@ class Pman_Core_UpdateDatabase extends Pman
                 // files ending in .pg.sql are native postgres files..
                 $fn = preg_match('#\.pg\.sql$#', basename($bfn)) ? false : $this->convertToPG($bfn);
                 
-                $cmd = "$psql_cmd -f  " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
+                $cmd = "$psql_cmd  < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
                 
                 echo "$bfn:   $cmd ". ($this->cli ? "\n" : "<BR>\n");
                 
@@ -203,6 +197,30 @@ class Pman_Core_UpdateDatabase extends Pman
                     unlink($fn);
                 }
             }
+            
+            
+            
+            $fd = $this->rootDir. "/Pman/$m/sql";
+            // sql directory  - we try to convert..
+            foreach(glob($fd.'/*.sql') as $bfn) {
+                $fn =  $this->convertToPG($bfn);
+                $cmd = "$psql_cmd  < " . escapeshellarg($fn) ;
+                echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+                passthru($cmd);
+            }
+            
+            // postgres specific directory..
+            
+            $fd = $this->rootDir. "/Pman/$m/pgsql";
+            
+            foreach(glob($fd.'/*.sql') as $fn) {
+                $cmd = "$psql_cmd   < " . escapeshellarg($fn) ;
+                echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+                passthru($cmd);
+            }
+            
+            
+            
         }
         
     }