[pLog-svn] r4694 - in plog/branches/lifetype-1.2: . templates/wizard

oscar at devel.lifetype.net oscar at devel.lifetype.net
Tue Feb 6 01:53:09 EST 2007


Author: oscar
Date: 2007-02-06 01:53:08 -0500 (Tue, 06 Feb 2007)
New Revision: 4694

Modified:
   plog/branches/lifetype-1.2/templates/wizard/header.template
   plog/branches/lifetype-1.2/templates/wizard/update3.template
   plog/branches/lifetype-1.2/wizard.php
Log:
moved the database schema checks/transformation to its own pages process, and now the changes are undertaken one step at a time with the page being reloaded automatically. This seems to fix the timeout issues some users were having when updating big databases.


Modified: plog/branches/lifetype-1.2/templates/wizard/header.template
===================================================================
--- plog/branches/lifetype-1.2/templates/wizard/header.template	2007-02-05 22:15:16 UTC (rev 4693)
+++ plog/branches/lifetype-1.2/templates/wizard/header.template	2007-02-06 06:53:08 UTC (rev 4694)
@@ -41,8 +41,7 @@
 	       <li {if $step==1}class="currentStep"{/if}>1 Checks</li>
            <li {if $step==2}class="currentStep"{/if}>&raquo; 2 Update</li>
            <li {if $step==3}class="currentStep"{/if}>&raquo; 3 Database Changes</li>
-           <li {if $step==4}class="currentStep"{/if}>&raquo; 4 Data changes</li>
-           <li {if $step==5}class="currentStep"{/if}>&raquo; 5 Done!</li>
+           <li {if $step==5}class="currentStep"{/if}>&raquo; 4 Done!</li>
           </ul>
           {/if}
           <br style="clear:both;"/>

Modified: plog/branches/lifetype-1.2/templates/wizard/update3.template
===================================================================
--- plog/branches/lifetype-1.2/templates/wizard/update3.template	2007-02-05 22:15:16 UTC (rev 4693)
+++ plog/branches/lifetype-1.2/templates/wizard/update3.template	2007-02-06 06:53:08 UTC (rev 4694)
@@ -20,7 +20,7 @@
 </fieldset>
 <div class="buttons">
    {if !$complete}
-   <input type="hidden" name="nextStep" value="Update3"/>
+   <input type="hidden" name="nextStep" value="Update2"/>
    {else}
    {if !$viewIsError}
    <input type="hidden" name="nextStep" value="Update4"/>   
@@ -29,7 +29,7 @@
    {/if}
    {/if}
    {if $viewIsError}
-     <input type="hidden" name="nextStep" value="Update3"/>   
+     <input type="hidden" name="nextStep" value="Update2"/>   
      <input type="submit" name="continue" value="Continue" />
    {/if}   
    <input type="hidden" name="page" value="{$nextStep}" />

Modified: plog/branches/lifetype-1.2/wizard.php
===================================================================
--- plog/branches/lifetype-1.2/wizard.php	2007-02-05 22:15:16 UTC (rev 4693)
+++ plog/branches/lifetype-1.2/wizard.php	2007-02-06 06:53:08 UTC (rev 4694)
@@ -89,7 +89,6 @@
     $_actionMap["Step5"] = "WizardStepFive";
     $_actionMap["Update1"] = "UpdateStepOne";
     $_actionMap["Update2"] = "UpdateStepTwo";
