[pLog-svn] r4394 - plog/trunk

oscar at devel.lifetype.net oscar at devel.lifetype.net
Mon Dec 18 22:35:15 GMT 2006


Author: oscar
Date: 2006-12-18 22:35:14 +0000 (Mon, 18 Dec 2006)
New Revision: 4394

Modified:
   plog/trunk/wizard.php
Log:
some work done towards getting wizard.php being able to ugprade from LT 1.1.x to 1.2.x. At least most of the permissions stuff seems to work, though it is granting too many permissions for non-blog owners at the moment. Updating resource files (to convert them from something like 1-44.jpg to their "real" name) will be implemented after this.


Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php	2006-12-18 04:16:17 UTC (rev 4393)
+++ plog/trunk/wizard.php	2006-12-18 22:35:14 UTC (rev 4394)
@@ -1380,7 +1380,7 @@
                              
             }
 
-            // check the configuration and add the new configuration settings that were added for 1.1
+            // 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);
@@ -1437,12 +1437,12 @@
                          "SELECT * FROM ".$this->_dbPrefix."config WHERE 1 GROUP BY config_key";
                 $result = $this->_db->Execute($query);
                 if($result){
-                    $result->Close();
+                    //$result->Close();
                         // Now delete the old table
                     $query = "DELETE FROM ".$this->_dbPrefix."config";
                     $result = $this->_db->Execute($query);
                     if($result){
-                        $result->Close();
+                        //$result->Close();
                         // Insert the unique rows into the old table
                         $query = "INSERT INTO ".$this->_dbPrefix."config SELECT * FROM tmptable";
                         $result = $this->_db->Execute($query);
@@ -1465,6 +1465,41 @@
                     }
                 }
             }
+
+			//
+			// 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!!
@@ -1580,425 +1615,112 @@
     }
     
     /**
-     * updates the article category counters based on the number of posts that have
-     * been assigned to each category
+	 * Processes all users and grants the appropriate permissions
      */
