X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Generator.php;h=7ffeb57b856b59713a431cae841142b4762957d7;hb=e6eb2122a2c49c78628944680de6b01f7439bed7;hp=eb87b55d894679b73b48a237147c8bd6058e86bd;hpb=85a3208394f29c9d35039ae2781bfb0e18fcc713;p=Pman.Core diff --git a/Generator.php b/Generator.php index eb87b55d..7ffeb57b 100644 --- a/Generator.php +++ b/Generator.php @@ -2,15 +2,20 @@ /** + * + * THIS HAS NOT BEEN TESTED WITH PDO yet... + * * - * 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... * * */ -require_once 'DB/DataObject/Generator.php'; +require_once 'PDO/DataObject/Generator.php'; /** basic thing now works... @@ -40,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 @@ -79,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(); @@ -106,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']; - + @@ -128,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 ? '' : '
';
-        $flist = explode(',', $overwrite);
+        $flist =   $overwrite;
         foreach($this->modtables as $m=>$ar) {
             if ($options['database'] !=  $standard_database) {
                 $options['database'] =  $standard_database ;
@@ -149,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;
                 }
@@ -162,8 +180,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" : "
"); + if ($cli && file_exists($tg) || in_array($f, $flist) || in_array('_all_', $flist )) { + echo "COPY $src $tg" . ($cli ? "\n" : "
"); copy($src, $tg); continue; } @@ -172,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" : "
"); @@ -201,62 +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"; - $cmd = $cat . ' ' . escapeshellarg($fn) . " | $mysql_cmd -f "; - echo $cmd. ($cli ? "\n" : "
\n"); - if ($cli) { - passthru($cmd); - } - - } - } - - - - } + /** * Scan the folders for DataObjects * - Use the list of php files in DataObjects folders @@ -349,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] : ''; @@ -371,29 +341,7 @@ touch Pman/????/DataObjects/".ucfirst($this->table).".php $inis[$mod] .= $this->_newConfig; } - - //echo '
';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..
          
     }
     
@@ -412,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];
@@ -420,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" : "
"); @@ -440,7 +391,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); @@ -473,118 +426,19 @@ touch Pman/????/DataObjects/".ucfirst($this->table).".php foreach($this->modtables as $m=>$ts) { $dirs[] = $ff->page->rootDir.'/Pman/'.$m.'/DataObjects'; } - $ini = array('database__render' => array()); - foreach($dirs as $d) { - if (!file_exists($d.'/pman.links.ini')) { - continue; - } - $in = parse_ini_file($d.'/pman.links.ini',true); - $r = array(); - if (isset($in['database__render'])) { - $r = $in['database__render']; - unset($in['database__render']); - } - $ini = array_merge($ini, $in); - $ini['database__render'] = array_merge($ini['database__render'] , $r); - } + //echo '
';print_R($ini);//exit;
         
         
-        if (!isset($ini['database__render'])) {
-            die("database__render not available in links files.");
-            return;
-        }
-        $this->mapcols = array();
-        foreach($ini as $tab=>$conf) {
-            if ($tab == 'database__render') {
-                continue;
-            }
-            $this->mergeConfig($tab,$conf,$ini['database__render']);
-             
-        }
-        $this->renderMap = $ini['database__render'];
+         
     }
-    function mergeConfig($table, $conf, $render)
-    {
-        $this->mapcols[$table] = array();
-        $options = &PEAR::getStaticProperty('DB_DataObject','options');
-        if (isset($options['modtables'])) {
-            $this->modtables = $options['modtables'];
-            $this->modmap = $options['modmap'];
-            $this->modsql = $options['modsql'];
-        }
-        
-        
-        foreach($conf as $ocol=>$info) {
-            // format col => showval..
-            //list($rtc, $rshow) = explode(':', $info);
-            list($tab,$col) = explode(':', $info);
-            //print_r($render);
-            $rshow = $render[$tab];
-            
-            $this->mapcols[$table][$ocol] = array('table'=>$tab, 'col' => $col);
-            
-            // for the grid...
-            
-            // reader:
-            //- just add an extra line..
-            if (!isset($this->def['readers'][$tab][$rshow])){
-                echo "WARNING in links.ini TABLE $tab does not have renderer $rshow 
\n"; - continue; - } - - // for the readers.. we need to merge all the columns in the left to the right... - - // table => original - // ocol => column in table - // tab => remote table - // col => right col linked to... - - $rdef = $this->_definitions[$tab]; - - - foreach($rdef as $t) { - //copy typedata from old coll - $this->def['readers'][$table][$ocol.'-'. $t->name] = $this->def['readers'][$tab][$t->name]; - $this->def['readers'][$table][$ocol.'-'. $t->name]['name'] = $ocol.'_'. $t->name; - } - - - - - - // remove the def column from the id one.. - if (isset($this->def['colmodels'][$table][$ocol])) { - unset($this->def['colmodels'][$table][$ocol]); - } - $this->def['colmodels'][$table][$ocol.'-'. $rshow] = - $this->def['colmodels'][$tab][$rshow]; - - // change the header name (merge of two..) - list($colname,) = explode('_',$ocol,2); - - $this->def['colmodels'][$table][$ocol.'-'. $rshow]['dataIndex'] = $ocol.'_'. $rshow; - $this->def['colmodels'][$table][$ocol.'-'. $rshow]['id'] = $ocol.'-'. $rshow; - - $this->def['colmodels'][$table][$ocol.'-'. $rshow]['header'] = ucwords($colname . ' ' . - $this->def['colmodels'][$tab][$rshow]['header']); - - // last of all add replace the old $col, with - $p = array_search($ocol, empty($this->def['order'][$table]) ? array() : $this->def['order'][$table]); - $this->def['order'][$table][$p] = $ocol.'-'. $rshow; - $this->def['order'][$table][] = $ocol; - - // --- now for forms!!!! - - - } + //var_dump($table); //print_r( $this->def['readers'][$table]); // print_r( $this->def['colmodels'][$table]); //print_r($this->def['readers'][$table]); exit; - } - + function writeFileEx($n, $f, $str) {