Fix PHP8.2 issues in `SitemapRebuildWorker`
authorMarcel Werk <burntime@woltlab.com>
Fri, 5 May 2023 11:47:31 +0000 (13:47 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 5 May 2023 11:47:31 +0000 (13:47 +0200)
This commit should only to fix the PHP8.2 incompatibilities. The code of the worker is generally quite ugly and should be fundamentally reworked with a future version.

wcfsetup/install/files/acp/templates/sitemapList.tpl
wcfsetup/install/files/lib/acp/page/SitemapListPage.class.php
wcfsetup/install/files/lib/system/worker/SitemapRebuildWorker.class.php

index c007f96f31fa51b59364c18159040d3894d389e8..5adbea77bc0470cb4e394dac73addfc0464c9ce1 100644 (file)
                                {foreach from=$sitemapObjectTypes item=object}
                                        <tr class="sitemapObjectRow jsObjectActionObject" data-object-id="{@$object->getObjectID()}">
                                                <td class="columnIcon">
-                                                       {assign var='sitemapIsDisabled' value=false}
-                                                       {if $object->isDisabled}
-                                                               {assign var='sitemapIsDisabled' value=true}
+                                                       {if $sitemapData[$object->objectType]['isDisabled']}
+                                                               {objectAction action="toggle" isDisabled=true}
+                                                       {else}
+                                                               {objectAction action="toggle" isDisabled=false}
                                                        {/if}
-                                                       {objectAction action="toggle" isDisabled=$sitemapIsDisabled}
                                                        <a href="{link controller="SitemapEdit"}objectType={$object->objectType}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip">{icon name='pencil'}</a>
                                                </td>
                                                <td class="columnTitle columnSitemap"><a href="{link controller="SitemapEdit"}objectType={$object->objectType}{/link}">{lang}wcf.acp.sitemap.objectType.{$object->objectType}{/lang}</a></td>
                                                <td class="columnInteger columnPriority">{$object->priority}</td>
-                                               <td class="columnText columnChangeFreq">{lang}wcf.acp.sitemap.changeFreq.{$object->changeFreq}{/lang}</td>
-                                               <td class="columnInteger columnRebuildTime">{dateInterval end=TIME_NOW+$object->rebuildTime full=true format='plain'}</td>
+                                               <td class="columnText columnChangeFreq">{lang}wcf.acp.sitemap.changeFreq.{$sitemapData[$object->objectType]['changeFreq']}{/lang}</td>
+                                               <td class="columnInteger columnRebuildTime">{dateInterval end=TIME_NOW+$sitemapData[$object->objectType]['rebuildTime'] full=true format='plain'}</td>
                                                
                                                {event name='columns'}
                                        </tr>
index 2e3f665d1c0e0b897150099eb190ca6fb5cf9e14..07248de221eea76def458119a2d1421d1e449795 100755 (executable)
@@ -5,6 +5,7 @@ namespace wcf\acp\page;
 use wcf\data\object\type\ObjectType;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\page\AbstractPage;
+use wcf\system\registry\RegistryHandler;
 use wcf\system\WCF;
 use wcf\system\worker\SitemapRebuildWorker;
 
@@ -33,6 +34,11 @@ class SitemapListPage extends AbstractPage
      */
     public $sitemapObjectTypes = [];
 
+    /**
+     * @var mixed[]
+     */
+    private $sitemapData = [];
+
     /**
      * @inheritDoc
      */
@@ -43,7 +49,26 @@ class SitemapListPage extends AbstractPage
         $this->sitemapObjectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.sitemap.object');
 
         foreach ($this->sitemapObjectTypes as $sitemapObjectType) {
-            SitemapRebuildWorker::prepareSitemapObject($sitemapObjectType);
+            $this->sitemapData[$sitemapObjectType->objectType] = [
+                'changeFreq' => $sitemapObjectType->changeFreq,
+                'rebuildTime' => $sitemapObjectType->rebuildTime,
+                'isDisabled' => 0,
+            ];
+
+            $sitemapData = RegistryHandler::getInstance()->get(
+                'com.woltlab.wcf',
+                SitemapRebuildWorker::REGISTRY_PREFIX . $sitemapObjectType->objectType
+            );
+
+            if ($sitemapData !== null) {
+                $sitemapData = @\unserialize($sitemapData);
+
+                if (\is_array($sitemapData)) {
+                    $this->sitemapData[$sitemapObjectType->objectType]['changeFreq'] = $sitemapData['changeFreq'];
+                    $this->sitemapData[$sitemapObjectType->objectType]['rebuildTime'] = $sitemapData['rebuildTime'];
+                    $this->sitemapData[$sitemapObjectType->objectType]['isDisabled'] = $sitemapData['isDisabled'];
+                }
+            }
         }
     }
 
