[pLog-svn] r3301 - in plog/trunk: . install

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Sat Apr 29 19:34:24 GMT 2006


Author: jondaley
Date: 2006-04-29 19:34:23 +0000 (Sat, 29 Apr 2006)
New Revision: 3301

Modified:
   plog/trunk/install/dbschemas.properties.php
   plog/trunk/wizard.php
Log:
config table no longer needs id column.  The wizard will remove config_key duplicates from the config table, and then remove the id column.  I also made the error printout a little better - it would be even nicer to only print errors in red, rather than everything.

Modified: plog/trunk/install/dbschemas.properties.php
===================================================================
--- plog/trunk/install/dbschemas.properties.php	2006-04-29 14:57:43 UTC (rev 3300)
+++ plog/trunk/install/dbschemas.properties.php	2006-04-29 19:34:23 UTC (rev 3301)
@@ -184,7 +184,6 @@
 $Tables["users_permissions"]["options"] = "TYPE=MyISAM";
 
 $Tables["config"]["schema"] = "
-   id I(10) NOTNULL AUTOINCREMENT PRIMARY,
    config_key C(255) NOTNULL DEFAULT '' PRIMARY,
    config_value TEXT NOTNULL,
    value_type I(3) DEFAULT '0'

Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php	2006-04-29 14:57:43 UTC (rev 3300)
+++ plog/trunk/wizard.php	2006-04-29 19:34:23 UTC (rev 3301)
@@ -1227,6 +1227,7 @@
             return true;
         }
 
+        
         function perform()
         {
             global $Tables;
@@ -1283,6 +1284,7 @@
             $errors = false;
             foreach( $Tables as $name => $table ) {
                 $errorMessage = "";
+                $table_errors = false;
             	$upperName = $dict->upperName;
             	$tableSchema = $table["schema"];
             	if ( isset( $table["options"] ) )
@@ -1296,22 +1298,16 @@
                 // generate the code with the changes for the table
                 $sqlarray = $dict->ChangeTableSQL( $this->_dbPrefix.$name, $tableSchema, $options );
                 
-                //print("<hr/><pre>");
                 foreach( $sqlarray as $sql ) {
-                    //print($sql."<br/>");
                     // and run the query
                     if( !$this->_db->Execute( $sql )) {
-                        /*if($tableId != "Deletions"){
-                            $errors = true;                    
-                            $errorMessage .= $this->_db->ErrorMsg()."<br/>";
-                        }*/
+                        $table_errors = true;
                         $errors = true;
                         $errorMessage .= $this->_db->ErrorMsg()."<br/>";
                     }
-                    //print("</pre>");
                 }
 
-                if( !$errors )
+                if( !$table_errors )
                     $message .= "Changes to table <strong>$name</strong> executed successfully.<br/>";
                 else {
                     $message .= "Error modifying table $name: ".$errorMessage;
@@ -1328,7 +1324,7 @@
 				$result = $this->_db->Execute($checkKeyQuery);
 				if ($result->RecordCount() == 0)
 				{
-		            // try to guess the url where plog is running
+                        // try to guess the url where plog is running
 		            $httpProtocol = (array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on") ? "https://" : "http://";
 		            $httpHost = $_SERVER["HTTP_HOST"];
 		            $requestUrl = $_SERVER["REQUEST_URI"];
@@ -1360,6 +1356,35 @@
 	            }
             }
 
+                // check to see if we need to remove duplicates and the id index
+            $query = "SELECT id FROM ".$this->_dbPrefix."config LIMIT 1";
+            $result = $this->_db->Execute($query);
+                // if $result is false, id column has already been removed
+            if($result){
+                $result->Close();
+            
+                    // remove all duplicates in plog_config table
+                $query = "DELETE a FROM ".$this->_dbPrefix."config a, ".$this->_dbPrefix."config b WHERE a.id > b.id " .
+                    "AND a.config_key = b.config_key";
+                $result = $this->_db->Execute($query);
+                if(!$result){
+                    $message .= "Error removing duplicates in config table: ".$this->_db->ErrorMsg()."<br/>";
+                    $errors = true;
+                }
+                else{
+                    $result->Close();
+
+                    // remove index id field, we don't need it any more!
+                    $query = "ALTER TABLE ".$this->_dbPrefix."config DROP COLUMN id";
+                    $result = $this->_db->Execute($query);
+                    if(!$result){
+                        $message .= "Error removing old id column from config table: ".$this->_db->ErrorMsg()."<br/>";
+                        $errors = true;
+                    }
+                    $result->Close();
+                }
+            }
+            
             //
             // there's nothing left to do so we can quit now!!
             //



More information about the pLog-svn mailing list