From: joshuaruesweg Date: Sat, 11 Jul 2020 09:29:37 +0000 (+0200) Subject: Save changes to the sitemap objects in the registry X-Git-Tag: 5.3.0_Alpha_1~135^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1207c9909b0e969974526b8839fbb9c8d2e168d0;p=GitHub%2FWoltLab%2FWCF.git Save changes to the sitemap objects in the registry Since changes to the sitemap are saved directly in the object type, there is the problem that when you update the WCF, these changes are potentially overwritten again. This commit fixes this problem by saving changes in the registry. Fixes #3376 --- diff --git a/wcfsetup/install/files/lib/acp/form/SitemapEditForm.class.php b/wcfsetup/install/files/lib/acp/form/SitemapEditForm.class.php index 37b1af7933..e51e7d7031 100755 --- a/wcfsetup/install/files/lib/acp/form/SitemapEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/SitemapEditForm.class.php @@ -1,12 +1,13 @@ objectType->priority !== null) $this->priority = $this->objectType->priority; - if ($this->objectType->changeFreq !== null) $this->changeFreq = $this->objectType->changeFreq; - if ($this->objectType->rebuildTime !== null) $this->rebuildTime = $this->objectType->rebuildTime; - if ($this->objectType->isDisabled !== null) $this->isDisabled = $this->objectType->isDisabled; + $sitemapData = RegistryHandler::getInstance()->get('com.woltlab.wcf', SitemapRebuildWorker::REGISTRY_PREFIX . $this->objectTypeName); + $sitemapData = @unserialize($sitemapData); + + if (is_array($sitemapData)) { + $this->priority = $sitemapData['priority']; + $this->changeFreq = $sitemapData['changeFreq']; + $this->rebuildTime = $sitemapData['rebuildTime']; + $this->isDisabled = $sitemapData['isDisabled']; + } + else { + if ($this->objectType->priority !== null) $this->priority = $this->objectType->priority; + if ($this->objectType->changeFreq !== null) $this->changeFreq = $this->objectType->changeFreq; + if ($this->objectType->rebuildTime !== null) $this->rebuildTime = $this->objectType->rebuildTime; + if ($this->objectType->isDisabled !== null) $this->isDisabled = $this->objectType->isDisabled; + } } } @@ -145,19 +157,12 @@ class SitemapEditForm extends AbstractForm { public function save() { parent::save(); - $data = array_merge($this->objectType->additionalData, [ + RegistryHandler::getInstance()->set('com.woltlab.wcf', SitemapRebuildWorker::REGISTRY_PREFIX . $this->objectTypeName, serialize([ 'priority' => $this->priority, 'changeFreq' => $this->changeFreq, 'rebuildTime' => $this->rebuildTime, - 'isDisabled' => $this->isDisabled - ]); - - $this->objectAction = new ObjectTypeAction([$this->objectType], 'update', [ - 'data' => [ - 'additionalData' => serialize($data) - ] - ]); - $this->objectAction->executeAction(); + 'isDisabled' => $this->isDisabled, + ])); $this->saved(); diff --git a/wcfsetup/install/files/lib/acp/page/SitemapListPage.class.php b/wcfsetup/install/files/lib/acp/page/SitemapListPage.class.php index 94efdb3809..3509086dad 100755 --- a/wcfsetup/install/files/lib/acp/page/SitemapListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/SitemapListPage.class.php @@ -4,6 +4,7 @@ use wcf\data\object\type\ObjectType; use wcf\data\object\type\ObjectTypeCache; use wcf\page\AbstractPage; use wcf\system\WCF; +use wcf\system\worker\SitemapRebuildWorker; /** * Shows a list of sitemap object types. @@ -37,6 +38,10 @@ class SitemapListPage extends AbstractPage { parent::readData(); $this->sitemapObjectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.sitemap.object'); + + foreach ($this->sitemapObjectTypes as $sitemapObjectType) { + SitemapRebuildWorker::prepareSitemapObject($sitemapObjectType); + } } /** diff --git a/wcfsetup/install/files/lib/data/object/type/SitemapObjectTypeAction.class.php b/wcfsetup/install/files/lib/data/object/type/SitemapObjectTypeAction.class.php index cffcc44f8d..f99a95a9f8 100644 --- a/wcfsetup/install/files/lib/data/object/type/SitemapObjectTypeAction.class.php +++ b/wcfsetup/install/files/lib/data/object/type/SitemapObjectTypeAction.class.php @@ -2,7 +2,9 @@ namespace wcf\data\object\type; use wcf\data\IToggleAction; use wcf\system\exception\IllegalLinkException; +use wcf\system\registry\RegistryHandler; use wcf\system\WCF; +use wcf\system\worker\SitemapRebuildWorker; /** * Executes sitemap object type-related actions. @@ -33,9 +35,22 @@ class SitemapObjectTypeAction extends ObjectTypeAction implements IToggleAction */ public function toggle() { foreach ($this->getObjects() as $objectEditor) { - $objectEditor->update([ - 'additionalData' => serialize(array_merge($objectEditor->additionalData, ['isDisabled' => !$objectEditor->isDisabled ? 1 : 0])) - ]); + $sitemapData = RegistryHandler::getInstance()->get('com.woltlab.wcf', SitemapRebuildWorker::REGISTRY_PREFIX . $objectEditor->objectType); + $sitemapData = @unserialize($sitemapData); + + if (is_array($sitemapData)) { + $sitemapData['isDisabled'] = $sitemapData['isDisabled'] ? 0 : 1; + } + else { + $sitemapData = [ + 'priority' => $objectEditor->priority, + 'changeFreq' => $objectEditor->changeFreq, + 'rebuildTime' => $objectEditor->rebuildTime, + 'isDisabled' => $objectEditor->isDisabled ? 0 : 1, + ]; + } + + RegistryHandler::getInstance()->set('com.woltlab.wcf', SitemapRebuildWorker::REGISTRY_PREFIX . $objectEditor->objectType, serialize($sitemapData)); } } diff --git a/wcfsetup/install/files/lib/system/worker/SitemapRebuildWorker.class.php b/wcfsetup/install/files/lib/system/worker/SitemapRebuildWorker.class.php index 0dd275239e..2cf3ef7a1e 100755 --- a/wcfsetup/install/files/lib/system/worker/SitemapRebuildWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/SitemapRebuildWorker.class.php @@ -9,6 +9,7 @@ use wcf\system\exception\ImplementationException; use wcf\system\exception\ParentClassException; use wcf\system\io\AtomicWriter; use wcf\system\io\File; +use wcf\system\registry\RegistryHandler; use wcf\system\request\LinkHandler; use wcf\system\Regex; use wcf\system\WCF; @@ -30,6 +31,8 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker { */ const SITEMAP_OBJECT_LIMIT = 50000; + const REGISTRY_PREFIX = 'sitemapData_'; + /** * @inheritDoc */ @@ -83,6 +86,7 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker { // read sitemaps $sitemapObjects = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.sitemap.object'); foreach ($sitemapObjects as $sitemapObject) { + self::prepareSitemapObject($sitemapObject); $processor = $sitemapObject->getProcessor(); if ($processor->isAvailableType() && ($sitemapObject->isDisabled === null || !$sitemapObject->isDisabled)) { @@ -421,4 +425,24 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker { private function changeToActualUser() { WCF::getSession()->changeUser($this->actualUser, true); } + + /** + * Reads the columns changed by the user for this sitemap object from the registry and modifies the object accordingly. + * + * @param ObjectType $object + */ + public static function prepareSitemapObject(ObjectType &$object) { + $sitemapData = RegistryHandler::getInstance()->get('com.woltlab.wcf', self::REGISTRY_PREFIX . $object->objectType); + + if ($sitemapData !== null) { + $sitemapData = @unserialize($sitemapData); + + if (is_array($sitemapData)) { + $object->priority = $sitemapData['priority']; + $object->changeFreq = $sitemapData['changeFreq']; + $object->rebuildTime = $sitemapData['rebuildTime']; + $object->isDisabled = $sitemapData['isDisabled']; + } + } + } }