PackageUpdateDispatcher is now a SingletonFactory
authorAlexander Ebert <ebert@woltlab.com>
Mon, 14 Jan 2013 19:15:56 +0000 (20:15 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 14 Jan 2013 19:15:56 +0000 (20:15 +0100)
wcfsetup/install/files/lib/acp/form/PackageUpdateForm.class.php
wcfsetup/install/files/lib/acp/form/PackageUpdateSearchForm.class.php
wcfsetup/install/files/lib/acp/page/PackageAutoUpdateListPage.class.php
wcfsetup/install/files/lib/system/cronjob/GetUpdateInfoCronjob.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationScheduler.class.php
wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php

index 5dabb65533d4fc56b45a509905924b4eac7a90d6..e114c4e86010030c83e8e2ebcb33ba216a8fdcee 100755 (executable)
@@ -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();
index 5a1bd266c21f18d6ab439218bdad2c11bb849df3..35cc9d111392fb40199886732bd9b8bc9f530de0 100644 (file)
@@ -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();
index a7ac55ba06627407568fe966eda51e5073a03039..154385594e834accefcfb9c6881e89609cf1db3b 100755 (executable)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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();
        }
        
        /**
index cb595c1047d1db26a7f4823cfa6728f635fcf95b..84b2da4644dd8a583550b069593ae413a83bd351 100644 (file)
@@ -1,13 +1,12 @@
 <?php
 namespace wcf\system\cronjob;
-use wcf\data\cronjob\Cronjob;
 use wcf\system\package\PackageUpdateDispatcher;
 
 /**
  * Gets update package information.
  * 
- * @author     Siegfried Schweizer
- * @copyright  2001-2012 WoltLab GmbH
+ * @author     Alexander Ebert
+ * @copyright  2001-2013 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @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();
        }
 }
index f3f953430178406c082c17c7282c5b861b266e79..c41add9e167fe2da040c0474e82454196d942412 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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;
                        }
index a40ea3f2bec0e2c66a62e9f5f216b293b8d60eb5..bb17c2ce30c590c7e385a60a10114800cad7bcd9 100644 (file)
@@ -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<integer>          $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();