Dynamically apply the branding free license
authorAlexander Ebert <ebert@woltlab.com>
Tue, 26 Sep 2023 15:28:20 +0000 (17:28 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 26 Sep 2023 15:28:20 +0000 (17:28 +0200)
wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php
wcfsetup/install/files/lib/data/option/OptionEditor.class.php

index 59732e3992c1ceb37d3a286ee93ebf027d3f6f4b..c6a3ea339d23694e1f1668ec969d83af9181ac2d 100644 (file)
@@ -15,6 +15,7 @@ use wcf\system\language\preload\event\PreloadPhrasesCollecting;
 use wcf\system\language\preload\PhrasePreloader;
 use wcf\system\package\event\PackageInstallationPluginSynced;
 use wcf\system\package\event\PackageListChanged;
+use wcf\system\package\license\LicenseApi;
 use wcf\system\user\authentication\event\UserLoggedIn;
 use wcf\system\user\event\UsernameValidating;
 use wcf\system\WCF;
@@ -62,4 +63,22 @@ return static function (): void {
         $event->register(\wcf\system\worker\SitemapRebuildWorker::class, 500);
         $event->register(\wcf\system\worker\StatDailyRebuildDataWorker::class, 800);
     });
+
+    try {
+        $licenseApi = LicenseApi::readFromFile();
+        if ($licenseApi !== null) {
+            $licenseData = $licenseApi->getData();
+            $brandingFree = $licenseData['woltlab']['com.woltlab.brandingFree'] ?? '0.0';
+            $expiresAt = $licenseData['expiryDates']['com.woltlab.brandingFree'] ?? \TIME_NOW;
+            if ($brandingFree !== '0.0' && $expiresAt >= \TIME_NOW) {
+                define('WOLTLAB_BRANDING', false);
+            }
+        }
+    } catch (\Throwable) {
+        // Reading the license file must never cause any errors.
+    }
+
+    if (!defined('WOLTLAB_BRANDING')) {
+        define('WOLTLAB_BRANDING', true);
+    }
 };
index 8cc79d37c15d9c7784fccb82ffa552895297cce9..dece6ba6638a68e4bd54242fd0afa745323c07a4 100644 (file)
@@ -158,6 +158,10 @@ class OptionEditor extends DatabaseObjectEditor implements IEditableCachedObject
         // get all options
         $options = $secretOptions + Option::getOptions();
         foreach ($options as $optionName => $option) {
+            if ($optionName === 'WOLTLAB_BRANDING') {
+                continue;
+            }
+
             $writeValue = $option->optionValue;
             if ($writeValue === null) {
                 $writeValue = "''";