From be764b44563f43119c737c8e8fb889e0b61f811d Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Wed, 1 Sep 2021 15:14:00 +0200 Subject: [PATCH] Add update script for box conditions --- ...pdate_com.woltlab.wcf_5.5_boxCondtions.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_boxCondtions.php diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_boxCondtions.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_boxCondtions.php new file mode 100644 index 0000000000..b1fcef9874 --- /dev/null +++ b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.5_boxCondtions.php @@ -0,0 +1,52 @@ + + * @package WoltLabSuite\Core + */ + +use wcf\data\box\Box; +use wcf\data\box\BoxList; +use wcf\data\condition\Condition; +use wcf\data\object\type\ObjectTypeCache; +use wcf\system\condition\ConditionHandler; +use wcf\system\condition\page\MultiPageCondition; + +$boxList = new BoxList(); +$boxList->readObjects(); + +foreach ($boxList as $box) { + $conditions = ConditionHandler::getInstance()->getConditions( + Box::VISIBILITY_CONDITIONS_OBJECT_TYPE_NAME, + $box->boxID + ); + + if (!empty($conditions)) { + // The box already has conditions (maybe from a previous upgrade attempt). + // Skip this box to ensure, that the condition will not attached twice. + continue; + } + + $pageCondition = ObjectTypeCache::getInstance()->getObjectTypeByName( + Box::VISIBILITY_CONDITIONS_OBJECT_TYPE_NAME, + 'com.woltlab.wcf.page' + ); + + \assert($pageCondition->getProcessor() instanceof MultiPageCondition); + + $pageCondition->getProcessor()->setData(new Condition(null, [ + 'conditionData' => \serialize([ + 'pageIDs' => $box->getPageIDs(), + 'pageIDs_reverseLogic' => $box->visibleEverywhere, + ]), + ])); + + ConditionHandler::getInstance()->createConditions( + $box->boxID, + [$pageCondition] + ); +} -- 2.20.1