[pLog-svn] r4616 - plog/branches/lifetype-1.2

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon Jan 29 17:34:01 EST 2007


Author: oscar
Date: 2007-01-29 17:34:01 -0500 (Mon, 29 Jan 2007)
New Revision: 4616

Modified:
   plog/branches/lifetype-1.2/wizard.php
Log:
Moved some code from UpdateStepTwo to their own classes so that they can be executed in UpdateStepThree as separate steps.

Modified: plog/branches/lifetype-1.2/wizard.php
===================================================================
--- plog/branches/lifetype-1.2/wizard.php	2007-01-29 21:53:12 UTC (rev 4615)
+++ plog/branches/lifetype-1.2/wizard.php	2007-01-29 22:34:01 UTC (rev 4616)
@@ -1332,7 +1332,6 @@
         function perform()
         {
             global $Tables;
-            global $Inserts;
 
             // connect to the db
             $this->_db = connectDb();
@@ -1393,127 +1392,6 @@
                              
             }
 
-            // check the configuration and add the new configuration settings that were added for 1.2
-            foreach( $Inserts as $key => $insert ) {
-				$checkKeyQuery = "SELECT * FROM ".$this->_dbPrefix."config WHERE config_key ='".$key."';";
-				$result = $this->_db->Execute($checkKeyQuery);
-                if(!$result){
-                    $message .= "Error executing code: ".$this->_db->ErrorMsg()."<br/>";
-                    $errors = true;
-                }
-				else{
-                    if ($result->RecordCount() == 0){
-                            // 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"];
-                        $requestUrl = str_replace( "/wizard.php", "", $requestUrl );
-                        $plogUrl = $httpProtocol.$httpHost.$requestUrl;
-                            // Find some of the tools we are going to need (last one is for os x, with fink installed)
-                            // TBD: support for Windows specific directories
-                        $folders = Array( "/bin/", "/usr/bin/", "/usr/local/bin/", "/sw/bin/" );
-                        $finder = new FileFinder();
-                        $pathToUnzip = $finder->findBinary( "unzip", $folders );
-                        $pathToTar = $finder->findBinary( "tar", $folders);
-                        $pathToGzip = $finder->findBinary( "gzip", $folders);
-                        $pathToBzip2 = $finder->findBinary( "bzip2", $folders);
-                        $pathToConvert = $finder->findBinary( "convert", $folders);
-                            // replace the de prefix and base url
-                        $query = str_replace( "{dbprefix}", $this->_dbPrefix, $insert );
-                        $query = str_replace( "{plog_base_url}", $plogUrl, $query );
-                            // replace also the placeholders for the paths to the tools
-                        $query = str_replace( "{path_to_tar}", $pathToTar, $query );
-                        $query = str_replace( "{path_to_unzip}", $pathToUnzip, $query );
-                        $query = str_replace( "{path_to_bz2}", $pathToBzip2, $query );
-                        $query = str_replace( "{path_to_gzip}", $pathToGzip, $query );
-                        $query = str_replace( "{path_to_convert}", $pathToConvert, $query );
-                        $query = str_replace( "{path_to_convert}", $pathToConvert, $query );
-                        if( !$this->_db->Execute( $query )) {
-                            $message .= "Error executing code: ".$this->_db->ErrorMsg()."<br/>";
-                            $errors = true;
-                        }
-                    }
-                    $result->Close();
-                }
-            }
-                // 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
-                    
-                    // first create temp table without the duplicates
-                $query = "CREATE TEMPORARY TABLE tmptable ".
-                         "SELECT * FROM ".$this->_dbPrefix."config WHERE 1 GROUP BY config_key";
-                $result = $this->_db->Execute($query);
-                if($result){
-                    //$result->Close();
-                        // Now delete the old table
-                    $query = "DELETE FROM ".$this->_dbPrefix."config";
-                    $result = $this->_db->Execute($query);
-                    if($result){
-                        //$result->Close();
-                        // Insert the unique rows into the old table
-                        $query = "INSERT INTO ".$this->_dbPrefix."config SELECT * FROM tmptable";
-                        $result = $this->_db->Execute($query);
-                    }
-                }
-                if(!$result){
-                    $message .= "Error removing duplicates in config table: ".
-                        $this->_db->ErrorMsg()."<br/>";
-                    $errors = true;
-                }
-
-                if($result){
-
-                    // 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;
-                    }
-                }
-            }
-
-			//
-			// load the new list of permissions
-			//
-			// load the core permissions
-		    include_once( PLOG_CLASS_PATH."install/corepermissions.properties.php" );
-
-		    // process permissions
-		    $total = 0;		
-		    foreach( $permissions as $perm ) {
-			    // check if it already exists
-			    $query = "SELECT * FROM ".Db::getPrefix()."permissions WHERE permission = '".$perm[0]."'";
-			    $result = $this->_db->Execute( $query );
-			    if( !$result || $result->RowCount() < 1 ) {				
-				   	// permission needs to be added
-					$corePerm = ( $perm[2] == true ? 1 : 0 );
-					$adminOnly = ( $perm[3] == true ? 1 : 0 );
-					$query = "INSERT INTO ".Db::getPrefix()."permissions (permission,description,core_perm,admin_only) ".
-					          "VALUES ('".$perm[0]."','".$perm[1]."','".$corePerm."','".$adminOnly."')";
-					$this->_db->Execute( $query );
-					$total++;
-			    }
-		    }
-		
-			//
-			// prepare the users_permissions table for the next step
-			//
-			if( !$this->_db->Execute( "INSERT INTO ".Db::getPrefix()."tmp_users_permissions SELECT * FROM ".Db::getPrefix()."users_permissions WHERE blog_id != 0 AND permission_id != 1" )) {
-				$message .= "Error preparing the users_permissions table for transformation";
-				$errors = true;
-			}
-			else {
-				$this->_db->Execute( "DELETE FROM ".Db::getPrefix()."users_permissions" );
-				$errors = false;
-			}
-            
             //
             // there's nothing left to do so we can quit now!!
             //
@@ -1639,7 +1517,7 @@
     
         function perform()
         {
-            $this->message = "<b>Updating user permissions (step 1 of 3)</b><br/><br/>";        
+            $this->message = "<b>Updating user permissions (step 3 of 5)</b><br/><br/>";        
         
             $query3 = "SELECT * FROM ".Db::getPrefix()."tmp_users_permissions";
             $res3 = $this->Execute( $query3, $this->page, $this->itemsPerPage );
@@ -1673,11 +1551,165 @@
 				}
             }
         
-            $this->message .= "{$this->updatedRecords} users updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
+            $this->message .= "{$this->updatedRecords} users updated (".$this->getPercentProcessed()."%)<br/>";
             return true;        
         }
     }
 
+	class PermissionLoader extends DatabaseDataTransformer
+	{
+		
+		//
+		// load the new list of permissions
+		//		
+		function getNumSteps()
+		{
+			return( 0 );
+		}
+		
+		function perform()
+		{
+			// initial message, no errors yet
+            $this->message = "<b>Loading new permissions (step 1 of 5)</b><br/><br/>";			
+			$errors = false;
+			
+			// load the core permissions
+		    include_once( PLOG_CLASS_PATH."install/corepermissions.properties.php" );	
+
+		    // process permissions
+		    $total = 0;		
+		    foreach( $permissions as $perm ) {
+			    // check if it already exists
+			    $query = "SELECT * FROM ".$this->dbPrefix."permissions WHERE permission = '".$perm[0]."'";
+			    $result = $this->Execute( $query );
+			    if( !$result || $result->RowCount() < 1 ) {				
+				   	// permission needs to be added
+					$corePerm = ( $perm[2] == true ? 1 : 0 );
+					$adminOnly = ( $perm[3] == true ? 1 : 0 );
+					$query = "INSERT INTO ".$this->dbPrefix."permissions (permission,description,core_perm,admin_only) ".
+					          "VALUES ('".$perm[0]."','".$perm[1]."','".$corePerm."','".$adminOnly."')";
+					$this->_db->Execute( $query );
+					$total++;
+			    }
+		    }
+		
+			//
+			// prepare the users_permissions table for the next step
+			//
+			if( !$this->Execute( "INSERT INTO ".$this->dbPrefix."tmp_users_permissions SELECT * FROM ".$this->dbPrefix."users_permissions WHERE blog_id != 0 AND permission_id != 1" )) {
+				$this->message .= "Error preparing the users_permissions table for transformation";
+				$errors = true;
+			}
+			else {
+				$this->Execute( "DELETE FROM ".$this->dbPrefix."users_permissions" );
+				$this->message .= count($permissions)." permissions successfully loaded";
+				$errors = false;
+			}				
+			
+			return( !$errors );			
+		}	
+	}
+
+	class ConfigDataTransformer extends DatabaseDataTransformer
+	{
+		function getNumSteps()
+		{
+			return( 0 );
+		}
+		
+		function perform()
+		{
+			print("here?");
+		    global $Inserts;	
+			
+            $this->message = "<b>Adding new configuration parameters (step 3 of 5)</b><br/><br/>";
+			$errors = false;
+			
+            // Find some of the tools we are going to need (last one is for os x, with fink installed), this will be needed later on
+            $folders = Array( "/bin/", "/usr/bin/", "/usr/local/bin/", "/sw/bin/" );
+            $finder = new FileFinder();
+            $pathToUnzip = $finder->findBinary( "unzip", $folders );
+            $pathToTar = $finder->findBinary( "tar", $folders);
+            $pathToGzip = $finder->findBinary( "gzip", $folders);
+            $pathToBzip2 = $finder->findBinary( "bzip2", $folders);
+            $pathToConvert = $finder->findBinary( "convert", $folders);
+
+            // check the configuration and add the new configuration settings that were added for 1.2
+            foreach( $Inserts as $key => $insert ) {
+				$checkKeyQuery = "SELECT * FROM ".$this->dbPrefix."config WHERE config_key ='".$key."';";
+				$result = $this->Execute($checkKeyQuery);
+                if(!$result){
+                    $this->message .= "Error executing code: ".$this->_db->ErrorMsg()."<br/>";
+                    $errors = true;
+                }
+				else{
+                    if ($result->RecordCount() == 0) {	
+                        // replace the prefix
+                        $query = str_replace( "{dbprefix}", $this->dbPrefix, $insert );
+                        // replace also the placeholders for the paths to the tools
+                        $query = str_replace( "{path_to_tar}", $pathToTar, $query );
+                        $query = str_replace( "{path_to_unzip}", $pathToUnzip, $query );
+                        $query = str_replace( "{path_to_bz2}", $pathToBzip2, $query );
+                        $query = str_replace( "{path_to_gzip}", $pathToGzip, $query );
+                        $query = str_replace( "{path_to_convert}", $pathToConvert, $query );
+                        $query = str_replace( "{path_to_convert}", $pathToConvert, $query );
+                        if( !$this->Execute( $query )) {
+                            $this->message .= "Error executing code: ".$this->_db->ErrorMsg()."<br/>";
+                            $errors = true;
+                        }
+                    }
+                    $result->Close();
+                }
+            }
+                // check to see if we need to remove duplicates and the id index
+            $query = "SELECT id FROM ".$this->dbPrefix."config LIMIT 1";
+            $result = $this->Execute($query);
+                // if $result is false, id column has already been removed
+            if($result){
+                $result->Close();           
+                    // remove all duplicates in plog_config table
+                    
+                    // first create temp table without the duplicates
+                $query = "CREATE TEMPORARY TABLE tmptable ".
+                         "SELECT * FROM ".$this->dbPrefix."config WHERE 1 GROUP BY config_key";
+                $result = $this->Execute($query);
+                if($result){
+                    //$result->Close();
+                        // Now delete the old table
+                    $query = "DELETE FROM ".$this->dbPrefix."config";
+                    $result = $this->Execute($query);
+                    if($result) {
+                        //$result->Close();
+                        // Insert the unique rows into the old table
+                        $query = "INSERT INTO ".$this->dbPrefix."config SELECT * FROM tmptable";
+                        $result = $this->Execute($query);
+                    }
+                }
+                /*if(!$result){
+                    $this->message .= "Error removing duplicates in config table<br/>";
+                    $errors = true;
+                }*/
+
+                if($result){
+
+                    // remove index id field, we don't need it any more!
+                    $query = "ALTER TABLE ".$this->dbPrefix."config DROP COLUMN id";
+                    $result = $this->Execute($query);
+                    if(!$result){
+                        $this->message .= "Error removing old id column from config table: ".$this->_db->ErrorMsg()."<br/>";
+                        $errors = true;
+                    }
+                }
+            }			
+
+			if( !$errors ) {
+				$this->message = "Configuration settings updated successfully";
+			}
+			
+			return( !$errors );
+		}		
+	}
+
     /**
 	 * Processes all admin users and grants the appropriate permissions
      */