-    class CategoryCountersDataTransformer extends DatabaseDataTransformer
+    class UserPermissionsDataTransformer extends DatabaseDataTransformer
     {        
         function getNumSteps()
         {
-            return( parent::getNumSteps( "articles_categories" ));
+            return( parent::getNumSteps( "tmp_users_permissions" ));
         }
     
         function perform()
         {
-            $this->message = "<b>Updating article categories (step 2 of 9)</b><br/><br/>";        
+            $this->message = "<b>Updating user permissions (step 1 of 2)</b><br/><br/>";        
         
-            // load each one of the categories and update them
-            // list of categories
-            $query3 = "SELECT id FROM ".$this->dbPrefix."articles_categories";            
+            $query3 = "SELECT * FROM ".Db::getPrefix()."tmp_users_permissions";
             $res3 = $this->Execute( $query3, $this->page, $this->itemsPerPage );
-            $catIds = Array();
             if( $res3->RecordCount() == 0 ) {
 				$this->message .= "No more records to process";
 				return( true );
 			}
+			
+			$permissions = new Permissions();
+			$userPermissions = new UserPermissions();
+			$allPerms = $permissions->getAllPermissions();			
+			
             while( $row = $res3->FetchRow()) {
-            	$catIds[] = $row["id"];
+            	// grant all the non-admin permissions so that users can still access the blogs to where they still had permissions
+				if( $row["permission_id"] != 3) {
+					foreach( $allPerms as $perm ) {
+						print( "granting perm: ".$perm->getName()." - user: ".$row["user_id"]." - blog id: ".$row["blog_id"]."<br/>");
+						if( !$perm->isAdminOnlyPermission()) {
+							$perm = new UserPermission( $row["user_id"], $row["blog_id"], $perm->getId());
+							$userPermissions->grantPermission( $perm );
+						}
+					}					
+				}
             }
-            $where = "(".implode( $catIds, "," ).")";
-            
-            // total number of articles
-            $query1 = "SELECT category_id, COUNT(*) AS total FROM ".$this->dbPrefix."article_categories_link ".
-                      "WHERE category_id IN {$where} GROUP BY category_id";
-            // number of active articles
-            $query2 = "SELECT l.category_id AS category_id, COUNT(*) AS total FROM ".
-                       $this->dbPrefix."article_categories_link l, ".$this->dbPrefix."articles a ".
-                       "WHERE a.id = l.article_id AND a.status = ".POST_STATUS_PUBLISHED." AND l.category_id IN {$where} ".
-                       "GROUP BY l.category_id";                   
-                      
-            // execute the 1st query
-            $res1 = $this->Execute( $query1 );
-            if( !$res1 ) {
-                $this->message .= "Error performing changes to the categories table";
-                return false;
-            }
-            $numArticles = Array();
-            while( $row = $res1->FetchRow()) {
-                $numArticles[$row["category_id"]] = $row["total"];
-            }
-            $res1->Close();
-                        
-            // total number of active comments
-            $res2 = $this->Execute( $query2 );
-            if( !$res2 ) {
-                $this->message .= "Error performing changes to the categories table";
-                return false;
-            }
-            $numActiveArticles = Array();
-            while( $row = $res2->FetchRow()) {
-                $numActiveArticles[$row["category_id"]] = $row["total"];
-            }
-            $res2->Close();                       
-            
-			foreach( $catIds as $catId ) {
-                // load the counters
-                $totalArticles = '';
-                $totalActiveArticles = '';
-                if( isset( $numArticles[$catId] ))
-                    $totalArticles = $numArticles[$catId];                    
-                if( $totalArticles == '' ) $totalArticles = 0;
-                if( isset( $numActiveArticles[$catId] ))
-                    $totalActiveArticles = $numActiveArticles[$catId];
-                if( $totalActiveArticles == '' ) $totalActiveArticles = 0;
-                
-                // build the update query
-                $query = "UPDATE ".$this->dbPrefix."articles_categories SET num_articles = {$totalArticles},
-                          num_published_articles = {$totalActiveArticles},
-                          last_modification = last_modification
-                          WHERE id = {$catId}";
-                          
-                // and execute it
-                $result = $this->Execute( $query );
-                if( !$result ) {
-                    $this->message .= "Error updating category with id {$catId}<br/>";
-                }
-                else
-                    $this->updatedRecords++;
-            }
-            $res3->Close();
         
-            $this->message .= "{$this->updatedRecords} categories updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
+            $this->message .= "{$this->updatedRecords} users updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
             return true;        
         }
     }
