fix 'Optional parameter declared before required parameter is implicitly treated'
[Pman.Cms] / UpdateDatabase.php
index c3c6993..9c2cf1b 100644 (file)
  */
 
 require_once 'Pman.php';
-class Pman_Core_UpdateDatabase extends Pman
+class Pman_Cms_UpdateDatabase extends Pman
 {
     
-    static $cli_desc = "Update SQL - Beta";
+    static $cli_desc = "Update Database (Cms)";
  
+    static $cli_opts = array(
+        'template' => array(
+            'desc' => 'Compile a specific template',
+            'default' => '',
+            'short' => 't',
+            'min' => 1,
+            'max' => 1,
+            
+        ),
+        'force-content-update' => array(
+            'desc' => 'Force updating of content from templates',
+            'default' => '',
+            'short' => 'f',
+            'min' => 1,
+            'max' => 1,
+            
+        ),
+        'debug' => array(
+            'desc' => 'Turn on debuggin',
+            'default' => '',
+            'short' => 'd',
+            'min' => 1,
+            'max' => 1,
+            
+        )
+    );
     
     var $cli = false;
+    
+    var $opts;
+    
     function getAuth() {
         
         
@@ -38,270 +66,28 @@ class Pman_Core_UpdateDatabase extends Pman
         return true;
     }
      
-    function get()
-    {
-        $this->importSQL();
-        $this->runUpdateDatabaseModules();
-         
-    }
-    function output() {
-        return '';
-    }
-     /**
-     * imports SQL files from all DataObjects directories....
-     * 
-     * except any matching /migrate/
-     */
-    function importSQL()
-    {
-        
-        $ff = HTML_Flexyframework::get();
-        
-        $url = parse_url($ff->DB_DataObject['database']);
-        
-        $this->{'import' . $url['scheme']}($url);
-        
-    }
-    
-    /**
-     * mysql - does not support conversions.
-     * 
-     *
-     */ 
-    
-    function importmysql($url)
+    function get($tbl, $opts= array())
     {
-        
-        // hide stuff for web..
-        
-        require_once 'System.php';
-        $cat = System::which('cat');
-        $mysql = System::which('mysql');
-        
-        $ar = $this->modulesList();
-        
-           
-        $mysql_cmd = $mysql .
-            ' -h ' . $url['host'] .
-            ' -u' . escapeshellarg($url['user']) .
-            (!empty($url['pass']) ? ' -p' . escapeshellarg($url['pass'])  :  '') .
-            ' ' . basename($url['path']);
-        echo $mysql_cmd . "\n" ;
-        
-        
-        // old -- DAtaObjects/*.sql
-        
-        foreach($ar as $m) {
-            
-            $fd = $this->rootDir. "/Pman/$m/DataObjects";
+        if (!empty($opts['debug'])) {
+            DB_DataObject::debugLevel(1);
             
-            foreach(glob($fd.'/*.sql') as $fn) {
-                
-                 
-                if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
-                    continue;
-                }
-                // .my.sql but not .pg.sql
-                if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
-                    && !preg_match('#\.my\.sql#i', basename($fn))
-                ) { // skip migration scripts at present..
-                    continue;
-                }
-                $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ;
-                
-                echo $cmd. ($this->cli ? "\n" : "<BR>\n");
-                
-                passthru($cmd);
-            
-                
-            }
-            // 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);
-            }
-              
-            
-            
-            
-            
-            
-        }
-        
-        
-        
-    }
-    /**
-     * postgresql import..
-     */
-    function importpgsql($url)
-    {
-        
-        // hide stuff for web..
-        
-        require_once 'System.php';
-        $cat = System::which('cat');
-        $psql = System::which('psql');
-        
-        $ar = $this->modulesList();
-        if (!empty($url['pass'])) { 
-            putenv("PGPASSWORD=". $url['pass']);
         }
-           
-        $psql_cmd = $psql .
-            ' -h ' . $url['host'] .
-            ' -U' . escapeshellarg($url['user']) .
-             ' ' . basename($url['path']);
-        echo $psql_cmd . "\n" ;
-        
-        
-        
-        
-        foreach($ar as $m) {
-            
-            $fd = $this->rootDir. "/Pman/$m/DataObjects";
-            
-            foreach(glob($fd.'/*.sql') as $bfn) {
-                
-                 
-                if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
-                    continue;
-                }
-                if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
-                    && !preg_match('#\.pg\.sql#i', basename($bfn))
-                ) { // skip migration scripts at present..
-                    continue;
-                }
-                // files ending in .pg.sql are native postgres files..
-                $fn = preg_match('#\.pg\.sql$#', basename($bfn)) ? false : $this->convertToPG($bfn);
-                
-                $cmd = "$psql_cmd  < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
-                
-                echo "$bfn:   $cmd ". ($this->cli ? "\n" : "<BR>\n");
-                
-                
-                passthru($cmd);
-                
-                if ($fn) {
-                    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);
-            }
-            
-            
+        if (!empty($opts['template'])) {
+             $tp = DB_DataObject::factory('cms_template');
+             //$opts = HTML_FlexyFramework::get()->Pman_Cms;
+             $tp->syncTemplate($opts['template'], true, '');
+             die("done");
             
         }
+        $this->opts = $opts;
         
