From adf0710fb683fe6aa589b7d9bb2940ff2b07bc4a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 14 Jan 2013 20:15:56 +0100 Subject: [PATCH] PackageUpdateDispatcher is now a SingletonFactory --- .../lib/acp/form/PackageUpdateForm.class.php | 2 +- .../form/PackageUpdateSearchForm.class.php | 2 +- .../page/PackageAutoUpdateListPage.class.php | 6 +-- .../cronjob/GetUpdateInfoCronjob.class.php | 8 ++-- .../PackageInstallationScheduler.class.php | 10 ++--- .../package/PackageUpdateDispatcher.class.php | 39 ++++++++++--------- 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php index 5dabb65533..e114c4e860 100755 --- a/wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php @@ -73,7 +73,7 @@ class PackageUpdateForm extends AbstractForm { } // build update stack - $this->packageUpdate = PackageUpdateDispatcher::prepareInstallation($this->updates, array(), isset($_POST['send'])); + $this->packageUpdate = PackageUpdateDispatcher::getInstance()->prepareInstallation($this->updates, array(), isset($_POST['send'])); try { $this->packageUpdate->buildPackageInstallationStack(); $this->excludedPackages = $this->packageUpdate->getExcludedPackages(); diff --git a/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php b/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php index 5a1bd266c2..35cc9d1113 100644 --- a/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php @@ -111,7 +111,7 @@ class PackageUpdateSearchForm extends AbstractForm { parent::validate(); // refresh package database - PackageUpdateDispatcher::refreshPackageDatabase($this->packageUpdateServerIDs); + PackageUpdateDispatcher::getInstance()->refreshPackageDatabase($this->packageUpdateServerIDs); // build conditions $conditions = new PreparedStatementConditionBuilder(); diff --git a/wcfsetup/install/files/lib/acp/page/PackageAutoUpdateListPage.class.php b/wcfsetup/install/files/lib/acp/page/PackageAutoUpdateListPage.class.php index a7ac55ba06..154385594e 100755 --- a/wcfsetup/install/files/lib/acp/page/PackageAutoUpdateListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/PackageAutoUpdateListPage.class.php @@ -9,7 +9,7 @@ use wcf\system\WCFACP; * Shows the list of available updates for installed packages. * * @author Marcel Werk - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage acp.page @@ -40,11 +40,11 @@ class PackageAutoUpdateListPage extends AbstractPage { if (empty($_POST)) { // refresh package database - PackageUpdateDispatcher::refreshPackageDatabase(); + PackageUpdateDispatcher::getInstance()->refreshPackageDatabase(); } // get updatable packages - $this->availableUpdates = PackageUpdateDispatcher::getAvailableUpdates(); + $this->availableUpdates = PackageUpdateDispatcher::getInstance()->getAvailableUpdates(); } /** diff --git a/wcfsetup/install/files/lib/system/cronjob/GetUpdateInfoCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/GetUpdateInfoCronjob.class.php index cb595c1047..84b2da4644 100644 --- a/wcfsetup/install/files/lib/system/cronjob/GetUpdateInfoCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/GetUpdateInfoCronjob.class.php @@ -1,13 +1,12 @@ * @package com.woltlab.wcf * @subpackage system.cronjob @@ -18,7 +17,6 @@ class GetUpdateInfoCronjob implements ICronjob { * @see wcf\system\ICronjob::execute() */ public function execute(Cronjob $cronjob) { - // TODO - PackageUpdateDispatcher::refreshPackageDatabase(); + PackageUpdateDispatcher::getInstance()->refreshPackageDatabase(); } } diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php index f3f9534301..c41add9e16 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php @@ -12,7 +12,7 @@ use wcf\util\FileUtil; * Contains business logic related to preparation of package installations. * * @author Alexander Ebert - * @copyright 2001-2012 WoltLab GmbH + * @copyright 2001-2013 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.package @@ -115,7 +115,7 @@ class PackageInstallationScheduler { */ protected function installPackage($package, $version = '', $stackPosition = -1) { // get package update versions - $packageUpdateVersions = PackageUpdateDispatcher::getPackageUpdateVersions($package, $version); + $packageUpdateVersions = PackageUpdateDispatcher::getInstance()->getPackageUpdateVersions($package, $version); // resolve requirements $this->resolveRequirements($packageUpdateVersions[0]['packageUpdateVersionID']); @@ -225,10 +225,10 @@ class PackageInstallationScheduler { // send request // TODO: Use HTTPRequest if (!empty($packageUpdateVersion['file'])) { - $response = PackageUpdateDispatcher::sendRequest($packageUpdateVersion['file'], array(), $authData); + $response = PackageUpdateDispatcher::getInstance()->sendRequest($packageUpdateVersion['file'], array(), $authData); } else { - $response = PackageUpdateDispatcher::sendRequest($packageUpdateVersion['server'], array('packageName' => $packageUpdateVersion['package'], 'packageVersion' => $packageUpdateVersion['packageVersion']), $authData); + $response = PackageUpdateDispatcher::getInstance()->sendRequest($packageUpdateVersion['server'], array('packageName' => $packageUpdateVersion['package'], 'packageVersion' => $packageUpdateVersion['packageVersion']), $authData); } // check response @@ -254,7 +254,7 @@ class PackageInstallationScheduler { $archive->getTar()->close(); // cache download in session - PackageUpdateDispatcher::cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename); + PackageUpdateDispatcher::getInstance()->cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename); return $filename; } diff --git a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php index a40ea3f2be..bb17c2ce30 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php @@ -10,6 +10,7 @@ use wcf\data\package\Package; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\SystemException; use wcf\system\Regex; +use wcf\system\SingletonFactory; use wcf\system\WCF; use wcf\util\HTTPRequest; use wcf\util\XML; @@ -24,13 +25,13 @@ use wcf\util\XML; * @subpackage system.package * @category Community Framework */ -abstract class PackageUpdateDispatcher { +class PackageUpdateDispatcher extends SingletonFactory { /** * Refreshes the package database. * * @param array $packageUpdateServerIDs */ - public static function refreshPackageDatabase(array $packageUpdateServerIDs = array()) { + public function refreshPackageDatabase(array $packageUpdateServerIDs = array()) { // get update server data $updateServers = PackageUpdateServer::getActiveUpdateServers($packageUpdateServerIDs); @@ -38,7 +39,7 @@ abstract class PackageUpdateDispatcher { foreach ($updateServers as $updateServer) { if ($updateServer->lastUpdateTime < TIME_NOW - 600) { try { - self::getPackageUpdateXML($updateServer); + $this->getPackageUpdateXML($updateServer); } catch (SystemException $e) { // save error status @@ -57,7 +58,7 @@ abstract class PackageUpdateDispatcher { * * @param wcf\data\package\update\server\PackageUpdateServer $updateServer */ - protected static function getPackageUpdateXML(PackageUpdateServer $updateServer) { + protected function getPackageUpdateXML(PackageUpdateServer $updateServer) { $authData = $updateServer->getAuthData(); $settings = array(); if ($authData) $settings['auth'] = $authData; @@ -88,12 +89,12 @@ abstract class PackageUpdateDispatcher { } // parse given package update xml - $allNewPackages = self::parsePackageUpdateXML($reply['body']); + $allNewPackages = $this->parsePackageUpdateXML($reply['body']); unset($request, $reply); // save packages if (!empty($allNewPackages)) { - self::savePackageUpdates($allNewPackages, $updateServer->packageUpdateServerID); + $this->savePackageUpdates($allNewPackages, $updateServer->packageUpdateServerID); } unset($allNewPackages); @@ -112,7 +113,7 @@ abstract class PackageUpdateDispatcher { * @param string $content * @return array $allNewPackages */ - protected static function parsePackageUpdateXML($content) { + protected function parsePackageUpdateXML($content) { // load xml document $xml = new XML(); $xml->loadXML('packageUpdateServer.xml', $content); @@ -126,7 +127,7 @@ abstract class PackageUpdateDispatcher { throw new SystemException("'".$package->getAttribute('name')."' is not a valid package name."); } - $allNewPackages[$package->getAttribute('name')] = self::parsePackageUpdateXMLBlock($xpath, $package); + $allNewPackages[$package->getAttribute('name')] = $this->parsePackageUpdateXMLBlock($xpath, $package); } return $allNewPackages; @@ -138,7 +139,7 @@ abstract class PackageUpdateDispatcher { * @param \DOMXPath $xpath * @param \DOMNode $package */ - protected static function parsePackageUpdateXMLBlock(\DOMXPath $xpath, \DOMNode $package) { + protected function parsePackageUpdateXMLBlock(\DOMXPath $xpath, \DOMNode $package) { // define default values $packageInfo = array( 'author' => '', @@ -268,7 +269,7 @@ abstract class PackageUpdateDispatcher { * @param array $allNewPackages * @param integer $packageUpdateServerID */ - protected static function savePackageUpdates(array &$allNewPackages, $packageUpdateServerID) { + protected function savePackageUpdates(array &$allNewPackages, $packageUpdateServerID) { // find existing packages and delete them // get existing packages $existingPackages = array(); @@ -523,7 +524,7 @@ abstract class PackageUpdateDispatcher { * @param boolean $removeRequirements * @return array */ - public static function getAvailableUpdates($removeRequirements = true) { + public function getAvailableUpdates($removeRequirements = true) { $updates = array(); // get update server data @@ -599,7 +600,7 @@ abstract class PackageUpdateDispatcher { foreach ($existingPackages as $identifier => $instances) { foreach ($instances as $instance) { if ($instance['isApplication'] && isset($updates[$instance['packageID']])) { - $updates = self::removeUpdateRequirements($updates, $updates[$instance['packageID']]['version']['servers'][0]['packageUpdateVersionID']); + $updates = $this->removeUpdateRequirements($updates, $updates[$instance['packageID']]['version']['servers'][0]['packageUpdateVersionID']); } } } @@ -615,7 +616,7 @@ abstract class PackageUpdateDispatcher { * @param integer $packageUpdateVersionID * @return array $updates */ - protected static function removeUpdateRequirements(array $updates, $packageUpdateVersionID) { + protected function removeUpdateRequirements(array $updates, $packageUpdateVersionID) { $sql = "SELECT pur.package, pur.minversion, p.packageID FROM wcf".WCF_N."_package_update_requirement pur LEFT JOIN wcf".WCF_N."_package p @@ -625,7 +626,7 @@ abstract class PackageUpdateDispatcher { $statement->execute(array($packageUpdateVersionID)); while ($row = $statement->fetchArray()) { if (isset($updates[$row['packageID']])) { - $updates = self::removeUpdateRequirements($updates, $updates[$row['packageID']]['version']['servers'][0]['packageUpdateVersionID']); + $updates = $this->removeUpdateRequirements($updates, $updates[$row['packageID']]['version']['servers'][0]['packageUpdateVersionID']); if (Package::compareVersion($row['minversion'], $updates[$row['packageID']]['version']['packageVersion'], '>=')) { unset($updates[$row['packageID']]); } @@ -643,7 +644,7 @@ abstract class PackageUpdateDispatcher { * @param boolean $download * @return wcf\system\package\PackageInstallationScheduler */ - public static function prepareInstallation(array $selectedPackages, array $packageUpdateServerIDs = array(), $download = true) { + public function prepareInstallation(array $selectedPackages, array $packageUpdateServerIDs = array(), $download = true) { return new PackageInstallationScheduler($selectedPackages, $packageUpdateServerIDs, $download); } @@ -654,10 +655,10 @@ abstract class PackageUpdateDispatcher { * @param string $version package version * @return array package update versions */ - public static function getPackageUpdateVersions($package, $version = '') { + public function getPackageUpdateVersions($package, $version = '') { // get newest package version if (empty($version)) { - $version = self::getNewestPackageVersion($package); + $version = $this->getNewestPackageVersion($package); } // get versions @@ -692,7 +693,7 @@ abstract class PackageUpdateDispatcher { * @param string $package package identifier * @return string newest package version */ - public static function getNewestPackageVersion($package) { + public function getNewestPackageVersion($package) { // get all versions $versions = array(); $sql = "SELECT packageVersion @@ -722,7 +723,7 @@ abstract class PackageUpdateDispatcher { * @param string $version package version * @param string $filename */ - public static function cacheDownload($package, $version, $filename) { + public function cacheDownload($package, $version, $filename) { $cachedDownloads = WCF::getSession()->getVar('cachedPackageUpdateDownloads'); if (!is_array($cachedDownloads)) { $cachedDownloads = array(); -- 2.20.1