use wcf\system\package\license\LicenseApi;
try {
- $licenseApi = LicenseApi::fetchFromRemote();
- $licenseApi->updateLicenseFile();
+ $licenseApi = new LicenseApi();
+ $licenseData = $licenseApi->fetchFromRemote();
+ $licenseApi->updateLicenseFile($licenseData);
// If we’re still here it means that the credentials are actually valid. Now
// we can check if the credentials for both servers are in sync, because
use wcf\system\form\builder\field\validation\FormFieldValidator;
use wcf\system\package\license\exception\ParsingFailed;
use wcf\system\package\license\LicenseApi;
+use wcf\system\package\license\LicenseData;
use wcf\system\request\LinkHandler;
use wcf\util\HeaderUtil;
private LicenseApi $licenseApi;
+ private LicenseData $licenseData;
+
/**
* @inheritDoc
*/
{
parent::createForm();
+ $this->licenseApi = new LicenseApi();
+
$this->form->appendChildren([
$credentialsContainer = FormContainer::create('credentials')
->label('wcf.acp.firstTimeSetup.license.credentials')
\assert($licenseNo instanceof TextFormField);
try {
- $this->licenseApi = LicenseApi::fetchFromRemote([
+ $this->licenseData = $this->licenseApi->fetchFromRemote([
'username' => $licenseNo->getValue(),
'password' => $serialNo->getValue(),
]);
Option::getOptionByName('first_time_setup_state')->optionID => 1,
];
- if (isset($this->licenseApi)) {
- $this->licenseApi->updateLicenseFile();
+ if (isset($this->licenseData)) {
+ $this->licenseApi->updateLicenseFile($this->licenseData);
- if (isset($this->licenseApi->getData()->license['authCode'])) {
- $optionData[Option::getOptionByName('package_server_auth_code')->optionID] = $this->licenseApi->getData()->license['authCode'];
+ if (isset($this->licenseData->license['authCode'])) {
+ $optionData[Option::getOptionByName('package_server_auth_code')->optionID] = $this->licenseData->license['authCode'];
}
}
use wcf\system\form\builder\field\validation\FormFieldValidator;
use wcf\system\package\license\exception\ParsingFailed;
use wcf\system\package\license\LicenseApi;
+use wcf\system\package\license\LicenseData;
use wcf\system\request\LinkHandler;
/**
private LicenseApi $licenseApi;
+ private LicenseData $licenseData;
+
private string $url;
/**
{
parent::createForm();
+ $this->licenseApi = new LicenseApi();
+
$licenseNo = '';
$serialNo = '';
$authData = PackageUpdateServer::getWoltLabUpdateServer()->getAuthData();
\assert($licenseNo instanceof TextFormField);
try {
- $this->licenseApi = LicenseApi::fetchFromRemote([
+ $this->licenseData = $this->licenseApi->fetchFromRemote([
'username' => $licenseNo->getValue(),
'password' => $serialNo->getValue(),
]);
}
$authCode = '';
- if (isset($this->licenseApi)) {
- $this->licenseApi->updateLicenseFile();
+ if (isset($this->licenseData)) {
+ $this->licenseApi->updateLicenseFile($this->licenseData);
- $authCode = $this->licenseApi->getData()->license['authCode'] ?? '';
+ $authCode = $this->licenseData->license['authCode'] ?? '';
} else {
- LicenseApi::removeLicenseFile();
+ $this->licenseApi->removeLicenseFile();
}
$objectAction = new OptionAction(
(new PackageUpdateAction([], 'refreshDatabase'))->executeAction();
- $licenseApi = LicenseApi::fetchFromRemote();
- $licenseApi->updateLicenseFile();
-
- $this->licenseData = $licenseApi->getData();
+ $licenseApi = new LicenseApi();
+ $this->licenseData = $licenseApi->fetchFromRemote();
+ $licenseApi->updateLicenseFile($this->licenseData);
$identifiers = \array_merge(
\array_keys($this->licenseData->woltlab),
});
try {
- $licenseApi = LicenseApi::readFromFile();
- if ($licenseApi !== null) {
- $licenseData = $licenseApi->getData();
+ $licenseData = LicenseApi::readFromFile();
+ if ($licenseData !== null) {
$brandingFree = $licenseData->woltlab['com.woltlab.brandingFree'] ?? '0.0';
$expiresAt = $licenseData->license['expiryDates']['com.woltlab.brandingFree'] ?? \TIME_NOW;
if ($brandingFree !== '0.0' && $expiresAt >= \TIME_NOW) {
// Try to update the cached license data to check for recent purchases.
if (LicenseApi::hasLicenseCredentials()) {
- $licenseApi = LicenseApi::fetchFromRemote();
- $licenseApi->updateLicenseFile();
+ $licenseApi = new LicenseApi();
+ $licenseData = $licenseApi->fetchFromRemote();
+ $licenseApi->updateLicenseFile($licenseData);
}
$updates = PackageUpdateDispatcher::getInstance()->getAvailableUpdates();
*/
public function getCkeditorLicenseKey(): string
{
- $licenseApi = LicenseApi::readFromFile();
- if ($licenseApi === null) {
+ $licenseData = LicenseApi::readFromFile();
+ if ($licenseData === null) {
return '';
}
- return $licenseApi->getData()->license['ckeditorLicenseKey'] ?? '';
+ return $licenseData->license['ckeditorLicenseKey'] ?? '';
}
}
private function refreshLicenseFile(): void
{
try {
- $licenseApi = LicenseApi::fetchFromRemote();
- $licenseApi->updateLicenseFile();
+ $licenseApi = new LicenseApi();
+ $licenseData = $licenseApi->fetchFromRemote();
+ $licenseApi->updateLicenseFile($licenseData);
} catch (\Throwable) {
// This is a “silent” operation that should not interrupt the
// execution of cronjobs in case of an error.
*/
final class LicenseApi
{
- private readonly LicenseData $data;
-
private const LICENSE_FILE = \WCF_DIR . 'license.php';
- private function __construct(LicenseData $data)
- {
- $this->data = $data;
- }
-
- public function getData(): LicenseData
- {
- return $this->data;
- }
-
- public function updateLicenseFile(): void
+ public function updateLicenseFile(LicenseData $data): void
{
@\file_put_contents(
self::LICENSE_FILE,
return unserialize(%s);
EOT,
\gmdate('r', \TIME_NOW),
- \var_export(\serialize($this->data), true),
+ \var_export(\serialize($data), true),
)
);
}
}
}
- public static function fetchFromRemote(array $authData = []): LicenseApi
+ public static function fetchFromRemote(array $authData = []): LicenseData
{
if ($authData === []) {
if (!self::hasLicenseCredentials()) {
$response = HttpFactory::makeClientWithTimeout(5)->send($request);
- return new LicenseApi(self::parseLicenseData($response->getBody()));
+ return self::parseLicenseData($response->getBody());
}
- public static function readFromFile(): ?LicenseApi
+ public static function readFromFile(): ?LicenseData
{
if (!\is_readable(self::LICENSE_FILE)) {
return null;
}
- return new LicenseApi(require(self::LICENSE_FILE));
+ return require(self::LICENSE_FILE);
}
- public static function removeLicenseFile(): void
+ public function removeLicenseFile(): void
{
if (!\file_exists(self::LICENSE_FILE)) {
return;