r4241 upgrade.php: merge "Objectlog" (small l) table data, which 0.19.0 missed
authorDenis Ovsienko <infrastation@yandex.ru>
Sat, 19 Feb 2011 13:55:31 +0000 (13:55 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Sat, 19 Feb 2011 13:55:31 +0000 (13:55 +0000)
ChangeLog
wwwroot/upgrade.php

index d1225adcc21e27e477b8687064e5258941337370..95221597955618d9a00cfea444221c348116a0b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
        bugfix: delete container relationships when an object is deleted (#398)
        bugfix: SQL syntax error in some versions of MySQL+PDO
        bugfix: image caching was broken with some browsers
+       bugfix: finalize ObjectLog merge (#392)
 0.19.0 2011-02-12
        new feature: IPv6 support, except of LivePTR, NAT and SLB functionality (by Alexey Andriyanov)
        new feature: cable ID column for links (#328, by Giovani Zamboni and Jens Weibler)
index d62f26063f091e73c08e8954a7b4f651b9d9229d..03e38df6c0bddca4e3009ee1a5b73e303bcac0c4 100644 (file)
@@ -967,6 +967,25 @@ CREATE TABLE `EntityLink` (
                        $query[] = "ALTER TABLE `Config` CHANGE COLUMN `varvalue` `varvalue` text NOT NULL";
                        $query[] = "ALTER TABLE `UserConfig` CHANGE COLUMN `varvalue` `varvalue` text NOT NULL";
                        $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, is_userdefined, description) VALUES ('FILTER_RACKLIST_BY_TAGS','yes','string','yes','no','yes','Rackspace: show only racks matching the current object\'s tags')";
+                       $result = $dbxlink->query ("SHOW TABLES LIKE 'Objectlog'");
+                       $rows = $result->fetchAll (PDO::FETCH_ASSOC);
+                       unset ($result);
+                       if (count ($rows))
+                       {
+                               # Now the ObjectLog merge... again, because the original table is named
+                               # "Objectlog". The job is to merge contents of Objectlog and ObjectLog
+                               # into the latter.
+                               $query[] = "INSERT INTO ObjectLog (object_id, user, date, content) SELECT object_id, user, date, content FROM Objectlog WHERE object_id IN(SELECT id FROM RackObject)";
+                               $query[] = "DELETE FROM Objectlog WHERE object_id IN(SELECT id FROM RackObject)";
+                               # Don't delete the old table, if the merge wasn't exhaustive.
+                               $result = $dbxlink->query ('SELECT COUNT(*) AS c FROM Objectlog WHERE object_id NOT IN(SELECT id FROM RackObject)');
+                               $row = $result->fetch (PDO::FETCH_ASSOC);
+                               unset ($result);
+                               if ($row['c'] == 0)
+                                       $query[] = 'DROP TABLE Objectlog';
+                               else
+                                       $query[] = 'ALTER TABLE Objectlog RENAME TO Objectlog_old_unmerged';
+                       }
                        $query[] = "UPDATE Config SET varvalue = '0.19.1' WHERE varname = 'DB_VERSION'";
                        break;
                default: