[pLog-svn] r2771 - plog/trunk

oscar at devel.lifetype.net oscar at devel.lifetype.net
Wed Jan 11 23:15:35 GMT 2006


Author: oscar
Date: 2006-01-11 23:15:35 +0000 (Wed, 11 Jan 2006)
New Revision: 2771

Modified:
   plog/trunk/wizard.php
Log:
the upgrade path of the wizard is now complete. The code is pretty painful and repetitive, but it works. Now if somebody's interested in testing this, please go ahead. I might switch my blog to 1.1 soon so that we can start getting some real life usage data concerning performance, memory usage, etc. Volunteers are welcome :)


Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php	2006-01-11 16:16:02 UTC (rev 2770)
+++ plog/trunk/wizard.php	2006-01-11 23:15:35 UTC (rev 2771)
@@ -1640,6 +1640,9 @@
             print($query3);
             // list of blog ids
             $query4 = "SELECT id FROM ".$this->dbPrefix."blogs";
+            // 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 GROUP BY blog_id";                       
                       
             // execute the 1st query
             $res1 = $this->db->Execute( $query1 );
@@ -1673,6 +1676,19 @@
             while( $row = $res3->FetchRow()) {
                 $numTrackbacks[$row["blog_id"]] = $row["total"];
             }
+            
+            // update and create dates
+            $res5 = $this->db->Execute( $query5 );
+            if( !$res5 ) {
+                $this->message .= "Error performing changes to the blogs table (5)";
+                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"];
+            }
                         
             // load each one of the categories and update them
             $res4 = $this->db->Execute( $query4 );
@@ -1689,16 +1705,29 @@
                 if( $totalComments == '' ) $totalComments = 0;
                 $totalTrackbacks = $numTrackbacks[$blogId];
                 if( $totalTrackbacks == '' ) $totalTrackbacks = 0;                
-                
+                $createDate = $createDates[$blogId];
+                if( $createDate == "" ) {
+                    $t = new Timestamp();
+                    $createDate = $t->getTimestamp();
+                }
+                $lastUpdateDate = $lastUpdateDates[$blogId];
+                if( $lastUpdateDate == "" ) {
+                    $t = new Timestamp();
+                    $lastUpdateDate = $t->getTimestamp();
+                }
+                                
                 // build the update query
-                $query = "UPDATE ".$this->dbPrefix."blogs SET num_articles = {$totalArticles},
+                print("blog update query=$query<br/>");
+                $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->db->Execute( $query );
-                if( !$result == 0 ) {
+                if( !$result ) {
                     $this->message .= "Error updating blog with id {$catId}<br/>";
                 }
                 else
@@ -1717,6 +1746,41 @@
              * move all the trackbacks to the articles_comments table and set the 'type' field 
              * to '3'
              */
+             
+            $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->db->Execute( $query );
+            if( !$result ) {
+                $this->message .= "Error updating trackbacks.<br/>";
+                return true;
+            }
+            
+            // process all trackbacks and insert them again to the comments table
+            include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+            $totalAdded++;
+            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, 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','".
+                                     Textfilter::urlize( $row["excerpt"] )."','".
+                                     Textfilter::urlize( $row["title"] )."','2')";                            
+                
+                $insertRes = $this->db->Execute( $insert );
+                if( $insertRes )
+                    $totalAdded++;
+                else
+                    $this->message .= "Error adding trackback with id ".$row["id"]."<br/>";
+            }
+            
+            $this->message .= "{$totalAdded} trackbacks modified.<br/>";            
         
             return true;
         }
@@ -1866,7 +1930,7 @@
                     $numUpdated++;
             }
              
-            $this->message .= "{$numUpdated} gallery albums updated successfully";
+            $this->message .= "{$numUpdated} gallery albums updated successfully<br/>";
             
             return true;
         }



More information about the pLog-svn mailing list