Update Google Fonts when upgrading to 5.4
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 26 Feb 2021 13:32:30 +0000 (14:32 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 26 Feb 2021 13:32:30 +0000 (14:32 +0100)
Resolves #4034

com.woltlab.wcf/package.xml
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_update_google_font.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/background/job/DownloadGoogleFontBackgroundJob.class.php [new file with mode: 0644]

index 932197b82d74f7d544c6b01d8ce28d03a70854a3..242d2117dafbdf8d2ccb4028be963e6f59449295 100644 (file)
@@ -117,5 +117,8 @@ tar cvf com.woltlab.wcf/files_pre.tar -C wcfsetup/install/files/ \
                
                <!-- Migration of the rank images -->
                <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.4_migrate_rank_images.php</instruction>
+
+               <!-- Update of the Google Fonts -->
+               <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.4_update_google_font.php</instruction>
        </instructions>
 </package>
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_update_google_font.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4_update_google_font.php
new file mode 100644 (file)
index 0000000..e2f7646
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * Re-downloads all Google Fonts.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core
+ */
+
+use wcf\system\background\BackgroundQueueHandler;
+use wcf\system\background\job\DownloadGoogleFontBackgroundJob;
+
+$families = \glob(WCF_DIR . 'font/families/*/font.css');
+
+foreach ($families as $css) {
+    $family = \basename(\dirname($css));
+
+    BackgroundQueueHandler::getInstance()->enqueueIn(
+        new DownloadGoogleFontBackgroundJob($family),
+        10 * 60
+    );
+}
diff --git a/wcfsetup/install/files/lib/system/background/job/DownloadGoogleFontBackgroundJob.class.php b/wcfsetup/install/files/lib/system/background/job/DownloadGoogleFontBackgroundJob.class.php
new file mode 100644 (file)
index 0000000..5718275
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace wcf\system\background\job;
+
+use wcf\system\style\FontManager;
+
+/**
+ * Downloads a Google Font family.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Background\Job
+ * @since   5.4
+ */
+final class DownloadGoogleFontBackgroundJob extends AbstractBackgroundJob
+{
+    /**
+     * @inheritDoc
+     */
+    const MAX_FAILURES = 5;
+
+    /**
+     * @var string
+     */
+    protected $family;
+
+    public function __construct(string $family)
+    {
+        $this->family = $family;
+    }
+
+    /**
+     * @return  int every 10 minutes
+     */
+    public function retryAfter()
+    {
+        return 10 * 60;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function perform()
+    {
+        FontManager::getInstance()->downloadFamily($this->family);
+    }
+}