Commit | Line | Data |
---|---|---|
317c8af5 | 1 | <?php |
308c880f | 2 | declare(strict_types=1); |
317c8af5 | 3 | namespace wcf\acp\page; |
7a23a706 | 4 | use wcf\data\package\update\server\PackageUpdateServer; |
eb0f6246 AE |
5 | use wcf\data\package\update\server\PackageUpdateServerList; |
6 | use wcf\data\package\Package; | |
7 | use wcf\data\package\PackageCache; | |
317c8af5 AE |
8 | use wcf\page\AbstractPage; |
9 | use wcf\system\exception\IllegalLinkException; | |
10 | use wcf\system\WCF; | |
317c8af5 AE |
11 | |
12 | /** | |
13 | * Shows a list of purchased plugin store items. | |
14 | * | |
15 | * @author Alexander Ebert | |
c839bd49 | 16 | * @copyright 2001-2018 WoltLab GmbH |
317c8af5 | 17 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
e71525e4 | 18 | * @package WoltLabSuite\Core\Acp\Page |
317c8af5 AE |
19 | */ |
20 | class PluginStorePurchasedItemsPage extends AbstractPage { | |
21 | /** | |
0fcfe5f6 | 22 | * @inheritDoc |
317c8af5 AE |
23 | */ |
24 | public $activeMenuItem = 'wcf.acp.menu.link.package'; | |
25 | ||
26 | /** | |
0fcfe5f6 | 27 | * @inheritDoc |
317c8af5 | 28 | */ |
058cbd6a | 29 | public $neededPermissions = ['admin.configuration.package.canUpdatePackage', 'admin.configuration.package.canUninstallPackage']; |
317c8af5 AE |
30 | |
31 | /** | |
4087dcf3 | 32 | * list of purchased products grouped by WCF major release |
317c8af5 AE |
33 | * @var array<array> |
34 | */ | |
058cbd6a | 35 | public $products = []; |
317c8af5 | 36 | |
4087dcf3 AE |
37 | /** |
38 | * list of product data grouped by WCF major release | |
39 | * @var array<array> | |
40 | */ | |
058cbd6a | 41 | public $productData = []; |
298a7cd8 | 42 | |
4087dcf3 AE |
43 | /** |
44 | * list of installed update servers (Plugin-Store only) | |
7a23a706 | 45 | * @var PackageUpdateServer[] |
4087dcf3 | 46 | */ |
058cbd6a | 47 | public $updateServers = []; |
298a7cd8 | 48 | |
4087dcf3 AE |
49 | /** |
50 | * list of supported WCF major releases (Plugin-Store) | |
7a23a706 | 51 | * @var string[] |
4087dcf3 | 52 | */ |
058cbd6a | 53 | public $wcfMajorReleases = []; |
298a7cd8 | 54 | |
317c8af5 | 55 | /** |
0fcfe5f6 | 56 | * @inheritDoc |
317c8af5 AE |
57 | */ |
58 | public function readParameters() { | |
59 | parent::readParameters(); | |
60 | ||
61 | $this->products = WCF::getSession()->getVar('__pluginStoreProducts'); | |
62 | if (empty($this->products)) { | |
63 | throw new IllegalLinkException(); | |
64 | } | |
65 | ||
298a7cd8 AE |
66 | $this->wcfMajorReleases = WCF::getSession()->getVar('__pluginStoreWcfMajorReleases'); |
67 | if (empty($this->wcfMajorReleases)) { | |
68 | throw new IllegalLinkException(); | |
69 | } | |
317c8af5 AE |
70 | } |
71 | ||
72 | /** | |
0fcfe5f6 | 73 | * @inheritDoc |
317c8af5 AE |
74 | */ |
75 | public function readData() { | |
76 | parent::readData(); | |
77 | ||
298a7cd8 AE |
78 | $serverList = new PackageUpdateServerList(); |
79 | $serverList->readObjects(); | |
80 | foreach ($serverList as $server) { | |
81 | if (preg_match('~https?://store.woltlab.com/(?P<wcfMajorRelease>[a-z]+)/~', $server->serverURL, $matches)) { | |
82 | $this->updateServers[$matches['wcfMajorRelease']] = $server; | |
83 | } | |
317c8af5 AE |
84 | } |
85 | ||
298a7cd8 AE |
86 | foreach ($this->products as $packageUpdateID => $product) { |
87 | $wcfMajorRelease = $product['wcfMajorRelease']; | |
88 | if (!isset($this->productData[$wcfMajorRelease])) { | |
058cbd6a | 89 | $this->productData[$wcfMajorRelease] = []; |
298a7cd8 AE |
90 | } |
91 | ||
92 | $languageCode = WCF::getLanguage()->languageCode; | |
63b9817b | 93 | $packageName = isset($product['packageName'][$languageCode]) ? $product['packageName'][$languageCode] : $product['packageName']['en']; |
298a7cd8 | 94 | |
058cbd6a | 95 | $this->productData[$wcfMajorRelease][$packageUpdateID] = [ |
298a7cd8 AE |
96 | 'author' => $product['author'], |
97 | 'authorURL' => $product['authorURL'], | |
1a6e8c52 | 98 | 'package' => $product['package'], |
298a7cd8 AE |
99 | 'packageName' => $packageName, |
100 | 'pluginStoreURL' => $product['pluginStoreURL'], | |
058cbd6a | 101 | 'version' => [ |
298a7cd8 AE |
102 | 'available' => $product['lastVersion'], |
103 | 'installed' => '' | |
058cbd6a | 104 | ], |
63b9817b | 105 | 'status' => isset($this->updateServers[$wcfMajorRelease]) ? 'install' : 'unavailable' |
058cbd6a | 106 | ]; |
298a7cd8 AE |
107 | |
108 | $package = PackageCache::getInstance()->getPackageByIdentifier($product['package']); | |
109 | if ($package !== null) { | |
110 | $this->productData[$wcfMajorRelease][$packageUpdateID]['version']['installed'] = $package->packageVersion; | |
111 | ||
112 | if (Package::compareVersion($product['lastVersion'], $package->packageVersion, '>')) { | |
113 | $this->productData[$wcfMajorRelease][$packageUpdateID]['status'] = 'update'; | |
114 | } | |
e1e7ce56 | 115 | else if (Package::compareVersion($product['lastVersion'], $package->packageVersion, '<=')) { |
60fe64f6 AE |
116 | $this->productData[$wcfMajorRelease][$packageUpdateID]['status'] = 'upToDate'; |
117 | } | |
298a7cd8 | 118 | } |
6e48b0ff AE |
119 | |
120 | if (isset($this->updateServers[$wcfMajorRelease]) && $this->updateServers[$wcfMajorRelease]->lastUpdateTime == 0) { | |
121 | $this->productData[$wcfMajorRelease][$packageUpdateID]['status'] = 'requireUpdate'; | |
122 | } | |
298a7cd8 | 123 | } |
317c8af5 AE |
124 | } |
125 | ||
126 | /** | |
0fcfe5f6 | 127 | * @inheritDoc |
317c8af5 AE |
128 | */ |
129 | public function assignVariables() { | |
130 | parent::assignVariables(); | |
131 | ||
058cbd6a | 132 | WCF::getTPL()->assign([ |
298a7cd8 AE |
133 | 'productData' => $this->productData, |
134 | 'updateServers' => $this->updateServers, | |
135 | 'wcfMajorReleases' => $this->wcfMajorReleases | |
058cbd6a | 136 | ]); |
317c8af5 AE |
137 | } |
138 | } |