From: Tim Düsterhus Date: Tue, 1 Sep 2020 14:45:40 +0000 (+0200) Subject: Add DownloadStyleLogoJob X-Git-Tag: 5.3.0_Alpha_1~10^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b2efa400ff0493fa2ce473ca27142636b6d5264e;p=GitHub%2FWoltLab%2FWCF.git Add DownloadStyleLogoJob --- diff --git a/wcfsetup/install/files/lib/system/background/job/DownloadStyleLogoJob.class.php b/wcfsetup/install/files/lib/system/background/job/DownloadStyleLogoJob.class.php new file mode 100644 index 0000000000..b4b203c5be --- /dev/null +++ b/wcfsetup/install/files/lib/system/background/job/DownloadStyleLogoJob.class.php @@ -0,0 +1,78 @@ + + * @package WoltLabSuite\Core\System\Background\Job + * @since 5.3 + * @deprecated 5.3 - This background job is used for the upgrade from 5.2 to 5.3. + */ +class DownloadStyleLogoJob extends AbstractBackgroundJob { + /** + * @inheritDoc + */ + const MAX_FAILURES = 5; + + /** + * @var int + */ + protected $styleID; + + public function __construct(Style $style) { + $this->styleID = $style->styleID; + } + + /** + * @return int every 10 minutes + */ + public function retryAfter() { + return 10 * 60; + } + + /** + * @inheritDoc + */ + public function perform() { + $style = new Style($this->styleID); + if (!$style->styleID) return; + $styleEditor = new StyleEditor($style); + + $style->loadVariables(); + $variables = $style->getVariables(); + + $http = HttpFactory::makeClient([ + 'timeout' => 10, + ]); + + foreach (['pageLogo', 'pageLogoMobile'] as $type) { + if ($variables[$type] && Url::is($variables[$type])) { + $extension = pathinfo(Url::parse($variables[$type])['path'], PATHINFO_EXTENSION); + + if (in_array($extension, ['gif','png','jpg','jpeg','svg','webp'])) { + $newLocation = $type . '.' . $extension; + + $http->send(new Request('GET', $variables[$type]), [ + 'sink' => $style->getAssetPath() . $newLocation, + ]); + + $variables[$type] = $newLocation; + } + else { + $variables[$type] = ''; + } + + $styleEditor->setVariables($variables); + } + } + StyleEditor::resetCache(); + } +}