Generator.php
[Pman.Core] / Generator.php
index d04ef1a..dd41cb0 100644 (file)
@@ -3,7 +3,9 @@
  
 /**
  * 
- * Generate DataObjects... and readers in the right places..
+ * Generate DataObjects...
+ * 
+ * This does not generate ini files any more - as that is done on the fly by the framework.
  * 
  * note - we write to a temporary directory first...
  * 
@@ -114,7 +116,7 @@ class Pman_Core_Generator extends DB_DataObject_Generator
         $standard_database = $options['database'];
        
        
-       
+        var_dump($options);exit;
        
        
        
@@ -149,6 +151,11 @@ class Pman_Core_Generator extends DB_DataObject_Generator
             if (!empty($options['mods'] ) && !in_array($m,  $options['mods'] )) {
                 continue;
             }
+            // this happens when we have no database tables from a module,
+            // but module code has been defined.
+            if (!file_exists($options['rootDir'].'/'.$m)) {
+                continue;
+            }
             foreach(scandir($options['rootDir'].'/'.$m) as $f) {
                 if (!strlen($f) || $f[0] == '.') {
                     continue;
@@ -162,8 +169,8 @@ class Pman_Core_Generator extends DB_DataObject_Generator
                 
                 if (!file_exists($tg) || !filesize($tg) ) {
                   
-                    if ($cli && in_array($f, $flist)) {
-                       echo "COPY $src $tg" . ($cli ? "\n" : "<BR>");
+                    if ($cli && !filesize($tg) || in_array($f, $flist)) {
+                        echo "COPY $src $tg" . ($cli ? "\n" : "<BR>");
                         copy($src, $tg);
                         continue;
                     }
@@ -172,7 +179,7 @@ class Pman_Core_Generator extends DB_DataObject_Generator
                     continue;
                 }
                 // always copy readers and ini file.=  nope - not on live..
-                if ($cli && in_array($f, $flist)) {
+                if ($cli && in_array($f, $flist) || in_array('_all_', $flist )) {
                     
                    //|| $f=='pman.ini' || preg_match('/\.js$/', $f))) {
                     echo "COPY $src $tg". ($cli ? "\n" : "<BR>");
@@ -201,9 +208,11 @@ class Pman_Core_Generator extends DB_DataObject_Generator
         
         
     }
-    
-    
-    
+    /**
+     * imports SQL files from all DataObjects directories....
+     * 
+     * except any matching /migrate/
+     */
     function importSQL()
     {
         $options = &PEAR::getStaticProperty('DB_DataObject','options');
@@ -218,8 +227,6 @@ class Pman_Core_Generator extends DB_DataObject_Generator
             $url['user'] = '*****';
             $url['host'] = '*****';
         }
-         
-        
         
         require_once 'System.php';
         $cat = System::which('cat');
@@ -228,7 +235,7 @@ class Pman_Core_Generator extends DB_DataObject_Generator
         foreach($this->modsql as $m => $fl)
         {
             if ($cli && isset($options['database_'. $m])) {
-                $url =parse_url($options['database_'.$m]);
+                $url = parse_url($options['database_'.$m]);
             }
             
             $mysql_cmd = $mysql .
@@ -245,6 +252,10 @@ class Pman_Core_Generator extends DB_DataObject_Generator
             
             foreach($fl as $f) {
                 $fn = $ff->page->rootDir. "/Pman/$m/DataObjects/$f";
+                if (preg_match('/migrate/i', $f)) { // skip migration scripts at present..
+                    continue;
+                }
+                
                 $cmd = $cat . ' ' . escapeshellarg($fn) . " | $mysql_cmd -f ";
                 echo $cmd. ($cli ? "\n" : "<BR>\n");
                 if ($cli) {
@@ -349,17 +360,24 @@ class Pman_Core_Generator extends DB_DataObject_Generator
                 if (in_array($this->table, $ignore)) {
                     continue;
                 }
-             
-             
-                die("No existing DataObject file found for table {$this->table} 
+                if (empty($mods)) {
                 
+                
+                   die("No existing DataObject file found for table {$this->table} 
+            
 - either add it to Pman_Builder[skip_tables] or\n
+- run generator and specify that module..
 - create an empty file in the related Module/DataObjects directory
 eg. 
 touch Pman/????/DataObjects/".ucfirst($this->table).".php
-
-");
-                    
+   
+   ");
+                }
+                // use mods to determine where it should output to..
+                //var_dump($mods);exit;
+                $this->modmap[$tn] = $mods[0];
+                
+                
             }
             $mod = $this->modmap[$tn];
             $inis[$mod] = isset($inis[$mod]) ? $inis[$mod] : '';
@@ -371,29 +389,7 @@ touch Pman/????/DataObjects/".ucfirst($this->table).".php
             
             $inis[$mod] .= $this->_newConfig;
         }
-        
-        //echo '<PRE>';print_r($this->_inis); exit;
-        $options = PEAR::getStaticProperty('DB_DataObject','options');
-        
-        $rd = $options['rootDir'];
-        foreach($inis as $m=>$ini) {
-            if (!empty($mods) && !in_array($m, $mods)) {
-                continue;
-            }
-            
-            if (!file_exists($rd.'/'.$m)) {
-                mkdir($rd.'/'.$m, 0775, true);
-            }
-            $fname = '/pman.ini';
-            if (isset($options['database_'. $m])) {
-                $url = parse_url($options['database_'.$m]);
-                $fname = '/'. basename($url['path']).'.ini';
-            }
-
-            
-            file_put_contents($rd.'/'.$m.$fname, $ini);
-        }
-         
+        return; // we do not generate in ifiles any more..
          
     }
     
@@ -429,7 +425,8 @@ touch Pman/????/DataObjects/".ucfirst($this->table).".php
             
            
                 // file_get_contents???
-            $oldcontents = file_get_contents($orig);
+            
+            $oldcontents = file_exists($orig) ? file_get_contents($orig) : '';
             
              
             echo "GENERATE: " .   $this->classname  . ($cli ? "\n" : "<BR>");
@@ -440,7 +437,9 @@ touch Pman/????/DataObjects/".ucfirst($this->table).".php
             $out = preg_replace('/(\n|\r\n)\s*function staticGet[^\n]+(\n|\r\n)/s', '', $out);
             $out = preg_replace('#/\* Static get \*/#s', '', $out);
               
-
+            if (!file_exists(dirname($outfilename))) {
+                mkdir(dirname($outfilename), 0755, true);
+            }
            // $this->debug( "writing $this->classname\n");
             //$tmpname = tempnam(session_save_path(),'DataObject_');
             file_put_contents($outfilename, $out);
@@ -485,8 +484,7 @@ touch Pman/????/DataObjects/".ucfirst($this->table).".php
        // print_r( $this->def['colmodels'][$table]);
         //print_r($this->def['readers'][$table]); exit;
         
-    }
-        
+      
        
     function writeFileEx($n, $f, $str) 
     {