more quote identeiifers fixessss
[Pman.Core] / Generator.php
index d3285aa..7ffeb57 100644 (file)
@@ -2,6 +2,9 @@
  
  
 /**
+ *
+ *  THIS HAS NOT BEEN TESTED WITH PDO yet...
+ *
  * 
  * Generate DataObjects...
  * 
@@ -12,7 +15,7 @@
  * 
  */
  
-require_once 'DB/DataObject/Generator.php';
+require_once 'PDO/DataObject/Generator.php';
 
 
 /** basic thing now works... 
@@ -42,10 +45,16 @@ $this->def['forms'][$table][$t->name] = $form;
 
 
 
-class Pman_Core_Generator extends DB_DataObject_Generator
+class Pman_Core_Generator extends PDO_DataObject_Generator
 {
     
-
+     
+    function getAuth()
+    {
+         
+        die("do not use this directly.. - use Core/RunGenerator");  
+        
+    }
    
     // inherrited..
     // $tablekeys
@@ -81,7 +90,7 @@ class Pman_Core_Generator extends DB_DataObject_Generator
     // we always overwrite the definition!!!
     // set to array('all') to overwrite everything!!!
     
-    function start($cli=false, $mods='', $overwrite='')
+    function start($cli=false, $mods='', $overwrite=array())
     {
         
         $ff = HTML_Flexyframework::get();
@@ -108,15 +117,14 @@ class Pman_Core_Generator extends DB_DataObject_Generator
         $options['class_location'] = $this->rootDir .'/'.$proj.'/DataObjects';
         $options['require_prefix'] =    $proj . '/DataObjects/';
         $options['class_prefix'] =    $proj . '_DataObjects_';
+        $this->debug(print_r($options,true));
        //  print_r($this);exit;
        
        
-        $this->importSQL();
-       
         $standard_database = $options['database'];
        
        
-       
+         
        
        
        
@@ -130,7 +138,7 @@ class Pman_Core_Generator extends DB_DataObject_Generator
         $diff = System::which('diff');
         // now for each of the directories copy/show diffs..
         echo $cli ? '' : '<PRE>';
-        $flist = explode(',', $overwrite);
+        $flist =   $overwrite;
         foreach($this->modtables as $m=>$ar) {
             if ($options['database'] !=  $standard_database) {
                 $options['database'] =  $standard_database ;
@@ -151,7 +159,15 @@ 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) {
+                
+                echo "SCAN {$options['rootDir']} $f\n";
+                
                 if (!strlen($f) || $f[0] == '.') {
                     continue;
                 }
@@ -164,7 +180,7 @@ class Pman_Core_Generator extends DB_DataObject_Generator
                 
                 if (!file_exists($tg) || !filesize($tg) ) {
                   
-                    if ($cli && !filesize($tg) || in_array($f, $flist)) {
+                    if ($cli && file_exists($tg) || in_array($f, $flist) || in_array('_all_', $flist )) {
                         echo "COPY $src $tg" . ($cli ? "\n" : "<BR>");
                         copy($src, $tg);
                         continue;
@@ -174,7 +190,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>");
@@ -203,66 +219,7 @@ class Pman_Core_Generator extends DB_DataObject_Generator
         
         
     }
-    
-    
-    
-    function importSQL()
-    {
-        $options = &PEAR::getStaticProperty('DB_DataObject','options');
-        
-        $ff = HTML_Flexyframework::get();
-        
-        $url = parse_url($options['database']);
-        // hide stuff for web..
-        $cli = $options['cli'];
-        if (!$cli) {
-            $url['pass'] = '*****';
-            $url['user'] = '*****';
-            $url['host'] = '*****';
-        }
-         
-        
-        
-        require_once 'System.php';
-        $cat = System::which('cat');
-        $mysql = System::which('mysql');
-        print_r($options['mods'] );
-        foreach($this->modsql as $m => $fl)
-        {
-            if ($cli && isset($options['database_'. $m])) {
-                $url =parse_url($options['database_'.$m]);
-            }
-            
-            $mysql_cmd = $mysql .
-                ' -h ' . $url['host'] .
-                ' -u' . escapeshellarg($url['user']) .
-                (!empty($url['pass']) ? ' -p' . escapeshellarg($url['pass'])  :  '') .
-                ' ' . basename($url['path']);
-           
-            echo $mysql_cmd . "\n" ;
-            
-            if (!empty($options['mods'] ) && !in_array($m,  $options['mods'] )) {
-                continue;
-            }
-            
-            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) {
-                    passthru($cmd);
-                }
-                
-            }
-        }
-        
-        
-        
-    }
+     
     /**
      * Scan the folders for DataObjects
      * - Use the list of php files in DataObjects folders 
@@ -355,17 +312,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] : '';
@@ -396,6 +360,7 @@ touch Pman/????/DataObjects/".ucfirst($this->table).".php
         $cli = $options['cli'];
 
         foreach($this->tables as $this->table) {
+            
             $this->table        = trim($this->table);
             $tn  = strtolower($this->table);
             $mod = $this->modmap[$tn];
@@ -404,16 +369,18 @@ touch Pman/????/DataObjects/".ucfirst($this->table).".php
                 continue;
             }
             
+            $clean_table = preg_replace('/[^A-Z0-9]+/i','_',ucfirst(trim($this->table)));
             
-            $this->classname    = 'Pman_'.$mod . '_DataObjects_'. ucfirst($this->table); // replace odd chars?
+            $this->classname    = 'Pman_'.$mod . '_DataObjects_'. $clean_table; // replace odd chars?
            
            
-            $outfilename    = $rd.'/'.$mod.'/'. ucfirst($this->table).'.php';
-            $orig           = $ff->page->rootDir .'/Pman/'.$mod.'/DataObjects/'. ucfirst($this->table).'.php';
+            $outfilename    = $rd.'/'.$mod.'/'. $clean_table .'.php';
+            $orig           = $ff->page->rootDir .'/Pman/'.$mod.'/DataObjects/'.  $clean_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>");