Convert dislikes into reactions during the upgrade
authorAlexander Ebert <ebert@woltlab.com>
Wed, 17 Jul 2019 14:52:44 +0000 (16:52 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 17 Jul 2019 14:52:44 +0000 (16:52 +0200)
wcfsetup/install/files/acp/update-com.woltlab.wcf_3.2_reactionUpdate.php
wcfsetup/install/files/images/reaction/reactionIcon.svg [deleted file]
wcfsetup/install/files/images/reaction/thumbsDown.svg [new file with mode: 0644]
wcfsetup/install/files/images/reaction/thumbsUp.svg [new file with mode: 0644]
wcfsetup/setup/db/install.sql

index 1b535daace22b196a7874de4abdf8077eb48d86f..2a335baa8068d33ab65e9724647beb517bfdaaa9 100644 (file)
@@ -1,6 +1,8 @@
 <?php
+use wcf\data\language\item\LanguageItemEditor;
 use wcf\data\like\Like;
 use wcf\data\option\OptionEditor;
+use wcf\system\language\LanguageFactory;
 use wcf\system\WCF;
 
 // !!!!!!!!!
@@ -23,30 +25,71 @@ OptionEditor::import([
 try {
        WCF::getDB()->beginTransaction();
        
-       $reactionTypes = <<<DATA
-('wcf.reactionType.title1', 1, 'like.svg'), 
-('wcf.reactionType.title2', 2, 'haha.svg'), 
-('wcf.reactionType.title3', 3, 'sad.svg'),
-('wcf.reactionType.title4', 4, 'confused.svg'),
-('wcf.reactionType.title5', 5, 'thanks.svg'),
-DATA;
+       $reactions = ['like', 'thanks', 'haha', 'confused', 'sad'];
+       if (LIKE_ENABLE_DISLIKE) {
+               $reactions[] = 'thumbsDown';
+               
+               $sql = "SELECT  languageCategoryID
+                       FROM    wcf".WCF_N."_language_category
+                       WHERE   languageCategory = ?";
+               $statement = WCF::getDB()->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/reactionIcon.svg b/wcfsetup/install/files/images/reaction/reactionIcon.svg
deleted file mode 100644 (file)
index 3dc973c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64"><path fill="#ffdd67" d="m31.765 27.09c0 0-4.354.869-.753-6.613 2.608-5.418 2.348-11.709 0-15.05-3.757-5.344-11.07-3.592-10.31-.523 2.607 10.546-3.284 13.688-6.328 20.345-3.086 6.746-2.748 16.321-1.329 24.847.887 5.328 3.138 11.899 11.449 11.899h11.486l-4.215-34.906"/><path fill="#eba352" d="m25.75 60.52c-8.31 0-10.131-6.569-11.02-11.897-1.419-8.524-1.646-15.328 1.082-22.22 2.969-7.497 6.097-7.717 6.097-22.542 0-.742.392-1.231.793-1.558-1.407.468-2.186 1.289-2.186 2.492 0 11.09-3.101 13.805-6.145 20.461-3.085 6.746-2.747 16.321-1.328 24.847.887 5.328 3.138 11.899 11.449 11.899h11.486v-1.483h-10.23"/><path fill="#ffdd67" d="m45.998 35.816h-14.233c-4.965 0-4.965-8.722 0-8.722h14.233c4.965 0 4.965 8.722 0 8.722"/><path fill="#eba352" d="m47.1 34.37h-14.232c-3.351 0-4.432-3.965-3.26-6.548-2.654 2.08-1.944 7.998 2.148 7.998h14.232c1.614 0 2.694-.927 3.259-2.173-.565.446-1.275.723-2.147.723"/><path fill="#ffdd67" d="m47.532 44.573h-17.08c-5.957 0-5.957-8.722 0-8.722h17.08c5.956.001 5.956 8.722-.001 8.722"/><path fill="#eba352" d="m48.857 43.13h-17.08c-4.02 0-5.317-3.967-3.91-6.548-3.187 2.08-2.334 7.996 2.576 7.996h17.08c1.938 0 3.234-.927 3.911-2.171-.678.444-1.532.723-2.578.723"/><path fill="#ffdd67" d="m45.931 53.3h-14.437c-5.04 0-5.04-8.723 0-8.723h14.437c5.04 0 5.04 8.723 0 8.723"/><path fill="#eba352" d="m47.05 51.848h-14.436c-3.398 0-4.492-3.968-3.307-6.551-2.692 2.082-1.972 7.999 2.18 7.999h14.438c1.636 0 2.731-.929 3.306-2.174-.575.445-1.295.726-2.181.726"/><path fill="#ffdd67" d="m44.38 62h-9.329c-5.385 0-5.385-8.721 0-8.721h9.329c5.388 0 5.388 8.721 0 8.721"/><path fill="#eba352" d="m45.58 60.55h-9.333c-3.631 0-4.804-3.968-3.532-6.551-2.881 2.082-2.109 7.998 2.33 7.998h9.329c1.75 0 2.923-.928 3.535-2.172-.613.443-1.381.725-2.329.725"/></svg>
\ No newline at end of file
diff --git a/wcfsetup/install/files/images/reaction/thumbsDown.svg b/wcfsetup/install/files/images/reaction/thumbsDown.svg
new file mode 100644 (file)
index 0000000..acefdc1
--- /dev/null
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64"><path d="m31.8 36.9c0 0-4.4-.9-.8 6.6 2.6 5.4 2.3 11.7 0 15-3.8 5.3-11.1 3.6-10.3.5 2.6-10.5-3.3-13.7-6.3-20.3-3.1-6.7-2.8-16.3-1.4-24.8.9-5.3 3.2-11.9 11.5-11.9h11.5l-4.2 34.9" fill="#ffdd67"/><path d="m25.8 3.5c-8.3 0-10.1 6.6-11 11.9-1.4 8.5-1.6 15.3 1.1 22.2 3 7.5 6.1 7.7 6.1 22.5 0 .7.4 1.2.8 1.6-1.4-.5-2.2-1.3-2.2-2.5 0-11.1-3.1-13.8-6.1-20.5-3.2-6.7-2.9-16.3-1.5-24.8.9-5.3 3.2-11.9 11.5-11.9h11.5v1.5h-10.2" fill="#eba352"/><path d="m46 28.2h-14.2c-5 0-5 8.7 0 8.7h14.2c5 0 5-8.7 0-8.7" fill="#ffdd67"/><path d="m47.1 29.6h-14.2c-3.4 0-4.4 4-3.3 6.5-2.7-2.1-1.9-8 2.1-8h14.3c1.6 0 2.7.9 3.3 2.2-.6-.4-1.3-.7-2.2-.7" fill="#eba352"/><path d="m47.5 19.4h-17c-6 0-6 8.7 0 8.7h17.1c5.9 0 5.9-8.7-.1-8.7" fill="#ffdd67"/><path d="m48.9 20.9h-17.1c-4 0-5.3 4-3.9 6.5-3.2-2.1-2.3-8 2.6-8h17.1c1.9 0 3.2.9 3.9 2.2-.7-.4-1.6-.7-2.6-.7" fill="#eba352"/><path d="m45.9 10.7h-14.4c-5 0-5 8.7 0 8.7h14.4c5.1 0 5.1-8.7 0-8.7" fill="#ffdd67"/><path d="m47.1 12.2h-14.5c-3.4 0-4.5 4-3.3 6.6-2.7-2.1-2-8 2.2-8h14.4c1.6 0 2.7.9 3.3 2.2-.5-.6-1.3-.8-2.1-.8" fill="#eba352"/><path d="m44.4 2h-9.3c-5.4 0-5.4 8.7 0 8.7h9.3c5.4 0 5.4-8.7 0-8.7" fill="#ffdd67"/><path d="m45.6 3.4h-9.3c-3.6 0-4.8 4-3.5 6.6-2.9-2.1-2.1-8 2.3-8h9.3c1.8 0 2.9.9 3.5 2.2-.6-.5-1.4-.8-2.3-.8" fill="#eba352"/></svg>
\ No newline at end of file
diff --git a/wcfsetup/install/files/images/reaction/thumbsUp.svg b/wcfsetup/install/files/images/reaction/thumbsUp.svg
new file mode 100644 (file)
index 0000000..3dc973c
--- /dev/null
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64"><path fill="#ffdd67" d="m31.765 27.09c0 0-4.354.869-.753-6.613 2.608-5.418 2.348-11.709 0-15.05-3.757-5.344-11.07-3.592-10.31-.523 2.607 10.546-3.284 13.688-6.328 20.345-3.086 6.746-2.748 16.321-1.329 24.847.887 5.328 3.138 11.899 11.449 11.899h11.486l-4.215-34.906"/><path fill="#eba352" d="m25.75 60.52c-8.31 0-10.131-6.569-11.02-11.897-1.419-8.524-1.646-15.328 1.082-22.22 2.969-7.497 6.097-7.717 6.097-22.542 0-.742.392-1.231.793-1.558-1.407.468-2.186 1.289-2.186 2.492 0 11.09-3.101 13.805-6.145 20.461-3.085 6.746-2.747 16.321-1.328 24.847.887 5.328 3.138 11.899 11.449 11.899h11.486v-1.483h-10.23"/><path fill="#ffdd67" d="m45.998 35.816h-14.233c-4.965 0-4.965-8.722 0-8.722h14.233c4.965 0 4.965 8.722 0 8.722"/><path fill="#eba352" d="m47.1 34.37h-14.232c-3.351 0-4.432-3.965-3.26-6.548-2.654 2.08-1.944 7.998 2.148 7.998h14.232c1.614 0 2.694-.927 3.259-2.173-.565.446-1.275.723-2.147.723"/><path fill="#ffdd67" d="m47.532 44.573h-17.08c-5.957 0-5.957-8.722 0-8.722h17.08c5.956.001 5.956 8.722-.001 8.722"/><path fill="#eba352" d="m48.857 43.13h-17.08c-4.02 0-5.317-3.967-3.91-6.548-3.187 2.08-2.334 7.996 2.576 7.996h17.08c1.938 0 3.234-.927 3.911-2.171-.678.444-1.532.723-2.578.723"/><path fill="#ffdd67" d="m45.931 53.3h-14.437c-5.04 0-5.04-8.723 0-8.723h14.437c5.04 0 5.04 8.723 0 8.723"/><path fill="#eba352" d="m47.05 51.848h-14.436c-3.398 0-4.492-3.968-3.307-6.551-2.692 2.082-1.972 7.999 2.18 7.999h14.438c1.636 0 2.731-.929 3.306-2.174-.575.445-1.295.726-2.181.726"/><path fill="#ffdd67" d="m44.38 62h-9.329c-5.385 0-5.385-8.721 0-8.721h9.329c5.388 0 5.388 8.721 0 8.721"/><path fill="#eba352" d="m45.58 60.55h-9.333c-3.631 0-4.804-3.968-3.532-6.551-2.881 2.082-2.109 7.998 2.33 7.998h9.329c1.75 0 2.923-.928 3.535-2.172-.613.443-1.381.725-2.329.725"/></svg>
\ No newline at end of file
index 64af1aca36b7f7ba0ca0adc8513232db7db72cb7..990d6b4e6735e6c194419adb4f16085d7c593ca1 100644 (file)
@@ -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');