Fixed reaction import, removed disabled reactions
authorMarcel Werk <burntime@woltlab.com>
Mon, 2 Sep 2019 14:38:10 +0000 (16:38 +0200)
committerMarcel Werk <burntime@woltlab.com>
Mon, 2 Sep 2019 14:38:10 +0000 (16:38 +0200)
14 files changed:
wcfsetup/install/files/acp/templates/reactionTypeList.tpl
wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php
wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php
wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php
wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php
wcfsetup/install/files/lib/data/reaction/type/ReactionTypeCache.class.php
wcfsetup/install/files/lib/data/reaction/type/ReactionTypeEditor.class.php
wcfsetup/install/files/lib/system/cache/builder/ReactionTypeCacheBuilder.class.php
wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php
wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php
wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml
wcfsetup/setup/db/install.sql

index 7de3ac3ae5b30bd6b4704e67be8d477c9f84f7a9..0ae6214c168b1db91055953622d0f7a63fbf4bea 100644 (file)
@@ -12,7 +12,6 @@
                
                $(function() {
                        new WCF.Action.Delete('wcf\\data\\reaction\\type\\ReactionTypeAction', '.reactionTypeRow');
-                       new WCF.Action.Toggle('wcf\\data\\reaction\\type\\ReactionTypeAction', '.reactionTypeRow');
                });
        </script>
 {/if}
@@ -47,7 +46,6 @@
                                                
                                                <span class="statusDisplay sortableButtonContainer">
                                                        <span class="icon icon16 fa-arrows sortableNodeHandle"></span>
-                                                       <span class="icon icon16 fa-{if !$reactionType->isDisabled}check-{/if}square-o jsToggleButton jsTooltip pointer" title="{lang}wcf.global.button.{if $reactionType->isDisabled}enable{else}disable{/if}{/lang}" data-object-id="{@$reactionType->reactionTypeID}"></span>
                                                        <a href="{link controller='ReactionTypeEdit' id=$reactionType->reactionTypeID}{/link}"><span title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip icon icon16 fa-pencil"></span></a>
                                                        <span title="{lang}wcf.global.button.delete{/lang}" class="jsDeleteButton pointer jsTooltip icon icon16 fa-times" data-object-id="{@$reactionType->reactionTypeID}" data-confirm-message-html="{lang __encode=true}wcf.acp.reactionType.delete.confirmMessage{/lang}"></span>
                                                        
index 6ef612371782c909e60880bc0eb8fb1a8832ae7d..2cbade39ff18ef9b6cc377ca21d836df7c47070b 100644 (file)
@@ -4,7 +4,6 @@ use wcf\data\reaction\type\ReactionTypeAction;
 use wcf\data\reaction\type\ReactionTypeList;
 use wcf\form\AbstractFormBuilderForm;
 use wcf\system\form\builder\container\FormContainer;
-use wcf\system\form\builder\field\IsDisabledFormField;
 use wcf\system\form\builder\field\ShowOrderFormField;
 use wcf\system\form\builder\field\TitleFormField;
 use wcf\system\form\builder\field\UploadFormField;
@@ -61,9 +60,7 @@ class ReactionTypeAddForm extends AbstractFormBuilderForm {
                                ShowOrderFormField::create()
                                        ->description('wcf.acp.reactionType.showOrder.description')
                                        ->required()
-                                       ->options(new ReactionTypeList()),
-                               IsDisabledFormField::create()
-                                       ->label('wcf.acp.reactionType.isDisabled')
+                                       ->options(new ReactionTypeList())
                        ]);
                
                $iconContainer = FormContainer::create('imageSection')
