* 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
*/
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']);
// 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
$archive->getTar()->close();
// cache download in session
- PackageUpdateDispatcher::cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename);
+ PackageUpdateDispatcher::getInstance()->cacheDownload($package, $packageUpdateVersion['packageVersion'], $filename);
return $filename;
}
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;
* @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);
foreach ($updateServers as $updateServer) {
if ($updateServer->lastUpdateTime < TIME_NOW - 600) {
try {
- self::getPackageUpdateXML($updateServer);
+ $this->getPackageUpdateXML($updateServer);
}
catch (SystemException $e) {
// save error status
*
* @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;
}
// 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);
* @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);
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;
* @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' => '',
* @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();
* @param boolean $removeRequirements
* @return array
*/
- public static function getAvailableUpdates($removeRequirements = true) {
+ public function getAvailableUpdates($removeRequirements = true) {
$updates = array();
// get update server data
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']);
}
}
}
* @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
$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']]);
}
* @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);
}
* @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
* @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
* @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();