From: Joshua Rüsweg Date: Tue, 3 Oct 2017 09:11:50 +0000 (+0200) Subject: Delete sitemap relics when rebuilding the sitemap X-Git-Tag: 3.1.0_Beta_2~57^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=52b710cca3c4dfafbe046a83415d5d964a1ec5bd;p=GitHub%2FWoltLab%2FWCF.git Delete sitemap relics when rebuilding the sitemap Delete all previously created sitemap files on rebuild so that no more relics remain in the system. --- diff --git a/wcfsetup/install/files/lib/system/worker/SitemapRebuildWorker.class.php b/wcfsetup/install/files/lib/system/worker/SitemapRebuildWorker.class.php index 3c1faad535..d455de5122 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\Regex; use wcf\system\request\LinkHandler; use wcf\system\WCF; use wcf\util\FileUtil; @@ -93,6 +94,9 @@ class SitemapRebuildWorker extends AbstractWorker { // modify count, because we handle only one sitemap object per call $this->count += max(1, ceil($list->countObjects() / $this->limit)) * $this->limit; } + else { + $this->deleteSitemaps($sitemapObject->objectType); + } } } } @@ -131,6 +135,11 @@ class SitemapRebuildWorker extends AbstractWorker { $sitemapObject = $this->sitemapObjects[$this->workerData['sitemap']]->getProcessor(); $sitemapLoopCount = $this->workerData['sitemapLoopCount']; + // delete all previously created sitemap files so that no more relics remain in the system + if ($sitemapLoopCount === 0) { + $this->deleteSitemaps($this->sitemapObjects[$this->workerData['sitemap']]->objectType); + } + /** @var DatabaseObjectList $objectList */ $objectList = $sitemapObject->getObjectList(); @@ -362,6 +371,23 @@ class SitemapRebuildWorker extends AbstractWorker { return WCF::getPath() . 'sitemaps/'; } + /** + * Unlink the sitemap files for a given object type name. + * + * @param string $objectTypeName + */ + private function deleteSitemaps($objectTypeName) { + $files = @glob(self::getSitemapPath().$objectTypeName.'*.xml'); + if (is_array($files)) { + $regex = new Regex(preg_quote($objectTypeName).'(_[0-9]*|).xml'); + foreach ($files as $filename) { + if ($regex->match(basename($filename))) { + unlink($filename); + } + } + } + } + /** * Saves the actual user and changes the session owner to a guest. */