From: Marcel Werk Date: Wed, 28 Dec 2016 15:18:56 +0000 (+0100) Subject: Fixed duplicates in page_content / box_content X-Git-Tag: 3.0.0_RC_3~21 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b68302ea55122d456e2eb4bc013e055855514da9;p=GitHub%2FWoltLab%2FWCF.git Fixed duplicates in page_content / box_content --- diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_3.0.0_rc_3.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_3.0.0_rc_3.php index 7385b3aef4..673949d5f4 100644 --- a/wcfsetup/install/files/acp/update_com.woltlab.wcf_3.0.0_rc_3.php +++ b/wcfsetup/install/files/acp/update_com.woltlab.wcf_3.0.0_rc_3.php @@ -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 diff --git a/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php index b59b0c6ce3..e9163e65f2 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/BoxPackageInstallationPlugin.class.php @@ -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'], diff --git a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php index db2c18ab55..8db6e7a98d 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php @@ -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'],