From 1626fe3e1c1fc7a8fcbd69e427a4e28648fc6e46 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Mon, 2 Sep 2019 16:38:10 +0200 Subject: [PATCH] Fixed reaction import, removed disabled reactions --- .../files/acp/templates/reactionTypeList.tpl | 2 - .../acp/form/ReactionTypeAddForm.class.php | 5 +- .../data/reaction/ReactionAction.class.php | 4 +- .../data/reaction/type/ReactionType.class.php | 1 - .../type/ReactionTypeAction.class.php | 6 +- .../reaction/type/ReactionTypeCache.class.php | 21 +------ .../type/ReactionTypeEditor.class.php | 4 +- .../ReactionTypeCacheBuilder.class.php | 5 -- .../importer/AbstractLikeImporter.class.php | 58 ++++++++++++++++++- .../system/reaction/ReactionHandler.class.php | 6 +- .../worker/UserRebuildDataWorker.class.php | 2 +- wcfsetup/install/lang/de.xml | 5 +- wcfsetup/install/lang/en.xml | 3 +- wcfsetup/setup/db/install.sql | 3 +- 14 files changed, 73 insertions(+), 52 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/reactionTypeList.tpl b/wcfsetup/install/files/acp/templates/reactionTypeList.tpl index 7de3ac3ae5..0ae6214c16 100644 --- a/wcfsetup/install/files/acp/templates/reactionTypeList.tpl +++ b/wcfsetup/install/files/acp/templates/reactionTypeList.tpl @@ -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'); }); {/if} @@ -47,7 +46,6 @@ - diff --git a/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php b/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php index 6ef6123717..2cbade39ff 100644 --- a/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/ReactionTypeAddForm.class.php @@ -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') diff --git a/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php b/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php index f7e65cbe53..650e9f91dd 100644 --- a/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php +++ b/wcfsetup/install/files/lib/data/reaction/ReactionAction.class.php @@ -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(); } diff --git a/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php b/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php index 771d841a1f..fca986dc02 100644 --- a/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php +++ b/wcfsetup/install/files/lib/data/reaction/type/ReactionType.class.php @@ -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 { /** diff --git a/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php b/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php index 2d3c056399..3bdae6773c 100644 --- a/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php +++ b/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeAction.class.php @@ -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 */ diff --git a/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeCache.class.php b/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeCache.class.php index 54dafd1d28..db08511ab5 100644 --- a/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeCache.class.php +++ b/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeCache.class.php @@ -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]); } } diff --git a/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeEditor.class.php b/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeEditor.class.php index accb9908b5..6288baeb22 100644 --- a/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeEditor.class.php +++ b/wcfsetup/install/files/lib/data/reaction/type/ReactionTypeEditor.class.php @@ -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 { /** diff --git a/wcfsetup/install/files/lib/system/cache/builder/ReactionTypeCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ReactionTypeCacheBuilder.class.php index a0c3ae229a..3e7c2d904f 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/ReactionTypeCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/ReactionTypeCacheBuilder.class.php @@ -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(); diff --git a/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php b/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php index d40f15b35a..6c7c0fd898 100644 --- a/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/AbstractLikeImporter.class.php @@ -1,6 +1,10 @@ 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; + } } diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index 9092605e4a..926e6a2cb1 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -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); diff --git a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php index 1fc8e37138..009fb72a18 100644 --- a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php @@ -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(*) diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index d280066aad..f7a0c2b9d0 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2573,7 +2573,6 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen {$reactionType->getTitle()} wirklich löschen?]]> - @@ -4321,8 +4320,8 @@ Dateianhänge: - - + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 2dac401c24..b3c4886b71 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2501,7 +2501,6 @@ If you have already bought the licenses for the listed apps, th {$reactionType->getTitle()}?]]> - @@ -4324,7 +4323,7 @@ Attachments: - + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 5a1893f4b6..082f4c6ad8 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -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; -- 2.20.1