DataObjects/Core_watch.php
[Pman.Core] / UpdateDatabase.php
index e82c47e..3bb92ef 100644 (file)
@@ -61,6 +61,13 @@ class Pman_Core_UpdateDatabase extends Pman
         $this->{'import' . $url['scheme']}($url);
         
     }
+    
+    /**
+     * mysql - does not support conversions.
+     * 
+     *
+     */ 
+    
     function importmysql($url)
     {
         
@@ -81,7 +88,7 @@ class Pman_Core_UpdateDatabase extends Pman
         echo $mysql_cmd . "\n" ;
         
         
-        
+        // old -- DAtaObjects/*.sql
         
         foreach($ar as $m) {
             
@@ -94,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;
                 }
@@ -107,6 +114,29 @@ class Pman_Core_UpdateDatabase extends Pman
             
                 
             }
+            // 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..
+            $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);
+            }
+              
+            
+            
+            
+            
+            
         }
         
         
@@ -156,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");
                 
@@ -167,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);
+            }
+            
+            
+            
         }
         
     }