Added `pluginStoreFileID` for packages
authorAlexander Ebert <ebert@woltlab.com>
Sat, 15 Jul 2017 20:35:17 +0000 (22:35 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 15 Jul 2017 20:35:22 +0000 (22:35 +0200)
See #2319

wcfsetup/install/files/acp/templates/package.tpl
wcfsetup/install/files/lib/acp/page/PackagePage.class.php
wcfsetup/install/files/lib/data/package/update/PackageUpdate.class.php
wcfsetup/install/files/lib/data/package/update/server/PackageUpdateServer.class.php
wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml
wcfsetup/setup/db/install.sql

index ffbe032dad4276caa20a93017eb91e6e33fc75c7..5e7708ead5c789bfc68914cb507cdd671d54c7ca 100644 (file)
                                <dt>{lang}wcf.acp.package.author{/lang}</dt>
                                <dd>{if $package->authorURL}<a href="{@$__wcf->getPath()}acp/dereferrer.php?url={$package->authorURL|rawurlencode}" class="externalURL">{$package->author}</a>{else}{$package->author}{/if}</dd>
                        </dl>
+                       {if $pluginStoreFileID}
+                               {capture assign=_storeUrl}https://pluginstore.woltlab.com/file/{$pluginStoreFileID}/{/capture}
+                               <dl>
+                                       <dt>{lang}wcf.acp.pluginStore.file{/lang}</dt>
+                                       <dd><a href="{@$__wcf->getPath()}acp/dereferrer.php?url={$_storeUrl|rawurlencode}" class="externalURL">{lang}wcf.acp.pluginStore.file.link{/lang}</a></dd>
+                               </dl>
+                       {/if}
                        
                        {event name='propertyFields'}
                </div>
index be6cacd5f605a7aff3a29412a4f7036d3495080f..99bfff286fb3674d20d41b154e7f4cbd3a390b53 100755 (executable)
@@ -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
+               ]);
        }
 }
index b93aa1901bac8775f3c8d2ceecf37cd4a466de15..e22449749b14b9d218c1afc17088e40942e3e17a 100644 (file)
@@ -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 {
        /**
index fd7e7dc82f88b2e538e48494d5a041438f22a2cf..03fa2c072eb63ad145f51aa6c2afee06edcbd491 100644 (file)
@@ -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';
+       }
 }
index 862b5b9f27a0583cd0b64754da7a390de452230e..83d6e03a185e628cb1596d87dd2ee41f915b23d6 100644 (file)
@@ -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;
index c0f1ead99d92db59115ea04d9523b8a5147d02c5..36e9d835470ceb812c5c557b962a5079f1161d8c 100644 (file)
@@ -1610,6 +1610,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.pluginStore.authorization.username"><![CDATA[Benutzername]]></item>
                <item name="wcf.acp.pluginStore.authorization.password"><![CDATA[Passwort]]></item>
                <item name="wcf.acp.pluginStore.authorization.saveCredentials"><![CDATA[Zugangsdaten für aktuelle Sitzung speichern]]></item>
+               <item name="wcf.acp.pluginStore.file"><![CDATA[WoltLab® Plugin-Store]]></item>
+               <item name="wcf.acp.pluginStore.file.link"><![CDATA[Eintrag im Plugin-Store anzeigen]]></item>
                <item name="wcf.acp.pluginStore.purchasedItems.button.search"><![CDATA[Erworbene Produkte (Plugin-Store)]]></item>
                <item name="wcf.acp.pluginStore.purchasedItems"><![CDATA[Erworbene Produkte (Plugin-Store)]]></item>
                <item name="wcf.acp.pluginStore.purchasedItems.noResults"><![CDATA[Die Suche ergab keine Treffer, entweder {if LANGUAGE_USE_INFORMAL_VARIANT}hast du{else}haben Sie{/if} noch keine Produkte erworben oder diese sind nicht kompatibel.]]></item>
index 5577dd038584467c50c712e685a1fdfb6cc6b2ec..39176eef21d7a410c93ad2494676d36c2dd982f3 100644 (file)
                <item name="wcf.acp.pluginStore.authorization.username"><![CDATA[Username]]></item>
                <item name="wcf.acp.pluginStore.authorization.password"><![CDATA[Password]]></item>
                <item name="wcf.acp.pluginStore.authorization.saveCredentials"><![CDATA[Save credentials for this session only]]></item>
+               <item name="wcf.acp.pluginStore.file"><![CDATA[WoltLab® Plugin-Store]]></item>
+               <item name="wcf.acp.pluginStore.file.link"><![CDATA[Show listing in the Plugin-Store]]></item>
                <item name="wcf.acp.pluginStore.purchasedItems.button.search"><![CDATA[Purchased Products (Plugin-Store)]]></item>
                <item name="wcf.acp.pluginStore.purchasedItems"><![CDATA[Purchased Products (Plugin-Store)]]></item>
                <item name="wcf.acp.pluginStore.purchasedItems.noResults"><![CDATA[The search returned no results, because either you have not purchased any products yet, or your purchases are not compatible with this version.]]></item>
index ed324aff9d2eed434299e723e757b30637aa113a..158327fca9a1487145820817cfb4fe3828743d2b 100644 (file)
@@ -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
 );