From 3b27fefe6f939f1ca176891e28f93000b6bf6344 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 17 Jul 2019 16:52:44 +0200 Subject: [PATCH] Convert dislikes into reactions during the upgrade --- ...ate-com.woltlab.wcf_3.2_reactionUpdate.php | 77 +++++++++++++++---- .../files/images/reaction/thumbsDown.svg | 1 + .../{reactionIcon.svg => thumbsUp.svg} | 0 wcfsetup/setup/db/install.sql | 10 +-- 4 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 wcfsetup/install/files/images/reaction/thumbsDown.svg rename wcfsetup/install/files/images/reaction/{reactionIcon.svg => thumbsUp.svg} (100%) diff --git a/wcfsetup/install/files/acp/update-com.woltlab.wcf_3.2_reactionUpdate.php b/wcfsetup/install/files/acp/update-com.woltlab.wcf_3.2_reactionUpdate.php index 1b535daace..2a335baa80 100644 --- a/wcfsetup/install/files/acp/update-com.woltlab.wcf_3.2_reactionUpdate.php +++ b/wcfsetup/install/files/acp/update-com.woltlab.wcf_3.2_reactionUpdate.php @@ -1,6 +1,8 @@ beginTransaction(); - $reactionTypes = <<prepareStatement($sql, 1); + $statement->execute(['wcf.reactionType']); + $languageCategoryID = $statement->fetchSingleColumn(); + + // Create a custom phrase for this reaction, it needs to be "manually" added + // because it would otherwise conflict with the next reaction created by the + // user, *if* there are no dislikes. + foreach (LanguageFactory::getInstance()->getLanguages() as $language) { + LanguageItemEditor::create([ + 'languageID' => $language->languageID, + 'languageItem' => 'wcf.reactionType.title6', + 'languageItemValue' => ($language->getFixedLanguageCode() === 'de' ? 'Gefällt mir nicht' : 'Dislike'), + 'languageCategoryID' => $languageCategoryID, + 'packageID' => 1, + ]); + } + } - // add reaction columns - $statement = WCF::getDB()->prepareStatement('INSERT INTO wcf'.WCF_N.'_reaction_type (title, showOrder, iconFile) VALUES '. $reactionTypes); - $statement->execute(); + $sql = "INSERT INTO wcf".WCF_N."_reaction_type + (reactionTypeID, title, showOrder, iconFile) + VALUES (?, ?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + for ($i = 0, $length = count($reactions); $i < $length; $i++) { + $reactionTypeID = $i + 1; + + $statement->execute([ + $reactionTypeID, + "wcf.reactionType.title{$reactionTypeID}", + $reactionTypeID, + "{$reactions[$i]}.svg", + ]); + } - // update current likes - $sql = "UPDATE wcf".WCF_N."_like SET reactionTypeID = ? WHERE likeValue = ?"; + // Update the existing (dis)likes. + $likeValues = [Like::LIKE => 1]; + if (LIKE_ENABLE_DISLIKE) $likeValues[Like::DISLIKE] = 6; + + $sql = "UPDATE wcf".WCF_N."_like + SET reactionTypeID = ? + WHERE likeValue = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute([ - Like::LIKE, - 1 - ]); + foreach ($likeValues as $likeValue => $reactionTypeID) { + $statement->execute([ + $reactionTypeID, + $likeValue, + ]); + } // Delete outdated or unsupported likes. WCF::getDB()->prepareStatement("DELETE FROM wcf".WCF_N."_like WHERE reactionTypeID = 0")->execute(); - // add foreign key + // Adjust the like objects by moving all dislikes into regular likes/cumulativeLikes. + $sql = "UPDATE wcf".WCF_N."_like_object + SET likes = likes + dislikes, + cumulativeLikes = likes, + dislikes = 0"; + WCF::getDB()->prepareStatement($sql)->execute(); + $statement = WCF::getDB()->prepareStatement('ALTER TABLE wcf'.WCF_N.'_like ADD FOREIGN KEY (reactionTypeID) REFERENCES wcf1_reaction_type (reactionTypeID) ON DELETE CASCADE'); $statement->execute(); diff --git a/wcfsetup/install/files/images/reaction/thumbsDown.svg b/wcfsetup/install/files/images/reaction/thumbsDown.svg new file mode 100644 index 0000000000..acefdc1c40 --- /dev/null +++ b/wcfsetup/install/files/images/reaction/thumbsDown.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wcfsetup/install/files/images/reaction/reactionIcon.svg b/wcfsetup/install/files/images/reaction/thumbsUp.svg similarity index 100% rename from wcfsetup/install/files/images/reaction/reactionIcon.svg rename to wcfsetup/install/files/images/reaction/thumbsUp.svg diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 64af1aca36..990d6b4e67 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -2422,8 +2422,8 @@ INSERT INTO wcf1_contact_option (optionID, optionTitle, optionDescription, optio INSERT INTO wcf1_contact_recipient (recipientID, name, email, isAdministrator, originIsSystem) VALUES (1, 'wcf.contact.recipient.name1', '', 1, 1); -- default reaction type -INSERT INTO wcf1_reaction_type (title, showOrder, iconFile) VALUES ('wcf.reactionType.title1', 1, 'like.svg'); -INSERT INTO wcf1_reaction_type (title, showOrder, iconFile) VALUES ('wcf.reactionType.title2', 2, 'haha.svg'); -INSERT INTO wcf1_reaction_type (title, showOrder, iconFile) VALUES ('wcf.reactionType.title3', 3, 'sad.svg'); -INSERT INTO wcf1_reaction_type (title, showOrder, iconFile) VALUES ('wcf.reactionType.title4', 4, 'confused.svg'); -INSERT INTO wcf1_reaction_type (title, showOrder, iconFile) VALUES ('wcf.reactionType.title5', 5, 'thanks.svg'); +INSERT INTO wcf1_reaction_type (reactionTypeID, title, showOrder, iconFile) VALUES (1, 'wcf.reactionType.title1', 1, 'like.svg'); +INSERT INTO wcf1_reaction_type (reactionTypeID, title, showOrder, iconFile) VALUES (2, 'wcf.reactionType.title5', 2, 'thanks.svg'); +INSERT INTO wcf1_reaction_type (reactionTypeID, title, showOrder, iconFile) VALUES (3, 'wcf.reactionType.title2', 3, 'haha.svg'); +INSERT INTO wcf1_reaction_type (reactionTypeID, title, showOrder, iconFile) VALUES (4, 'wcf.reactionType.title4', 4, 'confused.svg'); +INSERT INTO wcf1_reaction_type (reactionTypeID, title, showOrder, iconFile) VALUES (5, 'wcf.reactionType.title3', 5, 'sad.svg'); -- 2.20.1