@@ -56,6 +81,7 @@ class SitemapListPage extends AbstractPage
 
         WCF::getTPL()->assign([
             'sitemapObjectTypes' => $this->sitemapObjectTypes,
+            'sitemapData' => $this->sitemapData,
         ]);
     }
 }
index d7cf537a14d66e44b4ee87253acceb3d276d4335..8ad3ac87c5267518ca61c1b3f7e4aaae1f4a3259 100755 (executable)
@@ -68,6 +68,11 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker
      */
     private $actualUser;
 
+    /**
+     * @var mixed[]
+     */
+    private $sitemapData = [];
+
     /**
      * @inheritDoc
      */
@@ -94,12 +99,12 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker
                 // read sitemaps
                 $sitemapObjects = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.sitemap.object');
                 foreach ($sitemapObjects as $sitemapObject) {
-                    self::prepareSitemapObject($sitemapObject);
+                    $this->prepareSitemapObject($sitemapObject);
                     $processor = $sitemapObject->getProcessor();
 
                     if (
                         $processor->isAvailableType()
-                        && ($sitemapObject->isDisabled === null || !$sitemapObject->isDisabled)
+                        && !$this->sitemapData[$sitemapObject->objectType]['isDisabled']
                     ) {
                         $this->sitemapObjects[] = $sitemapObject;
 
@@ -197,13 +202,14 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker
                     $object->{$sitemapObject->getLastModifiedColumn()}
                 );
 
+                $objectType = $this->sitemapObjects[$this->workerData['sitemap']];
                 if ($sitemapObject->canView($object)) {
                     $this->file->write(WCF::getTPL()->fetch('sitemapEntry', 'wcf', [
                         // strip session links
                         'link' => MessageUtil::stripCrap($link),
                         'lastModifiedTime' => $lastModifiedTime,
-                        'priority' => $this->sitemapObjects[$this->workerData['sitemap']]->priority,
-                        'changeFreq' => $this->sitemapObjects[$this->workerData['sitemap']]->changeFreq,
+                        'priority' => $objectType->priority,
+                        'changeFreq' => $this->sitemapData[$objectType->objectType]['changeFreq'],
                     ]));
 
                     $this->workerData['dataCount']++;
@@ -262,7 +268,7 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker
         while (
             $object
             && \file_exists(self::getSitemapPath() . $object->objectType . '.xml')
-            && \filectime(self::getSitemapPath() . $object->objectType . '.xml') > TIME_NOW - (($object->rebuildTime !== null) ? $object->rebuildTime : 60 * 60 * 24 * 7)
+            && \filectime(self::getSitemapPath() . $object->objectType . '.xml') > TIME_NOW - ($this->sitemapData[$object->objectType]['rebuildTime'] ?: 60 * 60 * 24 * 7)
         ) {
             $filenames = \array_merge(
                 \glob(self::getSitemapPath() . $object->objectType . '_*'),
@@ -507,14 +513,19 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker
     }
 
     /**
-     * Reads the columns changed by the user for this sitemap object from the registry and
-     * modifies the object accordingly.
+     * Reads the columns changed by the user for this sitemap object from the registry.
      *
      * @param ObjectType $object
      * @since       5.3
      */
-    public static function prepareSitemapObject(ObjectType $object)
+    private function prepareSitemapObject(ObjectType $object): void
     {
+        $this->sitemapData[$object->objectType] = [
+            'changeFreq' => $object->changeFreq,
+            'rebuildTime' => $object->rebuildTime,
+            'isDisabled' => 0,
+        ];
+
         $sitemapData = RegistryHandler::getInstance()->get(
             'com.woltlab.wcf',
             self::REGISTRY_PREFIX . $object->objectType
@@ -524,9 +535,9 @@ class SitemapRebuildWorker extends AbstractRebuildDataWorker
             $sitemapData = @\unserialize($sitemapData);
 
             if (\is_array($sitemapData)) {
-                $object->changeFreq = $sitemapData['changeFreq'];
-                $object->rebuildTime = $sitemapData['rebuildTime'];
-                $object->isDisabled = $sitemapData['isDisabled'];
+                $this->sitemapData[$object->objectType]['changeFreq'] = $sitemapData['changeFreq'];
+                $this->sitemapData[$object->objectType]['rebuildTime'] = $sitemapData['rebuildTime'];
+                $this->sitemapData[$object->objectType]['isDisabled'] = $sitemapData['isDisabled'];
             }
         }
     }