From 0f5abeda1423f783b9449caa87ce40f2b00a524f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 26 Sep 2023 17:28:20 +0200 Subject: [PATCH] Dynamically apply the branding free license --- .../files/lib/bootstrap/com.woltlab.wcf.php | 19 +++++++++++++++++++ .../lib/data/option/OptionEditor.class.php | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php b/wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php index 59732e3992..c6a3ea339d 100644 --- a/wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php +++ b/wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php @@ -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); + } }; diff --git a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php index 8cc79d37c1..dece6ba663 100644 --- a/wcfsetup/install/files/lib/data/option/OptionEditor.class.php +++ b/wcfsetup/install/files/lib/data/option/OptionEditor.class.php @@ -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 = "''"; -- 2.20.1