From: Alexander Ebert Date: Sun, 21 Dec 2014 18:08:26 +0000 (+0100) Subject: Updated implementation for package update servers X-Git-Tag: 2.1.0_Beta_3~98 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2c49099b9b194ce688a660d0f55e048a6d05da8d;p=GitHub%2FWoltLab%2FWCF.git Updated implementation for package update servers --- 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 f6ec7196bc..9542942612 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 @@ -3,6 +3,8 @@ namespace wcf\data\package\update\server; use wcf\data\DatabaseObject; use wcf\system\Regex; use wcf\system\WCF; +use wcf\util\FileUtil; +use wcf\system\io\RemoteFile; /** * Represents a package update server. @@ -135,4 +137,26 @@ class PackageUpdateServer extends DatabaseObject { $host = parse_url($this->serverURL, PHP_URL_HOST); return str_replace($host, ''.$host.'', $this->serverURL); } + + /** + * Returns the list URL for package servers. + * + * @return string + */ + public function getListURL() { + if ($this->apiVersion == '2.0') { + return $this->serverURL; + } + + $serverURL = FileUtil::addTrailingSlash($this->serverURL) . 'list/' . WCF::getLanguage()->getFixedLanguageCode() . '.xml'; + $serverURL = preg_replace_callback('~^https?://~', function($matches) { + if (RemoteFile::supportsSSL()) { + return 'https://'; + } + + return 'http://'; + }, $serverURL); + + return $serverURL; + } } diff --git a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php index 8b62682173..31bd9afc45 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php @@ -78,21 +78,18 @@ class PackageUpdateDispatcher extends SingletonFactory { * @param \wcf\data\package\update\server\PackageUpdateServer $updateServer */ protected function getPackageUpdateXML(PackageUpdateServer $updateServer) { - $authData = $updateServer->getAuthData(); $settings = array(); - if ($authData) $settings['auth'] = $authData; - - $postData = array( - 'apiVersion' => PackageUpdate::API_VERSION, - 'lastUpdateTime' => $updateServer->lastUpdateTime - ); + if ($updateServer->apiVersion == '2.0') { + $authData = $updateServer->getAuthData(); + if ($authData) $settings['auth'] = $authData; + } // append auth code if set and update server resolves to woltlab.com - if (PACKAGE_SERVER_AUTH_CODE && Regex::compile('^https?://[a-z]+.woltlab.com/')->match($updateServer->serverURL)) { + /*if (PACKAGE_SERVER_AUTH_CODE && Regex::compile('^https?://[a-z]+.woltlab.com/')->match($updateServer->serverURL)) { $postData['authCode'] = PACKAGE_SERVER_AUTH_CODE; - } + }*/ - $request = new HTTPRequest($updateServer->serverURL, $settings, $postData); + $request = new HTTPRequest($updateServer->getListURL(), $settings); try { $request->execute(); @@ -109,43 +106,66 @@ class PackageUpdateDispatcher extends SingletonFactory { } // parse given package update xml - $allNewPackages = $this->parsePackageUpdateXML($reply['body']); - unset($request, $reply); + $allNewPackages = $this->parsePackageUpdateXML($updateServer, $reply['body']); - // purge package list - $sql = "DELETE FROM wcf".WCF_N."_package_update - WHERE packageUpdateServerID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($updateServer->packageUpdateServerID)); + $data = array( + 'lastUpdateTime' => TIME_NOW, + 'status' => 'online', + 'errorMessage' => '' + ); + + // check if server indicates support for a newer API + if ($updateServer->apiVersion == '2.0' && !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'; + } + } - // save packages - if (!empty($allNewPackages)) { - $this->savePackageUpdates($allNewPackages, $updateServer->packageUpdateServerID); + unset($request, $reply); + + if ($allNewPackages !== false) { + // purge package list + $sql = "DELETE FROM wcf".WCF_N."_package_update + WHERE packageUpdateServerID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($updateServer->packageUpdateServerID)); + + // save packages + if (!empty($allNewPackages)) { + $this->savePackageUpdates($allNewPackages, $updateServer->packageUpdateServerID); + } + unset($allNewPackages); } - unset($allNewPackages); // update server status $updateServerEditor = new PackageUpdateServerEditor($updateServer); - $updateServerEditor->update(array( - 'lastUpdateTime' => TIME_NOW, - 'status' => 'online', - 'errorMessage' => '' - )); + $updateServerEditor->update($data); } /** - * Parses a stream containing info from a packages_update.xml. + * Parses a stream containing info from a packages_update.xml, returns false if package list + * has not changed since last update. * - * @param string $content - * @return array $allNewPackages + * @param \wcf\data\package\update\server\PackageUpdateServer $updateServer + * @param string $content + * @return array $allNewPackages */ - protected function parsePackageUpdateXML($content) { + protected function parsePackageUpdateXML(PackageUpdateServer $updateServer, $content) { // load xml document $xml = new XML(); $xml->loadXML('packageUpdateServer.xml', $content); $xpath = $xml->xpath(); // loop through tags inside the
tag. + $section = $xpath->query('/ns:section'); + if ($section->item(0)->hasAttribute('lastUpdateTime')) { + $lastUpdateTime = intval($section->item(0)->getAttribute('lastUpdateTime')); + if ($lastUpdateTime && $updateServer->lastUpdateTime > $lastUpdateTime) { + return false; + } + } + $allNewPackages = array(); $packages = $xpath->query('/ns:section/ns:package'); foreach ($packages as $package) { diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 5684f29ca3..e951c2f207 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -759,7 +759,8 @@ CREATE TABLE wcf1_package_update_server ( isDisabled TINYINT(1) NOT NULL DEFAULT 0, lastUpdateTime INT(10) NOT NULL DEFAULT 0, status ENUM('online', 'offline') NOT NULL DEFAULT 'online', - errorMessage TEXT + errorMessage TEXT, + apiVersion ENUM('2.0', '2.1') NOT NULL DEFAULT '2.0' ); DROP TABLE IF EXISTS wcf1_package_update_version;