3 namespace wcf\system\package
;
5 use wcf\data\package\update\server\PackageUpdateServer
;
6 use wcf\system\exception\UserException
;
10 * Handles the case that the credentials for update server are either missing or invalid.
12 * @author Alexander Ebert
13 * @copyright 2001-2024 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 final class PackageUpdateUnauthorizedException
extends UserException
19 * @param string[] $responseHeaders
20 * @param mixed[] $packageUpdateVersion
22 public function __construct(
23 private readonly
int $responseStatusCode,
24 private readonly
array $responseHeaders,
25 private readonly
string $responseMessage,
26 private readonly PackageUpdateServer
$updateServer,
27 private readonly
array $packageUpdateVersion = []
32 * Returns the rendered template.
34 public function getRenderedTemplate(): string
36 $requiresPaidUpgrade = false;
37 if ($this->updateServer
->isWoltLabStoreServer() && !empty($this->packageUpdateVersion
['pluginStoreFileID'])) {
38 $requiresPaidUpgrade = ($this->responseHeaders
['wcf-update-server-requires-paid-upgrade'][0] ??
'') === 'true';
41 if ($requiresPaidUpgrade) {
42 WCF
::getTPL()->assign([
43 'packageName' => $this->packageUpdateVersion
['packageName'],
44 'pluginStoreFileID' => $this->packageUpdateVersion
['pluginStoreFileID'],
47 return WCF
::getTPL()->fetch('packageUpdateUnauthorizedPaidUpgrade');
50 $authInsufficient = (($this->responseHeaders
['wcf-update-server-auth'][0] ??
'') === 'unauthorized');
51 if ($authInsufficient && !empty($this->packageUpdateVersion
['pluginStoreFileID'])) {
52 $hasOnlyTrustedServers = true;
53 foreach (PackageUpdateServer
::getActiveUpdateServers() as $updateServer) {
54 if (!$updateServer->isWoltLabUpdateServer() && !$updateServer->isWoltLabStoreServer()) {
55 $hasOnlyTrustedServers = false;
60 if ($hasOnlyTrustedServers) {
61 WCF
::getTPL()->assign([
62 'packageName' => $this->packageUpdateVersion
['packageName'],
63 'pluginStoreFileID' => $this->packageUpdateVersion
['pluginStoreFileID'],
66 return WCF
::getTPL()->fetch('packageUpdateUnauthorizedPurchaseRequired');
70 WCF
::getTPL()->assign([
71 'authInsufficient' => $authInsufficient,
72 'packageUpdateVersion' => $this->packageUpdateVersion
,
73 'updateServer' => $this->updateServer
,
74 'serverAuthData' => $this->updateServer
->getAuthData(),
75 'requiresPaidUpgrade' => $requiresPaidUpgrade,
76 'responseStatusCode' => $this->responseStatusCode
,
77 'responseHeaders' => $this->responseHeaders
,
78 'responseMessage' => $this->responseMessage
,
81 return WCF
::getTPL()->fetch('packageUpdateUnauthorized');
84 public function getResponseMessage(): string
86 return $this->responseMessage
;