From: Joshua Rüsweg Date: Thu, 2 Aug 2018 13:01:45 +0000 (+0200) Subject: Add update script from WSC 3.1 or lower X-Git-Tag: 5.2.0_Alpha_1~364^2~101^2~28 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1b36ce57f2bee33807ddc9d6d6b78477ff3c5001;p=GitHub%2FWoltLab%2FWCF.git Add update script from WSC 3.1 or lower See #2508 --- 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 d8aec819c8..59e0114afb 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,12 @@ 1, 'like_enable_dislike' => 0 ]); + +try { + \wcf\system\WCF::getDB()->beginTransaction(); + + // add reaction columns + $statement = \wcf\system\WCF::getDB()->prepareStatement(str_replace('wcf1_', 'wcf'.WCF_N.'_', 'INSERT INTO wcf1_reaction_type (title, type, showOrder, iconFile) VALUES (\'wcf.reactionType.title1\', 1, 1, \'like.svg\'), (\'wcf.reactionType.title2\', 1, 2, \'haha.svg\'), (\'wcf.reactionType.title3\', -1, 3, \'sad.svg\'), (\'wcf.reactionType.title4\', 0, 4, \'confused.svg\'), (\'wcf.reactionType.title5\', 1, 5, \'thanks.svg\')')); + $statement->execute(); + + // update current likes + $sql = "UPDATE wcf1_like SET reactionTypeID = ? WHERE likeValue = ?"; + $statement = \wcf\system\WCF::getDB()->prepareStatement(str_replace('wcf1_', 'wcf'.WCF_N.'_', $sql)); + + $statement->execute([ + \wcf\data\like\Like::LIKE, + 1 + ]); + $statement->execute([ + \wcf\data\like\Like::DISLIKE, + 3 + ]); + + // delete outdated likes, which aren't likes nor dislikes (normally none should exist) + $sql = "DELETE wcf1_like WHERE reactionTypeID = 0"; + $statement = \wcf\system\WCF::getDB()->prepareStatement(str_replace('wcf1_', 'wcf'.WCF_N.'_', $sql)); + + // add foreign key + $statement = \wcf\system\WCF::getDB()->prepareStatement(str_replace('wcf1_', 'wcf'.WCF_N.'_', 'ALTER TABLE wcf1_like ADD FOREIGN KEY (reactionTypeID) REFERENCES wcf1_reaction_type (reactionTypeID) ON DELETE CASCADE')); + $statement->execute(); + + \wcf\system\WCF::getDB()->commitTransaction(); +} +catch (Exception $e) { + \wcf\system\WCF::getDB()->rollBackTransaction(); + + throw $e; +}