Save changes to the sitemap objects in the registry
authorjoshuaruesweg <ruesweg@woltlab.com>
Sat, 11 Jul 2020 09:29:37 +0000 (11:29 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Sat, 11 Jul 2020 09:29:37 +0000 (11:29 +0200)
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

wcfsetup/install/files/lib/acp/form/SitemapEditForm.class.php
wcfsetup/install/files/lib/acp/page/SitemapListPage.class.php
wcfsetup/install/files/lib/data/object/type/SitemapObjectTypeAction.class.php
wcfsetup/install/files/lib/system/worker/SitemapRebuildWorker.class.php

index 37b1af79338d2f568a8a28dd54e9a7fd356b5d7c..e51e7d70317684d5582ba4810a56216d9be9a20e 100755 (executable)
@@ -1,12 +1,13 @@
 <?php
 namespace wcf\acp\form;
 use wcf\data\object\type\ObjectType;
-use wcf\data\object\type\ObjectTypeAction;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\form\AbstractForm;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\UserInputException;
+use wcf\system\registry\RegistryHandler;
 use wcf\system\WCF;
+use wcf\system\worker\SitemapRebuildWorker;
 
 /**
  * Shows the sitemap edit form.
@@ -105,10 +106,21 @@ class SitemapEditForm extends AbstractForm {
                parent::readData();
                
                if (empty($_POST)) {
-                       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;
+                       $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();
                
index 94efdb3809464d27f38372668cc6473f10b0ddf8..3509086dad014c8015ae4311fdaf18e325a1ef21 100755 (executable)
@@ -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);
+               }
        }
        
        /**
index cffcc44f8df5df7514e7d8552749accbced08d82..f99a95a9f8e1d1c0a8d60824d6761b01693c3619 100644 (file)
@@ -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));
                }
        }
        
index 0dd275239e0f6622d377dcf0e18623035b1edc46..2cf3ef7a1e620f307c79cd58e00865fb6457bd0d 100755 (executable)
@@ -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'];
+                       }
+               }
+       }
 }