Fixed duplicates in page_content / box_content
authorMarcel Werk <burntime@woltlab.com>
Wed, 28 Dec 2016 15:18:56 +0000 (16:18 +0100)
committerMarcel Werk <burntime@woltlab.com>
Wed, 28 Dec 2016 15:19:01 +0000 (16:19 +0100)
wcfsetup/install/files/acp/update_com.woltlab.wcf_3.0.0_rc_3.php
wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php

index 7385b3aef4640f40d01767f07ca3249af49255f7..673949d5f47b54516419ce71b55c4b0e0acded91 100644 (file)
@@ -26,3 +26,42 @@ if (!$hasLandingPageID) {
        $statement = WCF::getDB()->prepareStatement("UPDATE wcf".WCF_N."_application SET landingPageID = (SELECT pageID FROM wcf".WCF_N."_page WHERE isLandingPage = 1 LIMIT 1) WHERE packageID = 1;");
        $statement->execute();
 }
+
+
+// remove duplicates in page_content
+$sql = "DELETE FROM     wcf".WCF_N."_page_content
+       WHERE           pageID = ?
+                       AND languageID IS NULL
+       ORDER BY        pageContentID DESC
+       LIMIT           ?";
+$deleteStatement = WCF::getDB()->prepareStatement($sql);
+
+$sql = "SELECT          COUNT(*) AS count, pageID
+       FROM            wcf".WCF_N."_page_content
+       WHERE           languageID IS NULL
+       GROUP BY        pageID
+       HAVING          count > 1";
+$statement = WCF::getDB()->prepareStatement($sql);
+$statement->execute();
+while ($row = $statement->fetchArray()) {
+       $deleteStatement->execute([$row['pageID'], $row['count'] - 1]);
+}
+
+// remove duplicates in box_content
+$sql = "DELETE FROM     wcf".WCF_N."_box_content
+       WHERE           boxID = ?
+                       AND languageID IS NULL
+       ORDER BY        boxContentID DESC
+       LIMIT           ?";
+$deleteStatement = WCF::getDB()->prepareStatement($sql);
+
+$sql = "SELECT          COUNT(*) AS count, boxID
+       FROM            wcf".WCF_N."_box_content
+       WHERE           languageID IS NULL
+       GROUP BY        boxID
+       HAVING          count > 1";
+$statement = WCF::getDB()->prepareStatement($sql);
+$statement->execute();
+while ($row = $statement->fetchArray()) {
+       $deleteStatement->execute([$row['boxID'], $row['count'] - 1]);
+}
\ No newline at end of file
index b59b0c6ce34211489d9a45b9edd5f5e4dc33fad1..e9163e65f217db18f7f99c299393b9d2828fe5f9 100644 (file)
@@ -294,10 +294,16 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
         */
        protected function postImport() {
                if (!empty($this->content)) {
+                       $sql = "SELECT  COUNT(*) AS count
+                               FROM    wcf".WCF_N."_box_content
+                               WHERE   boxID = ?
+                                       AND languageID IS NULL";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       
                        $sql = "INSERT IGNORE INTO      wcf".WCF_N."_box_content
                                                        (boxID, languageID, title, content)
                                VALUES                  (?, ?, ?, ?)";
-                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $insertStatement = WCF::getDB()->prepareStatement($sql);
                        
                        WCF::getDB()->beginTransaction();
                        foreach ($this->content as $boxID => $contentData) {
@@ -310,7 +316,12 @@ class BoxPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                                                $languageID = $language->languageID;
                                        }
                                        
-                                       $statement->execute([
+                                       if ($languageID === null) {
+                                               $statement->execute([$boxID]);
+                                               if ($statement->fetchColumn()) continue;
+                                       }
+                                       
+                                       $insertStatement->execute([
                                                $boxID,
                                                $languageID,
                                                $content['title'],
index db2c18ab55b5c96bafc1a368721eebc1ea3469d8..8db6e7a98dbb8e16c561b2c3448828325b494cc8 100644 (file)
@@ -280,10 +280,16 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
         */
        protected function postImport() {
                if (!empty($this->content)) {
+                       $sql = "SELECT  COUNT(*) AS count
+                               FROM    wcf".WCF_N."_page_content
+                               WHERE   pageID = ?
+                                       AND languageID IS NULL";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       
                        $sql = "INSERT IGNORE INTO      wcf".WCF_N."_page_content
                                                        (pageID, languageID, title, content, metaDescription, metaKeywords, customURL)
                                VALUES                  (?, ?, ?, ?, ?, ?, ?)";
-                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $insertStatement = WCF::getDB()->prepareStatement($sql);
                        
                        WCF::getDB()->beginTransaction();
                        foreach ($this->content as $pageID => $contentData) {
@@ -296,7 +302,12 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                                                $languageID = $language->languageID;
                                        }
                                        
-                                       $statement->execute([
+                                       if ($languageID === null) {
+                                               $statement->execute([$pageID]);
+                                               if ($statement->fetchColumn()) continue;
+                                       }
+                                       
+                                       $insertStatement->execute([
                                                $pageID,
                                                $languageID,
                                                $content['title'],