@@ -1690,7 +1722,7 @@
     
         function perform()
         {
-            $this->message = "<b>Updating admin user permissions (step 1 of 3)</b><br/><br/>";        
+            $this->message = "<b>Updating admin user permissions (step 2 of 5)</b><br/><br/>";        
         
             // load each one of the categories and update them
             // list of categories
@@ -1707,8 +1739,7 @@
 			$allPerms = $permissions->getAllPermissions();
 			
             while( $row = $res3->FetchRow()) {
-            	if( $row["site_admin"] == "1" ) {
-					print("processing admin user = ".$row["id"]."<br/>");
+            	if( $row["site_admin"] > 0 ) {
 					// it's an admin, let's grant all the appropriate permissions
 					foreach( $allPerms as $perm ) {
 						if( $perm->isAdminOnlyPermission() && $perm->getName() != "login_perm" ) {
@@ -1724,7 +1755,7 @@
 				$this->updatedRecords++;
             }
         
-            $this->message .= "{$this->updatedRecords} users updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
+            $this->message .= "{$this->updatedRecords} users updated (".$this->getPercentProcessed()."%)<br/>";
             return true;        
         }
     }
@@ -1741,7 +1772,7 @@
     
         function perform()
         {
-            $this->message = "<b>Updating resource files (step 3 of 3)</b><br/><br/>";        
+            $this->message = "<b>Updating resource files (step 5 of 5)</b><br/><br/>";        
         
             $query1 = "SELECT id, owner_id, file_name, resource_type, thumbnail_format FROM ".$this->dbPrefix."gallery_resources";
 
@@ -1859,8 +1890,10 @@
              * array with the data transformers that will be run
              */
             $this->transformers = Array(
+				"PermissionLoader",
 				"AdminUserPermissionsDataTransformer",
 				"UserPermissionsDataTransformer",
+				"ConfigDataTransformer",
 				"ResourcesDataTransformer"
             );
             
@@ -1910,7 +1943,7 @@
                 $this->_view->setValue( "transformerId", $this->currentTransformerId );            
                 $this->_view->setValue( "error", true );
                 if( $transformer->DbError() != "" ) {
-                    $message .= "<br/><br/>The database error message was: ".$transformer->DbError()."<br/>";
+                    $message .= "<br/>The database error message was: ".$transformer->DbError()."<br/>";
                 }
 
                 $this->_view->setErrorMessage( $message );



More information about the pLog-svn mailing list