-    
-    /**
-     * updates blog article counters
-     */
-    class ArticleCountersDataTransformer extends DatabaseDataTransformer
-    {        
-        function getNumSteps()
-        {
-            return( parent::getNumSteps( "articles" ));
-        }
-        
-        function perform()
-        {
-            include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-            include_once( PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" );
-            
-            $this->message = "<b>Updating articles (step 3 of 9)</b><br/><br/>";           
-                        
-            // article ids
-            $artIds = Array();            
-            $query4 = "SELECT id FROM ".$this->dbPrefix."articles";            
-            $res4 = $this->Execute( $query4, $this->page, $this->itemsPerPage );
-            if( $res4->RecordCount() == 0 ) {
-				$this->message .= "No more records to process";				
-				return( true );
-            }
-            while( $row = $res4->FetchRow()) {
-            	$artIds[] = $row["id"];
-            }
-            $where = "(".implode( $artIds, "," ).")";
-            
-            // build the queries
-            $query1 = "SELECT article_id, COUNT(*) AS total FROM ".$this->dbPrefix."articles_comments ".
-                      "WHERE article_id IN {$where} GROUP BY article_id";
-            $query2 = "SELECT article_id, COUNT(*) AS total FROM ".$this->dbPrefix."articles_comments ".
-                      "WHERE article_id IN {$where} AND status = ".COMMENT_STATUS_NONSPAM." GROUP BY article_id";
-            $query3 = "SELECT article_id, COUNT(*) AS total FROM ".$this->dbPrefix."trackbacks ".
-                      "WHERE article_id IN {$where} GROUP BY article_id";
-            
-            // and execute all of them...
-            
-            // total number of comments
-            $res1 = $this->Execute( $query1 );
-            if( !$res1 ) {
-                $this->message .= "Error performing changes to the articles table";
-                return false;
-            }
-            $numComments = Array();
-            while( $row = $res1->FetchRow()) {
-                $numComments[$row["article_id"]] = $row["total"];
-            }
-            $res1->Close();
-            
-            // total number of active comments
-            $res2 = $this->Execute( $query2 );
-            if( !$res2 ) {
-                $this->message .= "Error performing changes to the articles table";
-                return false;
-            }
-            $numActiveComments = Array();
-            while( $row = $res2->FetchRow()) {
-                $numActiveComments[$row["article_id"]] = $row["total"];
-            }
-            $res2->Close();
-            
-            // number of trackbacks
-            $res3 = $this->Execute( $query3 );
-            if( !$res3 ) {
-                $this->message .= "Error performing changes to the articles table";
-                return false;
-            }
-            $numTrackbacks = Array();            
-            while( $row = $res3->FetchRow()) {
-                $numTrackbacks[$row["article_id"]] = $row["total"];
-            }           
-            $res3->Close();            
-            
-            foreach( $artIds as $artId ) {
-                // load the counters
-                if(isset($numComments[$artId]))
-                    $totalComments = $numComments[$artId];
-                else
-                    $totalComments = 0;
 
-                if(isset($numActiveComments[$artId]))
-                    $totalActiveComments = $numActiveComments[$artId];
-                else
-                    $totalActiveComments = 0;
-
-                if(isset($numTrackbacks[$artId]))
-                    $totalTrackbacks = $numTrackbacks[$artId];
-                else
-                    $totalTrackbacks = 0;
-                
-                // build the update query
-                $query = "UPDATE ".$this->dbPrefix."articles SET num_comments = {$totalComments},
-                          num_nonspam_comments = {$totalActiveComments},
-                          num_trackbacks = {$totalTrackbacks},
-                          num_nonspam_trackbacks = {$totalTrackbacks},
-                          date = date,
-                          modification_date = modification_date
-                          WHERE id = {$artId}";
-                          
-                // and execute it
-                $result = $this->Execute( $query );
-                if( !$result ) {
-                    $this->message .= "Error updating article with id {$artId}<br/>";
-                }
-                else
-                    $this->updatedRecords++;
-            }
-            $res4->Close();
-            
-            $processed = $this->page * $this->itemsPerPage;            
-            $this->message .= "{$this->updatedRecords} articles updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
-            
-            return( true );
-        }
-    }
-    
     /**
-     * Moves trackbacks from their own table to the comments table
+	 * Processes all admin users and grants the appropriate permissions
      */
-    class BlogTrackbacksDataTransformer extends DatabaseDataTransformer
+    class AdminUserPermissionsDataTransformer extends DatabaseDataTransformer
     {        
         function getNumSteps()
         {
-            return( parent::getNumSteps( "trackbacks" ));
+            return( parent::getNumSteps( "users" ));
         }
     
         function perform()
         {
-            $this->message = "<b>Updating trackbacks (step 4 of 9)</b><br/><br/>";        
+            $this->message = "<b>Updating admin user permissions (step 1 of 3)</b><br/><br/>";        
         
-            $query = "SELECT t.id AS id, a.blog_id AS blog_id, t.url AS url, t.title AS title, t.article_id as article_id,
-                      t.excerpt AS excerpt, t.blog_name AS blog_name, t.date AS date 
-                      FROM ".$this->dbPrefix."trackbacks t, ".$this->dbPrefix."articles a 
-                      WHERE t.article_id = a.id";
-
-            $result = $this->Execute( $query, $this->page, $this->itemsPerPage );
-            if( !$result ) {
-                $this->message .= "Error updating trackbacks.<br/>";
-                return true;
-            }
-            if( $result->RecordCount() == 0 ) {
+            // load each one of the categories and update them
+            // list of categories
+            $query3 = "SELECT id, site_admin FROM ".$this->dbPrefix."users";
+            $res3 = $this->Execute( $query3, $this->page, $this->itemsPerPage );
+            if( $res3->RecordCount() == 0 ) {
 				$this->message .= "No more records to process";
-				return( true );            
+				return( true );
+			}
+			
+			$permissions = new Permissions();
+			$userPermissions = new UserPermissions();
+			$loginPerm = $permissions->getPermissionByName( "login_perm" );
+			$allPerms = $permissions->getAllPermissions();
+			
+            while( $row = $res3->FetchRow()) {
+            	if( $row["site_admin"] == "1" ) {
+					print("processing admin user = ".$row["id"]."<br/>");
+					// it's an admin, let's grant all the appropriate permissions
+					foreach( $allPerms as $perm ) {
+						if( $perm->isAdminOnlyPermission() && $perm->getName() != "login_perm" ) {
+							$userPerm = new UserPermission( $row["id"], 0, $perm->getId());
+							$userPermissions->grantPermission( $userPerm );
+						}
+					}
+				}
+				// grant the login_perm permission or else users won't be able to log in
+				$newPerm = new UserPermission( $row["id"], 0, $loginPerm->getId());
+				$userPermissions->grantPermission( $newPerm );
+				
+				$this->updatedRecords++;
             }
-            
-            // process all trackbacks and insert them again to the comments table
-            include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
-            while( $row = $result->FetchRow()) {
-                // build the insert query
-                $insert = "INSERT INTO ".$this->dbPrefix."articles_comments
-                           (article_id, blog_id, topic, text, date, user_email, user_url, user_name, parent_id, 
-                           client_ip, send_notification, status, spam_rate, properties, normalized_text, normalized_topic, type) 
-                           VALUES (".$row["article_id"].",".$row["blog_id"].",'".Db::qstr($row["title"])."','".
-                                     Db::qstr($row["excerpt"])."','".$row["date"]."','','".$row["url"]."','".
-                                     Db::qstr($row["blog_name"])."', '0', '0.0.0.0','0', '0', '0','".
-                                     serialize(array())."','".
-                                     Textfilter::urlize( $row["excerpt"] )."','".
-                                     Textfilter::urlize( $row["title"] )."','2')";                            
-                
-                $insertRes = $this->Execute( $insert );
-                if( $insertRes )
-                    $this->updatedRecords++;
-                else
-                    $this->message .= "Error adding trackback with id ".$row["id"]."<br/>";
-            }
-            $result->Close();
-            
-            $processed = $this->page * $this->itemsPerPage;            
-            $this->message .= "{$this->updatedRecords} trackbacks modified, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";            
         
+            $this->message .= "{$this->updatedRecords} users updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
             return true;        
         }
     }
     
     /**
-     * Updates the blog counters (number of posts, number of comments, etc)
+     * processes all resource files and renames the files to their "real" names
      */
-    class BlogCountersDataTransformer extends DatabaseDataTransformer 
+    class ResourcesDataTransformer extends DatabaseDataTransformer
     {
         function getNumSteps()
         {
-            return( parent::getNumSteps( "blogs" ));
+            return( parent::getNumSteps( "gallery_resources" ));
         }
     
         function perform()
         {
-            $this->message = "<b>Updating blogs (step 1 of 9)</b><br/><br/>";
-                                
-            // list of blog ids
-            $query4 = "SELECT id, blog, owner_id FROM ".$this->dbPrefix."blogs";            
-            $res4 = $this->Execute( $query4, $this->page, $this->itemsPerPage );
-            $blogIds = Array();
-			if( $res4->RecordCount() == 0 ) {
-				$this->message .= "No more records to process";
-				return( true );
-			}
-            while( $row = $res4->FetchRow()) {
-            	// gather the blog ids and use them to reduce the amount of data that the other queries need to process            
-            	$blogIds[] = $row["id"];
-            }
-            $where = "(".implode( $blogIds, "," ).")";
-
-            // number of active articles
-            $query1 = "SELECT blog_id, COUNT(*) AS total FROM ".$this->dbPrefix."articles ".
-                      "WHERE status = ".POST_STATUS_PUBLISHED." AND blog_id IN {$where} GROUP BY blog_id";
-            // number of active comments
-            $query2 = "SELECT a.blog_id AS blog_id, COUNT(*) AS total FROM ".$this->dbPrefix."articles_comments c, ".
-                      $this->dbPrefix."articles a WHERE a.id = c.article_id AND a.status = ".POST_STATUS_PUBLISHED." ".
-                      "AND a.blog_id IN {$where} GROUP BY a.blog_id";
-            // number of trackbacks
-            $query3 = "SELECT blog_id, COUNT(*) AS total FROM ".$this->dbPrefix."trackbacks t,".
-                      $this->dbPrefix."articles a WHERE a.id = t.article_id ".
-                      "AND blog_id IN {$where} GROUP BY a.blog_id";
-            // create_date and last_update_date
-            $query5 = "SELECT blog_id, MIN(date) AS create_date, MAX(date) AS last_update_date
-                       FROM ".$this->dbPrefix."articles WHERE blog_id IN {$where} GROUP BY blog_id";                     
-                      
-            // execute the 1st query
-            $res1 = $this->Execute( $query1 );
-            if( !$res1 ) {
-                $this->message .= "Error performing changes to the blogs table";
-                return false;
-            }
-            $numArticles = Array();
-            while( $row = $res1->FetchRow()) {
-                $numArticles[$row["blog_id"]] = $row["total"];
-            }
-            $res1->Close();
-                        
-            // total number of active comments
-            $res2 = $this->Execute( $query2 );
-            if( !$res2 ) {
-                $this->message .= "Error performing changes to the blogs table";
-                return false;
-            }
-            $numComments = Array();
-            while( $row = $res2->FetchRow()) {
-                $numComments[$row["blog_id"]] = $row["total"];
-            }
-            $res2->Close();
-            
-            // total number of trackbacks
-            $res3 = $this->Execute( $query3 );
-            if( !$res3 ) {
-                $this->message .= "Error performing changes to the blogs table";
-                return false;
-            }
-            $numTrackbacks = Array();
-            while( $row = $res3->FetchRow()) {
-                $numTrackbacks[$row["blog_id"]] = $row["total"];
-            }
-            $res3->Close();
-            
-            // update and create dates
-            $res5 = $this->Execute( $query5 );
-            if( !$res5 ) {
-                $this->message .= "Error performing changes to the blogs table";
-                return false;
-            }
-            $createDates = Array();
-            $lastUpdateDates = Array();
-            while( $row = $res5->FetchRow()) {
-                $createDates[$row["blog_id"]] = $row["create_date"];
-                $lastUpdateDates[$row["blog_id"]] = $row["last_update_date"];
-            }
-            $res5->Close();            
-
-            foreach( $blogIds as $blogId ) {
-                // load the counters
-                isset( $numArticles[$blogId] ) ? $totalArticles = $numArticles[$blogId] : $totalArticles = 0;
-                isset( $numComments[$blogId] ) ? $totalComments = $numComments[$blogId] : $totalComments = 0;
-                isset( $numTrackbacks[$blogId] ) ? $totalTrackbacks = $numTrackbacks[$blogId] :$totalTrackbacks = 0;
-                
-                if( isset( $createDates[$blogId] ))
-                    $createDate = $createDates[$blogId];
-                else {
-                    $t = new Timestamp();
-                    $createDate = $t->getTimestamp();
-                }
-                if( isset( $lastUpdateDates[$blogId] ))
-                    $lastUpdateDate = $lastUpdateDates[$blogId];
-                else {
-                    $t = new Timestamp();
-                    $lastUpdateDate = $t->getTimestamp();
-                }
-                                
-                // build the update query
-                $query = "UPDATE ".$this->dbPrefix."blogs SET num_posts = {$totalArticles},
-                          num_comments = {$totalComments},
-                          num_trackbacks = {$totalTrackbacks},
-                          create_date = '{$createDate}',
-                          last_update_date = '{$lastUpdateDate}'
-                          WHERE id = {$blogId}";
-                          
-                // and execute it
-                $result = $this->Execute( $query );
-                if( !$result ) {
-                    $this->message .= "Error updating blog with id {$catId}<br/>";
-                }
-                else
-                    $this->updatedRecords++;
-            }
-            $res4->Close();
-            
-            $processed = $this->page * $this->itemsPerPage;            
-            $this->message .= "{$this->updatedRecords} blogs updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
-            return true;         
-        } 
-    }
-    
-    /**
-     * populates the site_admin field in the users table
-     */
-    class AdminUsersDataTransformer extends DatabaseDataTransformer
-    {
-        function getNumSteps()
-        {
-            return( parent::getNumSteps( "users_permissions" ));
-        }
-    
-        function perform()
-        {
-            $this->message = "<b>Updating users (step 5 of 9)</b><br/><br/>";        
+            $this->message = "<b>Updating users (step 2 of 2)</b><br/><br/>";        
         
             $query1 = "SELECT DISTINCT user_id FROM ".$this->dbPrefix."users_permissions WHERE permission_id = 1";
 
@@ -2030,260 +1752,8 @@
         
         
     }
-    
-    /**
-     * populates the article categories counter
-     */
-    class LinkCategoriesDataTransformer extends DatabaseDataTransformer
-    {
-        function getNumSteps()
-        {
-            return( parent::getNumSteps( "mylinks_categories" ));
-        }           
-    
-        function perform()
-        {
-            $this->message = "<b>Updating link categories (step 6 of 9)</b><br/><br/>";        
         
-            // load each one of the categories and update them
-            // list of categories
-            $query2 = "SELECT id FROM ".$this->dbPrefix."mylinks_categories";            
-            $res2 = $this->Execute( $query2, $this->page, $this->itemsPerPage );
-            $catIds = Array();
-            if( $res2->RecordCount() == 0 ) {
-				$this->message .= "No more records to process";
-				return( true );
-            }
-            while( $row = $res2->FetchRow()) {
-            	$catIds[] = $row["id"];
-            }
-            $where = "(".implode( $catIds, "," ).")";
-            
-            // total number of articles
-            $query1 = "SELECT category_id, COUNT(*) AS total FROM ".$this->dbPrefix."mylinks ".
-                      "WHERE category_id IN {$where} GROUP BY category_id";
-                      
-            // execute the 1st query
-            $res1 = $this->Execute( $query1 );
-            if( !$res1 ) {
-                $this->message .= "Error performing changes to the link categories table";
-                return false;
-            }
-            $numArticles = Array();
-            while( $row = $res1->FetchRow()) {
-                $numLinks[$row["category_id"]] = $row["total"];
-            }
-            $res1->Close();                       
-            
-            foreach( $catIds as $catId ) {
-                // load the counters
-                isset( $numLinks[$catId] ) ? $totalLinks = $numLinks[$catId] : $totalLinks = 0;
-                
-                // build the update query
-                $query = "UPDATE ".$this->dbPrefix."mylinks_categories SET num_links = {$totalLinks}, last_modification = last_modification
-                          WHERE id = {$catId}";
-                          
-                // and execute it
-                $result = $this->Execute( $query );
-                if( !$result ) {
-                    $this->message .= "Error updating links category with id {$catId}<br/>";
-                }
-                else
-                    $this->updatedRecords++;
-            }
-            $res2->Close();
-            
-            $processed = $this->page * $this->itemsPerPage;            
-            $this->message .= "{$this->updatedRecords} links categories updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
-            return true;        
-        }    
-    }
-    
     /**
-     * populates some fields in the comments table
-     */
-    class CommentsDataTransformer extends DatabaseDataTransformer
-    {                
-        function getNumSteps()
-        {
-            return( parent::getNumSteps( "articles_comments" ));
-        }          
-            
-        function perform()
-        {        
-            $this->message = "<b>Updating article comments (step 7 of 9)</b><br/><br/>";
-        
-            // now process all the comments
-            $query2 = "SELECT id FROM ".$this->dbPrefix."articles_comments";
-            $res2 = $this->Execute( $query2, $this->page, $this->itemsPerPage );
-            if( !$res2 ) {
-                $this->message.= "Error loading comments<br/>";
-                return false;
-            }
-            if( $res2->RecordCount() == 0 ) {
-				$this->message .= "No more records to process";
-				return( true );            
-            }
-            $commentIds = Array();
-            while( $row = $res2->FetchRow()) {
-            	$commentIds[] = $row["id"];
-            }
-            $where = "(".implode( $commentIds, "," ).")";
-            
-            // build the query
-            $query1 = "SELECT a.blog_id AS blog_id, c.id AS comment_id
-                       FROM ".$this->dbPrefix."articles a, ".$this->dbPrefix."articles_comments c
-                       WHERE a.id = c.article_id AND c.id IN {$where}"; 
-            $res1 = $this->Execute( $query1 );
-            if( !$res1 ) {
-                $this->message .= "Error loading comments<br/>";
-                return false;
-            }
-            $commentBlogIds = Array();
-            while( $row = $res1->FetchRow()) {
-                $commentBlogIds[$row["comment_id"]] = $row["blog_id"];
-            }
-            $res1->Close();                       
-            
-            foreach( $commentIds as $commentId ) {
-                // build the query      
-                $blogId = $commentBlogIds[$commentId];
-                $query = "UPDATE ".$this->dbPrefix."articles_comments
-                          SET blog_id = {$blogId}, date = date WHERE id = {$commentId}";
-                // and execute it
-                $res = $this->Execute( $query );
-                if( !$res )
-                    $this->message .= "Error updating comment with id {$commentId}<br/>";
-                else
-                    $this->updatedRecords++;
-            }
-            $res2->Close();
-            
-            $processed = $this->page * $this->itemsPerPage;            
-            $this->message .= "{$this->updatedRecords} comments updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
-        	 
-        	return true;        
-        }
-    }
-    
-    /**
-     * populates album counters
-     */
-    class AlbumsDataTransformer extends DatabaseDataTransformer
-    {            
-        function getNumSteps()
-        {
-            return( parent::getNumSteps( "gallery_albums" ));
-        }  
-        
-        function perform()
-        {
-            $this->message = "<b>Updating resource albums (step 8 of 9)</b><br/><br/>";        
-        
-            // now update all albums
-            $query3 = "SELECT id FROM ".$this->dbPrefix."gallery_albums";
-            $res3 = $this->Execute( $query3, $this->page, $this->itemsPerPage );
-            $albumIds = Array();
-            if( !$res3 ) {
-                $this->message .= "Error updating gallery albums<br/>";
-                return false;
-            }
-            if( $res3->RecordCount() == 0 ) {
-				$this->message .= "No more records to process";
-				return( true );            
-            }
-            $albumIds = Array();
-            while( $row = $res3->FetchRow()) {
-            	$albumIds[] = $row["id"];
-            }
-            $where = "(".implode( $albumIds, "," ).")";
-            
-            // load the resource counter
-        	$query1 = "SELECT album_id, COUNT(*) AS total FROM ".$this->dbPrefix."gallery_resources ".
-        	          "WHERE album_id IN {$where} GROUP BY album_id";
-        	// and the child counter
-        	$query2 = "SELECT parent_id, COUNT(*) AS total FROM ".$this->dbPrefix."gallery_albums 
-        	           WHERE parent_id > 0 AND id IN {$where} GROUP BY parent_id";
-        	           
-            $res1 = $this->Execute( $query1 );
-            if( !$res1 ) {
-                $this->message .= "Error loading resources<br/>";
-                return false;
-            }
-            $numResources = Array();
-            while( $row = $res1->FetchRow()) {
-                $numResources[$row["album_id"]] = $row["total"];
-            }
-            $res1->Close();
-            
-            $res2 = $this->Execute( $query2 );
-            if( !$res2 ) {
-                $this->message .= "Error loading albums<br/>";
-                return false;
-            }
-            $numChildren = Array();
-            while( $row = $res2->FetchRow()) {
-                $numChildren[$row["parent_id"]] = $row["total"];
-            }
-            $res2->Close();            
-            
-            foreach( $albumIds as $albumId ) {
-                isset( $numResources[$albumId] ) ? $resources = $numResources[$albumId] : $resources = 0;
-                isset( $numChildren[$albumId]) ? $children = $numChildren[$albumId] : $children = 0;
-                
-                // build the query
-                $query = "UPDATE ".$this->dbPrefix."gallery_albums
-                          SET num_children = {$children}, num_resources = {$resources}, date = date
-                          WHERE id = {$albumId}";
-                // and execute it
-                $res = $this->Execute( $query );
-                if( !$res )
-                    $this->message .= "Error updating gallery album with id {$albumId}<br/>";
-                else
-                    $this->updatedRecords++;
-            }
-            $res3->Close();
-             
-            $processed = $this->page * $this->itemsPerPage;
-            $this->message .= "{$this->updatedRecords} gallery albums updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
-            
-            return true;
-        }
-    }
-    
-    /**
-     * drops a few fields and tables that are not needed anymore
-     */
-    class PostSchemaDataTransformer extends DatabaseDataTransformer
-    {
-        function getNumSteps()
-        {
-            // everything's done in one step
-            return( 1 );
-        }       
-            
-        function perform()
-        {
-            $this->message = "<b>Removing unneeded database fields and tables (step 9 of 9)</b><br/><br/>";        
-        
-        	global $Changes;
-        	
-            foreach( $Changes as $change ) {
-                // replace the de prefix and base url
-                $query = str_replace( "{dbprefix}", $this->dbPrefix, $change );
-                $result = $this->Execute( $query  );
-                if( !$result ) {
-                	$this->message .= "Error updating database schema {$query}<br/>";
-                }
-            }
-            
-            $this->message .= "Database schema updated.<br/>";
-            
-            return true;        
-        }
-    }
-    
-    /**
      * This class is basically now a "data transformer runner", because now it works
      * like class that executes data transformers, collects their results and refreshes
      * the page to execute the next step of the transformer. If the current transformer
@@ -2321,15 +1791,9 @@
              * array with the data transformers that will be run
              */
             $this->transformers = Array(
-                "BlogCountersDataTransformer",
-                "CategoryCountersDataTransformer",
-                "ArticleCountersDataTransformer",
-                "BlogTrackbacksDataTransformer",
-                "AdminUsersDataTransformer",
-                "LinkCategoriesDataTransformer",
-                "CommentsDataTransformer",
-                "AlbumsDataTransformer",
-                "PostSchemaDataTransformer"
+				"AdminUserPermissionsDataTransformer",
+				"UserPermissionsDataTransformer" /*,
+				"ResourcesDataTransformer"*/
             );
             
             $this->currentTransformerId = $this->getTransformerIdFromRequest();



More information about the pLog-svn mailing list