Refresh the license file when searching for updates
authorAlexander Ebert <ebert@woltlab.com>
Wed, 27 Sep 2023 12:05:09 +0000 (14:05 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 27 Sep 2023 12:05:09 +0000 (14:05 +0200)
wcfsetup/install/files/lib/data/package/update/PackageUpdateAction.class.php
wcfsetup/install/files/lib/system/cronjob/GetUpdateInfoCronjob.class.php

index 1371c38bf07421a15937379e7a70fb7b483eac75..0b2f0c490ad0120a86fa6b04fb8fb72385c8a7ca 100644 (file)
@@ -13,6 +13,7 @@ use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\NamedUserException;
 use wcf\system\exception\SystemException;
 use wcf\system\exception\UserInputException;
+use wcf\system\package\license\LicenseApi;
 use wcf\system\package\PackageInstallationScheduler;
 use wcf\system\package\PackageUpdateDispatcher;
 use wcf\system\package\PackageUpdateUnauthorizedException;
@@ -610,6 +611,12 @@ class PackageUpdateAction extends AbstractDatabaseObjectAction
     {
         PackageUpdateDispatcher::getInstance()->refreshPackageDatabase([], $this->parameters['ignoreCache']);
 
+        // Try to update the cached license data to check for recent purchases.
+        if (LicenseApi::hasLicenseCredentials()) {
+            $licenseApi = LicenseApi::fetchFromRemote();
+            $licenseApi->updateLicenseFile();
+        }
+
         $updates = PackageUpdateDispatcher::getInstance()->getAvailableUpdates();
         $url = '';
         if (!empty($updates)) {
index 55d938e0c70a2453c3bc8c80df62e02a51b2a162..9d0bde92edf0a4d0dfbb436ffdfd99eb377dfbc7 100644 (file)
@@ -4,6 +4,7 @@ namespace wcf\system\cronjob;
 
 use wcf\data\cronjob\Cronjob;
 use wcf\system\language\LanguageFactory;
+use wcf\system\package\license\LicenseApi;
 use wcf\system\package\PackageUpdateDispatcher;
 use wcf\system\WCF;
 
@@ -40,5 +41,21 @@ class GetUpdateInfoCronjob extends AbstractCronjob
                 WCF::setLanguage($currentLanguage);
             }
         }
+
+        $this->refreshLicenseFile();
+    }
+
+    /**
+     * Refresh the license file to update any recently made purchases.
+     */
+    private function refreshLicenseFile(): void
+    {
+        try {
+            $licenseApi = LicenseApi::fetchFromRemote();
+            $licenseApi->updateLicenseFile();
+        } catch (\Throwable) {
+            // This is a “silent” operation that should not interrupt the
+            // execution of cronjobs in case of an error.
+        }
     }
 }