-    }
-    /**
-     * simple regex based convert mysql to pgsql...
-     */
-    function convertToPG($src)
-    {
-        $fn = $this->tempName('sql');
-        
-        $ret = array( ); // pad it a bit.
-        $extra = array("", "" );
         
-        $tbl = false;
-        foreach(file($src) as $l) {
-            $l = trim($l);
-            
-            if (!strlen($l) || $l[0] == '#') {
-                continue;
-            }
-            $m = array();
-            if (preg_match('#create\s+table\s+([a-z0-9_]+)#i',  $l, $m)) {
-                $tbl = $m[1];
-               // $extra[]  =   "drop table {$tbl};";
-             }
-            // autoinc
-            if ($tbl && preg_match('#auto_increment#i',  $l, $m)) {
-                $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
-                $extra[]  =   "create sequence {$tbl}_seq;";
-              
-            }
-            $m = array();
-            if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+([^(]+)(.*)$#i',  $l, $m)) {
-               $l = "CREATE INDEX  {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
-             }
-            // ALTER TABLE core_event_audit ADD     INDEX looku
-            // CREATE INDEX 
-            
-            // basic types..
-            $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
-            
-            $l = preg_replace('# datetime #i', ' TIMESTAMP WITHOUT TIME ZONE ', $l);
-            $l = preg_replace('# blob #i', ' TEXT ', $l);
-             $l = preg_replace('# longtext #i', ' TEXT ', $l);
-            //$l = preg_match('#int\([0-9]+\)#i', 'INT', $l);
-                            
-            $ret[] = $l;
-            
-            
-            
-            
-            
-            
-            
+        $this->updateData();
+        if (!empty($tbl)) {
+            $d = DB_DataObject::factory($tbl);
+            $d->initDatabase($this);
         }
-        $ret = array_merge($extra,$ret);
         
-        //echo implode("\n", $ret); //exit;
-        file_put_contents($fn, implode("\n", $ret));
-        
-        return $fn;
-    }
-    function runUpdateModulesData()
-    {
-        /*
-        foreach of the modules (except core)
-        
-        does {module}/UpdateDatabase.php exist
-        
-        require it.
-        
-        create an instance of it eg. $x = new ......
-        call $x->updateData();
-        
-          
-        }
-        */
-        
-        
-                
     }
     
     function updateData()
@@ -309,25 +95,94 @@ class Pman_Core_UpdateDatabase extends Pman
         $enum = DB_DataObject::Factory('core_enum');
         $enum->initEnums(
             array(
-                'etype' => '',
-                'name' => 'COMPTYPE',
-                'display_name' =>  'Company Types',
-                'cn' => array(
-                    array(
-                        'name' => 'OWNER',
-                        'display_name' => 'Owner',
-                        'seqid' => 999, // last...
+                array(
+                    'etype' => '',
+                    'name' => 'cms_page_type',
+                    'display_name' =>  'Cms Page Type',
+                    'cn' => array(
+                        array(
+                            'name' => 'page',
+                            'display_name' => 'Pages',
+                        ),
+                        array(
+                            'name' => 'element',
+                            'display_name' => 'Elements',
+                        ),
+                        array(
+                            'name' => 'blog',
+                            'display_name' => 'Blog Entries',
+                        ),
+                        array(
+                            'name' => 'menu',
+                            'display_name' => 'Menu Tree',
+                        ),
+                        array(
+                            'name' => 'category',
+                            'display_name' => 'Category',
+                        ),
+                        array(
+                            'name' => 'disabled',
+                            'display_name' => 'Disabled element',
+                        ),
+                    )
+                ),
+                array(
+                    'etype' => '',
+                    'name' => 'Cms.Settings',
+                    'display_name' => 'Cms Settings',
+                    'cn' => array(
+                        
+                    )
+                ),
+                array(
+                    'etype' => '',
+                    'name' => 'cms_page_class',
+                    'display_name' =>  'Cms Page Class',
+                    'cn' => array(
+                        array(
+                            'name' => 'deep-blue',
+                            'display_name' => 'Deep Blue',
+                        ),
+                        array(
+                            'name' => 'deep-grey',
+                            'display_name' => 'Deep Grey',
+                        ),
+                        array(
+                            'name' => 'light-red',
+                            'display_name' => 'Light Red',
+                        ),
+                        array(
+                            'name' => 'deep-orange',
+                            'display_name' => 'Deep Orange',
+                        ),
+                        array(
+                            'name' => 'deep-green',
+                            'display_name' => 'Deep Green',
+                        )
                     )
-                    
-                )
+                ),
             )
-        );  
+        );
+        /*
+        $p = DB_DataObject::Factory('cms_page');
+        $p->page_type_id = 0;
+        $all = $p->fetchAll();
+        foreach($all as $t) {
+            $t->convertOld();
+        }
+        $ff = $this->bootLoader;
+        $opts = isset($this->bootLoader->Pman_Cms) ? $this->bootLoader->Pman_Cms  : array();
+        echo "Calling syncTemplateDir from Cms/UpdateDatabase\n";
         
         
+        if (empty($this->opts['force-content-update'])) {
+            return;
+        }
+        */
+        echo "Template sync has been removed from here - call   Cms/UpdateTemplates\n";
         
-    }
         
-         
-    
+       
+    }
     
 }
\ No newline at end of file