From 7d547f61ee367ec5584c2e416d0d1cd3780a6d44 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 15 Jul 2017 22:35:17 +0200 Subject: [PATCH] Added `pluginStoreFileID` for packages See #2319 --- .../install/files/acp/templates/package.tpl | 7 ++++ .../files/lib/acp/page/PackagePage.class.php | 28 +++++++++++++-- .../package/update/PackageUpdate.class.php | 1 + .../server/PackageUpdateServer.class.php | 18 ++++++++++ .../package/PackageUpdateDispatcher.class.php | 36 +++++++++++-------- wcfsetup/install/lang/de.xml | 2 ++ wcfsetup/install/lang/en.xml | 2 ++ wcfsetup/setup/db/install.sql | 3 +- 8 files changed, 80 insertions(+), 17 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/package.tpl b/wcfsetup/install/files/acp/templates/package.tpl index ffbe032dad..5e7708ead5 100644 --- a/wcfsetup/install/files/acp/templates/package.tpl +++ b/wcfsetup/install/files/acp/templates/package.tpl @@ -75,6 +75,13 @@
{lang}wcf.acp.package.author{/lang}
{if $package->authorURL}{$package->author}{else}{$package->author}{/if}
+ {if $pluginStoreFileID} + {capture assign=_storeUrl}https://pluginstore.woltlab.com/file/{$pluginStoreFileID}/{/capture} +
+
{lang}wcf.acp.pluginStore.file{/lang}
+
{lang}wcf.acp.pluginStore.file.link{/lang}
+
+ {/if} {event name='propertyFields'} diff --git a/wcfsetup/install/files/lib/acp/page/PackagePage.class.php b/wcfsetup/install/files/lib/acp/page/PackagePage.class.php index be6cacd5f6..99bfff286f 100755 --- a/wcfsetup/install/files/lib/acp/page/PackagePage.class.php +++ b/wcfsetup/install/files/lib/acp/page/PackagePage.class.php @@ -34,7 +34,13 @@ class PackagePage extends AbstractPage { * package object * @var Package */ - public $package = null; + public $package; + + /** + * Plugin-Store fileID + * @var integer + */ + public $pluginStoreFileID = 0; /** * @inheritDoc @@ -49,12 +55,30 @@ class PackagePage extends AbstractPage { } } + /** + * @inheritDoc + */ + public function readData() { + parent::readData(); + + $sql = "SELECT pluginStoreFileID + FROM wcf".WCF_N."_package_update + WHERE package = ? + AND pluginStoreFileID <> 0"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$this->package->package]); + $this->pluginStoreFileID = intval($statement->fetchSingleColumn()); + } + /** * @inheritDoc */ public function assignVariables() { parent::assignVariables(); - WCF::getTPL()->assign('package', $this->package); + WCF::getTPL()->assign([ + 'package' => $this->package, + 'pluginStoreFileID' => $this->pluginStoreFileID + ]); } } diff --git a/wcfsetup/install/files/lib/data/package/update/PackageUpdate.class.php b/wcfsetup/install/files/lib/data/package/update/PackageUpdate.class.php index b93aa1901b..e22449749b 100644 --- a/wcfsetup/install/files/lib/data/package/update/PackageUpdate.class.php +++ b/wcfsetup/install/files/lib/data/package/update/PackageUpdate.class.php @@ -18,6 +18,7 @@ use wcf\data\DatabaseObject; * @property-read string $author author of the package * @property-read string $authorURL external url to the website of the package author * @property-read integer $isApplication is `1` if the package update belongs to an application, otherwise `0` + * @property-read integer $pluginStoreFileID file id for related package on pluginstore.woltlab.com, otherwise `0` */ class PackageUpdate extends DatabaseObject { /** diff --git a/wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php b/wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php index fd7e7dc82f..03fa2c072e 100644 --- a/wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php +++ b/wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php @@ -220,4 +220,22 @@ class PackageUpdateServer extends DatabaseObject { return false; } + + /** + * Returns true if the host is `update.woltlab.com`. + * + * @return boolean + */ + public function isWoltLabUpdateServer() { + return Url::parse($this->serverURL)['host'] === 'update.woltlab.com'; + } + + /** + * Returns true if the host is `store.woltlab.com`. + * + * @return boolean + */ + public function isWoltLabStoreServer() { + return Url::parse($this->serverURL)['host'] === 'store.woltlab.com'; + } } diff --git a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php index 862b5b9f27..83d6e03a18 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php @@ -144,7 +144,8 @@ class PackageUpdateDispatcher extends SingletonFactory { $request = new HTTPRequest($updateServer->getListURL($forceHTTP), $settings); - if ($updateServer->apiVersion == '2.1') { + $apiVersion = $updateServer->apiVersion; + if (in_array($apiVersion, ['2.1', '3.1'])) { $metaData = $updateServer->getMetaData(); if (isset($metaData['list']['etag'])) $request->addHeader('if-none-match', $metaData['list']['etag']); if (isset($metaData['list']['lastModified'])) $request->addHeader('if-modified-since', $metaData['list']['lastModified']); @@ -178,7 +179,7 @@ class PackageUpdateDispatcher extends SingletonFactory { // parse given package update xml $allNewPackages = false; - if ($updateServer->apiVersion == '2.0' || $reply['statusCode'] != 304) { + if ($apiVersion === '2.0' || $reply['statusCode'] != 304) { $allNewPackages = $this->parsePackageUpdateXML($updateServer, $reply['body']); } @@ -189,15 +190,18 @@ class PackageUpdateDispatcher extends SingletonFactory { ]; // check if server indicates support for a newer API - if ($updateServer->apiVersion == '2.0' && !empty($reply['httpHeaders']['wcf-update-server-api'])) { + if ($updateServer->apiVersion !== '3.1' && !empty($reply['httpHeaders']['wcf-update-server-api'])) { $apiVersions = explode(' ', reset($reply['httpHeaders']['wcf-update-server-api'])); - if (in_array('2.1', $apiVersions)) { - $data['apiVersion'] = '2.1'; + if (in_array('3.1', $apiVersions)) { + $apiVersion = $data['apiVersion'] = '3.1'; + } + else if (in_array('2.1', $apiVersions)) { + $apiVersion = $data['apiVersion'] = '2.1'; } } $metaData = []; - if ($updateServer->apiVersion == '2.1' || (isset($data['apiVersion']) && $data['apiVersion'] == '2.1')) { + if (in_array($apiVersion, ['2.1', '3.1'])) { if (empty($reply['httpHeaders']['etag']) && empty($reply['httpHeaders']['last-modified'])) { throw new SystemException("Missing required HTTP headers 'etag' and 'last-modified'."); } @@ -277,7 +281,8 @@ class PackageUpdateDispatcher extends SingletonFactory { 'authorURL' => '', 'isApplication' => 0, 'packageDescription' => '', - 'versions' => [] + 'versions' => [], + 'pluginStoreFileID' => 0 ]; // parse package information @@ -295,6 +300,12 @@ class PackageUpdateDispatcher extends SingletonFactory { case 'isapplication': $packageInfo['isApplication'] = intval($element->nodeValue); break; + + case 'pluginStoreFileID': + if ($updateServer->isWoltLabStoreServer()) { + $packageInfo['pluginStoreFileID'] = intval($element->nodeValue); + } + break; } } @@ -314,12 +325,8 @@ class PackageUpdateDispatcher extends SingletonFactory { $key = ''; if ($this->hasAuthCode) { - if (preg_match('~^https?://update\.woltlab\.com~', $updateServer->serverURL)) { - $key = 'woltlab'; - } - else if (preg_match('~^https?://store\.woltlab\.com~', $updateServer->serverURL)) { - $key = 'pluginstore'; - } + if ($updateServer->isWoltLabUpdateServer()) $key = 'woltlab'; + else if ($updateServer->isWoltLabStoreServer()) $key = 'pluginstore'; } // parse versions @@ -435,7 +442,8 @@ class PackageUpdateDispatcher extends SingletonFactory { 'packageDescription' => $packageData['packageDescription'], 'author' => $packageData['author'], 'authorURL' => $packageData['authorURL'], - 'isApplication' => $packageData['isApplication'] + 'isApplication' => $packageData['isApplication'], + 'pluginStoreFileID' => $packageData['pluginStoreFileID'] ]); $packageUpdateID = $packageUpdate->packageUpdateID; diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index c0f1ead99d..36e9d83547 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1610,6 +1610,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 5577dd0385..39176eef21 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1549,6 +1549,8 @@ + + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index ed324aff9d..158327fca9 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -938,6 +938,7 @@ CREATE TABLE wcf1_package_update ( author VARCHAR(255) NOT NULL DEFAULT '', authorURL VARCHAR(255) NOT NULL DEFAULT '', isApplication TINYINT(1) NOT NULL DEFAULT 0, + pluginStoreFileID INT(10) NOT NULL DEFAULT 0, UNIQUE KEY packageUpdateServerID (packageUpdateServerID, package) ); @@ -980,7 +981,7 @@ CREATE TABLE wcf1_package_update_server ( lastUpdateTime INT(10) NOT NULL DEFAULT 0, status ENUM('online', 'offline') NOT NULL DEFAULT 'online', errorMessage TEXT, - apiVersion ENUM('2.0', '2.1') NOT NULL DEFAULT '2.0', + apiVersion ENUM('2.0', '2.1', '3.1') NOT NULL DEFAULT '2.0', metaData TEXT ); -- 2.20.1