index f7e65cbe53f94dc1d0f4bd88798c94a000aee498..650e9f91dd9a0f54ddc900d456f59168d87c8b77 100644 (file)
@@ -97,8 +97,6 @@ class ReactionAction extends AbstractDatabaseObjectAction {
                
                $data = [];
                foreach ($likeList as $item) {
-                       if ($item->getReactionType()->isDisabled) continue; 
-                       
                        // we cast the reactionTypeID to a string, so that we can sort the array
                        if (!isset($data[(string)$item->getReactionType()->reactionTypeID])) {
                                $data[(string)$item->getReactionType()->reactionTypeID] = new GroupedUserList($item->getReactionType()->renderIcon() . ' ' . StringUtil::encodeHTML($item->getReactionType()->getTitle()));
@@ -182,7 +180,7 @@ class ReactionAction extends AbstractDatabaseObjectAction {
                
                $this->reactionType = ReactionTypeCache::getInstance()->getReactionTypeByID($this->parameters['reactionTypeID']);
                
-               if (!$this->reactionType->reactionTypeID || $this->reactionType->isDisabled) {
+               if (!$this->reactionType->reactionTypeID) {
                        throw new IllegalLinkException();
                }
                
index 771d841a1f2afd5144ff3ce66165b7d83824762a..fca986dc02c32910b0a92e6e1df9b95d5aaf692a 100644 (file)
@@ -17,7 +17,6 @@ use wcf\system\WCF;
  * @property-read      string          $title
  * @property-read      integer         $showOrder              position of the reaction type in relation to the other reaction types
  * @property-read      string          $iconFile               the file location of the icon
- * @property-read       integer                $isDisabled             is `1` if the reaction type is disabled and thus not shown, otherwise `0`
  */
 class ReactionType extends DatabaseObject implements ITitledObject {
        /**
index 2d3c0563995cffe17ce92c2784375e19879875b1..3bdae6773ca02138ceb0ada36718a056d92435ca 100644 (file)
@@ -2,8 +2,6 @@
 namespace wcf\data\reaction\type;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\ISortableAction;
-use wcf\data\IToggleAction;
-use wcf\data\TDatabaseObjectToggle;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\UserInputException;
 use wcf\system\file\upload\UploadFile;
@@ -22,9 +20,7 @@ use wcf\system\WCF;
  * @method     ReactionTypeEditor[]            getObjects()
  * @method     ReactionTypeEditor              getSingleObject()
  */
-class ReactionTypeAction extends AbstractDatabaseObjectAction implements ISortableAction, IToggleAction {
-       use TDatabaseObjectToggle;
-       
+class ReactionTypeAction extends AbstractDatabaseObjectAction implements ISortableAction {
        /**
         * @inheritDoc
         */
index 54dafd1d2837b910dd9676cb80dfe6dafe12fc94..db08511ab5e89cdf0cee881a6ccc0c5c04cd98ea 100644 (file)
@@ -14,23 +14,16 @@ use wcf\system\SingletonFactory;
  */
 class ReactionTypeCache extends SingletonFactory {
        /**
-        * Contains all reaction types.
+        * Contains reaction types.
         * @var ReactionType[]
         */
        protected $reactionTypes;
        
-       /**
-        * Contains all enabled reaction types.
-        * @var ReactionType[]
-        */
-       protected $enabledReactionTypes;
-       
        /**
         * @inheritDoc
         */
        protected function init() {
                $this->reactionTypes = ReactionTypeCacheBuilder::getInstance()->getData();
-               $this->enabledReactionTypes = ReactionTypeCacheBuilder::getInstance()->getData(['onlyEnabled' => 1]);
        }
        
        /**
@@ -71,21 +64,11 @@ class ReactionTypeCache extends SingletonFactory {
        public function getReactionTypes() {
                return $this->reactionTypes;
        }
-       
-       /**
-        * Return all enabled reaction types.
-        *
-        * @return      ReactionType[]
-        */
-       public function getEnabledReactionTypes() {
-               return $this->enabledReactionTypes;
-       }
-       
+               
        /**
         * Resets the cache for the trophies.
         */
        public function clearCache() {
                ReactionTypeCacheBuilder::getInstance()->reset();
-               ReactionTypeCacheBuilder::getInstance()->reset(['onlyEnabled' => 1]);
        }
 }
index accb9908b5fa1eef66248dba926a78c71296ffa4..6288baeb227ecbd66b26f23a38dc5d89dd48cdfe 100644 (file)
@@ -12,7 +12,9 @@ use wcf\data\IEditableCachedObject;
  * @package    WoltLabSuite\Core\Data\Reaction\Type
  * @since      5.2
  * 
- * @mixin      ReactionType
+ * @method      static         ReactionType    create(array $parameters = [])
+ * @method                     ReactionType    getDecoratedObject()
+ * @mixin                      ReactionType
  */
 class ReactionTypeEditor extends DatabaseObjectEditor implements IEditableCachedObject {
        /**
index a0c3ae229a9fac591337b52cfc55e570f7ed6b54..3e7c2d904f984414f16689ec14a3e73c168de712 100644 (file)
@@ -17,11 +17,6 @@ class ReactionTypeCacheBuilder extends AbstractCacheBuilder {
         */
        public function rebuild(array $parameters) {
                $reactionTypeList = new ReactionTypeList();
-               
-               if (isset($parameters['onlyEnabled']) && $parameters['onlyEnabled']) {
-                       $reactionTypeList->getConditionBuilder()->add('isDisabled = ?', [0]);
-               }
-               
                $reactionTypeList->sqlOrderBy = 'showOrder ASC';
                $reactionTypeList->readObjects();
                
index d40f15b35a049406e479a6146f0786a63159069d..6c7c0fd89844ac400037ac0022cf2c9ab4ad4163 100644 (file)
@@ -1,6 +1,10 @@
 <?php
 namespace wcf\system\importer;
+use wcf\data\language\item\LanguageItemEditor;
 use wcf\data\like\Like;
+use wcf\data\reaction\type\ReactionType;
+use wcf\data\reaction\type\ReactionTypeEditor;
+use wcf\system\language\LanguageFactory;
 use wcf\system\reaction\ReactionHandler;
 use wcf\system\WCF;
 
@@ -24,6 +28,11 @@ class AbstractLikeImporter extends AbstractImporter {
         */
        protected $objectTypeID = 0;
        
+       /**
+        * @var integer|null
+        */
+       protected static $dislikeReactionTypeID;
+       
        /**
         * @inheritDoc
         */
@@ -37,12 +46,15 @@ class AbstractLikeImporter extends AbstractImporter {
                        if ($data['likeValue'] == 1) {
                                $data['reactionTypeID'] = ReactionHandler::getInstance()->getFirstReactionTypeID();
                        }
+                       else {
+                               $data['reactionTypeID'] = self::getDislikeReactionTypeID();
+                       }
                }
                else {
                        $data['reactionTypeID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.reactionType', $data['reactionTypeID']);
                }
                
-               if ($data['reactionTypeID'] === null) {
+               if (empty($data['reactionTypeID'])) {
                        return 0;
                }
                
@@ -62,4 +74,48 @@ class AbstractLikeImporter extends AbstractImporter {
                
                return 0;
        }
+       
+       /**
+        * @return integer
+        */
+       protected static function getDislikeReactionTypeID() {
+               if (self::$dislikeReactionTypeID === null) {
+                       $sql = "SELECT reactionTypeID FROM wcf" . WCF_N . "_reaction_type WHERE iconFile = ?";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(['thumbsDown.svg']);
+                       $reaction = $statement->fetchObject(ReactionType::class);
+                       if ($reaction === null) {
+                               $sql = "SELECT MAX(showOrder) FROM wcf" . WCF_N . "_reaction_type";
+                               $statement = WCF::getDB()->prepareStatement($sql);
+                               $statement->execute();
+                               $showOrder = $statement->fetchColumn();
+                               
+                               $reaction = ReactionTypeEditor::create(['iconFile' => 'thumbsDown.svg', 'showOrder' => $showOrder + 1]);
+                               
+                               $sql = "SELECT  languageCategoryID
+                                       FROM    wcf".WCF_N."_language_category
+                                       WHERE   languageCategory = ?";
+                               $statement = WCF::getDB()->prepareStatement($sql, 1);
+                               $statement->execute(['wcf.reactionType']);
+                               $languageCategoryID = $statement->fetchSingleColumn();
+                               
+                               foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
+                                       LanguageItemEditor::create([
+                                               'languageID' => $language->languageID,
+                                               'languageItem' => 'wcf.reactionType.title' . $reaction->reactionTypeID,
+                                               'languageItemValue' => ($language->getFixedLanguageCode() === 'de' ? 'Gefällt mir nicht' : 'Dislike'),
+                                               'languageCategoryID' => $languageCategoryID,
+                                               'packageID' => 1,
+                                       ]);
+                               }
+                               
+                               $editor = new ReactionTypeEditor($reaction);
+                               $editor->update(['title' => 'wcf.reactionType.title' . $reaction->reactionTypeID]);
+                       }
+                       
+                       self::$dislikeReactionTypeID = $reaction->reactionTypeID;
+               }
+               
+               return self::$dislikeReactionTypeID;
+       }
 }
index 9092605e4a8029be9386ce77a0dc4044c7a8750a..926e6a2cb15edf8471e68e3db70d7736885a26ae 100644 (file)
@@ -69,7 +69,7 @@ class ReactionHandler extends SingletonFactory {
         * @return string
         */
        public function getReactionsJSVariable() {
-               $reactions = ReactionTypeCache::getInstance()->getEnabledReactionTypes();
+               $reactions = ReactionTypeCache::getInstance()->getReactionTypes();
                
                $returnValues = []; 
                
@@ -92,7 +92,7 @@ class ReactionHandler extends SingletonFactory {
         * @return      ReactionType[]
         */
        public function getReactionTypes() {
-               return ReactionTypeCache::getInstance()->getEnabledReactionTypes();
+               return ReactionTypeCache::getInstance()->getReactionTypes();
        }
        
        /**
@@ -715,7 +715,7 @@ class ReactionHandler extends SingletonFactory {
                static $firstReactionType;
                
                if ($firstReactionType === null) {
-                       $reactionTypes = ReactionTypeCache::getInstance()->getEnabledReactionTypes();
+                       $reactionTypes = ReactionTypeCache::getInstance()->getReactionTypes();
                        ReactionType::sort($reactionTypes, 'showOrder');
                        
                        $firstReactionType = reset($reactionTypes);
index 1fc8e37138b24dd01558f8191c2e80e0a224c17e..009fb72a184f55747676c766487f85aa770b695c 100644 (file)
@@ -83,7 +83,7 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker {
                        if (MODULE_LIKE) {
                                $sql = "UPDATE  wcf".WCF_N."_user user_table SET";
                                
-                               $reactionTypeIDs = array_keys(ReactionTypeCache::getInstance()->getEnabledReactionTypes());
+                               $reactionTypeIDs = array_keys(ReactionTypeCache::getInstance()->getReactionTypes());
                                if (!empty($reactionTypeIDs)) {
                                        $sql .= " likesReceived = (
                                                        SELECT  COUNT(*)
index d280066aad2f216a93e1f0c689d89e6f5dd25c8a..f7a0c2b9d0851a0501fe65be82173bafbe18b63e 100644 (file)
@@ -2573,7 +2573,6 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen
        <category name="wcf.acp.reactionType">
                <item name="wcf.acp.reactionType.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} den Reaktions-Typen <span class="confirmationObject">{$reactionType->getTitle()}</span> wirklich löschen?]]></item>
                <item name="wcf.acp.reactionType.type"><![CDATA[Reaktions-Typ]]></item>
-               <item name="wcf.acp.reactionType.isDisabled"><![CDATA[Reaktion deaktivieren]]></item>
                <item name="wcf.acp.reactionType.image"><![CDATA[Reaktions-Datei]]></item>
                <item name="wcf.acp.reactionType.showOrder.description"><![CDATA[Der Reaktions-Typ wird nach dem ausgewählten Reaktions-Typ angezeigt.]]></item>
        </category>
@@ -4321,8 +4320,8 @@ Dateianhänge:
                <item name="wcf.reactions.react"><![CDATA[Reagieren]]></item>
        </category>
        <category name="wcf.reactionType">
-               <item name="wcf.reactionType.title1"><![CDATA[Gefällt mir!]]></item>
-               <item name="wcf.reactionType.title2"><![CDATA[Danke!]]></item>
+               <item name="wcf.reactionType.title1"><![CDATA[Gefällt mir]]></item>
+               <item name="wcf.reactionType.title2"><![CDATA[Danke]]></item>
                <item name="wcf.reactionType.title3"><![CDATA[Haha]]></item>
                <item name="wcf.reactionType.title4"><![CDATA[Verwirrend]]></item>
                <item name="wcf.reactionType.title5"><![CDATA[Traurig]]></item>
index 2dac401c24d312464921ab3d56b2e2233b2dc163..b3c4886b71e6cae3f14414028ccdc127ea1082ed 100644 (file)
@@ -2501,7 +2501,6 @@ If you have <strong>already bought the licenses for the listed apps</strong>, th
        <category name="wcf.acp.reactionType">
                <item name="wcf.acp.reactionType.delete.confirmMessage"><![CDATA[Do you really want to delete the reaction type <span class="confirmationObject">{$reactionType->getTitle()}</span>?]]></item>
                <item name="wcf.acp.reactionType.type"><![CDATA[Reaction Type]]></item>
-               <item name="wcf.acp.reactionType.isDisabled"><![CDATA[Disable Reaction]]></item>
                <item name="wcf.acp.reactionType.image"><![CDATA[Reaction File]]></item>
                <item name="wcf.acp.reactionType.showOrder.description"><![CDATA[The reaction type will be shown after the selected reaction type.]]></item>
        </category>
@@ -4324,7 +4323,7 @@ Attachments:
        </category>
        <category name="wcf.reactionType">
                <item name="wcf.reactionType.title1"><![CDATA[Like]]></item>
-               <item name="wcf.reactionType.title2"><![CDATA[Thanks!]]></item>
+               <item name="wcf.reactionType.title2"><![CDATA[Thanks]]></item>
                <item name="wcf.reactionType.title3"><![CDATA[Haha]]></item>
                <item name="wcf.reactionType.title4"><![CDATA[Confused]]></item>
                <item name="wcf.reactionType.title5"><![CDATA[Sad]]></item>
index 5a1893f4b6a484dd525eeba0297c8013de98d6d9..082f4c6ad8ef6634355efd3bf04fac41abc01d51 100644 (file)
@@ -1201,8 +1201,7 @@ CREATE TABLE wcf1_reaction_type (
        reactionTypeID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, 
        title VARCHAR(255), 
        showOrder INT(10) NOT NULL DEFAULT 0,
-       iconFile MEDIUMTEXT,
-       isDisabled TINYINT(1) NOT NULL DEFAULT 0
+       iconFile MEDIUMTEXT
 );
 
 DROP TABLE IF EXISTS wcf1_registry;