-    $_actionMap["Update3"] = "UpdateStepThree";
 
 
     /**
@@ -1313,101 +1312,6 @@
             $this->setCommonData();
         }
     }
-
-    class UpdateStepTwo extends WizardAction
-    {
-
-        var $_db;
-        var $_dbPrefix;
-
-        function validate()
-        {
-            $configFile = new ConfigFileStorage();
-            $this->_dbPrefix = $configFile->getValue( "db_prefix" );
-
-            return true;
-        }
-
-        
-        function perform()
-        {
-            global $Tables;
-
-            // connect to the db
-            $this->_db = connectDb();
-
-            // store error messages in this var
-            $message = "";
-
-            if( !$this->_db ) {
-                $this->_view = new WizardView( "update1" );
-                WizardStepTwo::setDbConfigValues( $this->_view );
-                $this->_view->setErrorMessage( "There was an error connecting to the database. Please check your settings." );
-                return false;
-            }
-
-            // ---
-            // make changes to the tables that need changes, but leave it up to the data dictionary
-            // to take care of the changes
-            // ---
-            $dict = NewPDbDataDictionary( $this->_db );            
-            $errors = false;
-            foreach( $Tables as $name => $table ) {
-                $errorMessage = "";
-                $table_errors = false;
-            	$upperName = $dict->upperName;
-            	$tableSchema = $table["schema"];
-            	if ( isset( $table["options"] ) )
-            	{
-            		$tableOptions = $table["options"];
-            		$options = array ( $upperName => $tableOptions );
-            	} else {
-            		$options = array ();
-                }
-               
-                // generate the code with the changes for the table
-                $sqlarray = $dict->ChangeTableSQL( $this->_dbPrefix.$name, $tableSchema, $options );
-                
-                foreach( $sqlarray as $sql ) {
-                    // and run the query
-                    if( !$this->_db->Execute( $sql )) {
-                        $table_errors = true;
-                        $errors = true;
-                        $errorMessage .= $this->_db->ErrorMsg()."<br/>";
-                    }
-                }
-
-                if( !$table_errors )
-                    $message .= "Changes to table <strong>$name</strong> executed successfully.<br/>";
-                else {
-                    $message .= "Error modifying table $name: ".$errorMessage;
-                }
-            }
-
-            if( !$errors ) {
-                $message .= "<br/><b>** Modifications to the database schema carried out successfully **</b><br/><br/>";
-                $message .= "The next step will update some of the data in your database. This process may take a while
-                             depending on the amount of data in your database, and the browser will periodically refresh
-                             to avoid timeout issues. <b>Please do not attempt to interrupt this process.</b>";
-                             
-            }
-
-            //
-            // there's nothing left to do so we can quit now!!
-            //
-            if( !$errors ) {
-                $this->_view = new WizardView( "update2" );
-                $this->_view->setValue( "message", $message );
-            }
-            else {
-                $this->_view = new WizardView( "update1" );
-                WizardStepTwo::setDbConfigValues( $this->_view );
-                $this->_view->setErrorMessage( $message );
-            }
-
-            return true;
-        }
-    }
     
     /**
      * Generic class that performs data updates on the database
@@ -1504,6 +1408,71 @@
             return((int)($processed / ( $this->getNumSteps() * $this->itemsPerPage ) * 100 ));
         }
     }
+
+	/**
+	 * This step takes care of transforming the database schema, one
+	 * table at a time.
+	 */
+	class DatabaseSchemaDataTransformer extends DatabaseDataTransformer
+	{		
+		function getNumSteps()
+		{
+			global $Tables;			
+			return( count( $Tables ) - 1);
+		}
+		
+		function perform()
+		{
+			global $Tables;
+			
+			$tablesArray = array_keys( $Tables );
+			$curTable = $tablesArray[$this->page-1];
+						
+			//print("Processing page: ".$this->page." - table: ".$curTable."<br/>" );			
+
+			$db =& Db::getDb();
+            $dict = NewPDbDataDictionary( $db );
+            $errors = false;
+
+			$this->message = "Performing changes to the dabase schema, please wait (step 1 of 6)<br/>";
+
+			$errorMessage = "";
+			$table_errors = false;
+			$upperName = $dict->upperName;
+			$tableSchema = $Tables[$curTable]["schema"];
+			if ( isset( $Tables[$curTable]["options"] )) {
+				$tableOptions = $Tables[$curTable]["options"];
+				$options = array ( $upperName => $tableOptions );
+			} 
+			else {
+				$options = array ();
+			}
+
+			// generate the code with the changes for the table
+			$sqlarray = $dict->ChangeTableSQL( $this->getPrefix().$curTable, $tableSchema, $options );
+
+			foreach( $sqlarray as $sql ) {
+				// and run the query
+				//print( "sql: ".$sql."<br/>" );
+				if( !$this->Execute( $sql )) {
+					$table_errors = true;
+					$errors = true;
+					$errorMessage .= $this->_db->ErrorMsg()."<br/>";
+				}
+			}
+
+			if( !$table_errors ) {
+				$this->message .= "Changes to table <strong>$curTable</strong> executed successfully.<br/>";
+				$result = true;
+			}
+			else {
+				$this->message .= "Error modifying table $curTAble: ".$errorMessage;
+				$result = false;
+			}
+
+			return( $result ); 
+		}
+	}
     
     /**
 	 * Processes all users and grants the appropriate permissions
@@ -1517,7 +1486,7 @@
     
         function perform()
         {
-            $this->message = "<b>Updating user permissions (step 3 of 5)</b><br/><br/>";        
+            $this->message = "<b>Updating user permissions (step 4 of 6)</b><br/><br/>";        
         
             $query3 = "SELECT * FROM ".Db::getPrefix()."tmp_users_permissions";
             $res3 = $this->Execute( $query3, $this->page, $this->itemsPerPage );
@@ -1570,7 +1539,7 @@
 		function perform()
 		{
 			// initial message, no errors yet
-            $this->message = "<b>Loading new permissions (step 1 of 5)</b><br/><br/>";			
+            $this->message = "<b>Loading new permissions (step 2 of 6)</b><br/><br/>";			
 			$errors = false;
 			
 			// load the core permissions
@@ -1619,10 +1588,9 @@
 		
 		function perform()
 		{
-			print("here?");
 		    global $Inserts;	
 			
-            $this->message = "<b>Adding new configuration parameters (step 3 of 5)</b><br/><br/>";
+            $this->message = "<b>Adding new configuration parameters (step 4 of 6)</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
@@ -1722,7 +1690,7 @@
     
         function perform()
         {
-            $this->message = "<b>Updating admin user permissions (step 2 of 5)</b><br/><br/>";        
+            $this->message = "<b>Updating admin user permissions (step 3 of 6)</b><br/><br/>";        
         
             // load each one of the categories and update them
             // list of categories
@@ -1772,7 +1740,7 @@
     
         function perform()
         {
-            $this->message = "<b>Updating resource files (step 5 of 5)</b><br/><br/>";        
+            $this->message = "<b>Updating resource files (step 6 of 6)</b><br/><br/>";        
         
             $query1 = "SELECT id, owner_id, file_name, resource_type, thumbnail_format FROM ".$this->dbPrefix."gallery_resources";
 
@@ -1874,15 +1842,15 @@
      * the methods DatabaseDataTransformer::perform() and DatabaseDataTransformer::getNumSteps(). The
      * first does the data processing while the second one returns the number of needed steps to the
      * class running the transformer.
-     * - Add the name of the transformer class to the the UpdateStepThree::transformers array,
+     * - Add the name of the transformer class to the the UpdateStepTwo::transformers array,
      * and the class will take care of everything else. 
      */
-    class UpdateStepThree extends WizardPagedAction
+    class UpdateStepTwo extends WizardPagedAction
     {
         var $message;    
         var $currentTransformerId;
     
-        function UpdateStepThree( $actionInfo, $httpRequest )
+        function UpdateStepTwo( $actionInfo, $httpRequest )
         {
             $this->WizardPagedAction( $actionInfo, $httpRequest );
             
@@ -1890,6 +1858,7 @@
              * array with the data transformers that will be run
              */
             $this->transformers = Array(
+				"DatabaseSchemaDataTransformer",
 				"PermissionLoader",
 				"AdminUserPermissionsDataTransformer",
 				"UserPermissionsDataTransformer",



More information about the pLog-svn mailing list