use wcf\data\package\Package;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\SystemException;
+use wcf\system\Regex;
use wcf\system\WCF;
use wcf\util\HTTPRequest;
use wcf\util\XML;
* Provides functions to manage package updates.
*
* @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
/**
* Refreshes the package database.
*
- * @param array $packageUpdateServerIDs
+ * @param array<integer> $packageUpdateServerIDs
*/
public static function refreshPackageDatabase(array $packageUpdateServerIDs = array()) {
// get update server data
$settings = array();
if ($authData) $settings['auth'] = $authData;
- $request = new HTTPRequest($updateServer->serverURL, $settings, array(
+ $postData = array(
'lastUpdateTime' => $updateServer->lastUpdateTime
- ));
+ );
+
+ // 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)) {
+ $postData['authCode'] = PACKAGE_SERVER_AUTH_CODE;
+ }
+
+ $request = new HTTPRequest($updateServer->serverURL, $settings, $postData);
try {
$request->execute();
protected static function parsePackageUpdateXMLBlock(\DOMXPath $xpath, \DOMNode $package) {
// define default values
$packageInfo = array(
- 'packageDescription' => '',
- 'isApplication' => 0,
- 'plugin' => '',
'author' => '',
'authorURL' => '',
+ 'isApplication' => 0,
+ 'packageDescription' => '',
'versions' => array()
);
case 'isapplication':
$packageInfo['isApplication'] = intval($element->nodeValue);
break;
-
- case 'plugin':
- $packageInfo['plugin'] = $element->nodeValue;
- break;
}
}
$elements = $xpath->query('./ns:versions/ns:version', $package);
foreach ($elements as $element) {
$versionNo = $element->getAttribute('name');
+ $packageInfo['versions'][$versionNo] = array(
+ 'isAccessible' => true
+ );
+
+ if ($element->hasAttribute('accessible') && $element->getAttribute('accessible') == 'false') {
+ $packageInfo['versions'][$versionNo]['accessible'] = false;
+ }
$children = $xpath->query('child::*', $element);
foreach ($children as $child) {
}
break;
+ case 'optionalpackages':
+ $packageInfo['versions'][$versionNo]['optionalPackages'] = array();
+
+ $optionalPackages = $xpath->query('child::*', $child);
+ foreach ($optionalPackages as $optionalPackage) {
+ $packageInfo['versions'][$versionNo]['optionalPackages'][] = $optionalPackage->nodeValue;
+ }
+ break;
+
case 'excludedpackages':
$excludedpackages = $xpath->query('child::*', $child);
- foreach ($excludedpackages as $excludedpackage) {
- $exclusion = $excludedpackage->nodeValue;
- $version = $excludedpackage->getAttribute('version');
+ foreach ($excludedpackages as $excludedPackage) {
+ $exclusion = $excludedPackage->nodeValue;
+ $version = $excludedPackage->getAttribute('version');
$packageInfo['versions'][$versionNo]['excludedPackages'][$exclusion] = array();
if (!empty($version)) {
}
}
break;
+
+ case 'license':
+ $packageInfo['versions'][$versionNo]['license'] = array(
+ 'license' => $child->nodeValue,
+ 'licenseURL' => ($child->hasAttribute('url') ? $child->getAttribute('url') : '')
+ );
+ break;
}
}
}
}
// insert updates
- $excludedPackagesParameters = $fromversionParameters = $insertParameters = array();
+ $excludedPackagesParameters = $fromversionParameters = $insertParameters = $optionalInserts = $requirementInserts = array();
foreach ($allNewPackages as $identifier => $packageData) {
if (isset($existingPackages[$identifier])) {
$packageUpdateID = $existingPackages[$identifier]->packageUpdateID;
'packageDescription' => $packageData['packageDescription'],
'author' => $packageData['author'],
'authorURL' => $packageData['authorURL'],
- 'isApplication' => $packageData['isApplication'],
- 'plugin' => $packageData['plugin']
+ 'isApplication' => $packageData['isApplication']
));
}
else {
'packageDescription' => $packageData['packageDescription'],
'author' => $packageData['author'],
'authorURL' => $packageData['authorURL'],
- 'isApplication' => $packageData['isApplication'],
- 'plugin' => $packageData['plugin']
+ 'isApplication' => $packageData['isApplication']
));
$packageUpdateID = $packageUpdate->packageUpdateID;
// update database entry
$versionEditor = new PackageUpdateVersionEditor($existingPackageVersions[$packageUpdateID][$packageVersion]);
$versionEditor->update(array(
- 'updateType' => $versionData['updateType'],
+ 'filename' => $packageFile,
+ 'isAccessible' => ($versionData['isAccessible'] ? 1 : 0),
+ 'license' => $versionData['license']['license'],
+ 'licenseURL' => $versionData['license']['licenseURL'],
'packageDate' => $versionData['packageDate'],
- 'filename' => $packageFile
+ 'updateType' => $versionData['updateType']
));
}
else {
// create new database entry
$version = PackageUpdateVersionEditor::create(array(
+ 'filename' => $packageFile,
+ 'license' => $versionData['license']['license'],
+ 'licenseURL' => $versionData['license']['licenseURL'],
+ 'isAccessible' => ($versionData['isAccessible'] ? 1 : 0),
+ 'packageDate' => $versionData['packageDate'],
'packageUpdateID' => $packageUpdateID,
'packageVersion' => $packageVersion,
- 'updateType' => $versionData['updateType'],
- 'packageDate' => $versionData['packageDate'],
- 'filename' => $packageFile
+ 'updateType' => $versionData['updateType']
));
$packageUpdateVersionID = $version->packageUpdateVersionID;
}
}
+ // register optional packages of this update package version
+ if (isset($versionData['optionalPackages'])) {
+ foreach ($versionData['optionalPackages'] as $optionalPackage) {
+ $optionalInserts[] = array(
+ 'packageUpdateVersionID' => $packageUpdateVersionID,
+ 'package' => $optionalPackage
+ );
+ }
+ }
+
// register excluded packages of this update package version.
if (isset($versionData['excludedPackages'])) {
foreach ($versionData['excludedPackages'] as $excludedIdentifier => $exclusion) {
}
}
+ if (!empty($optionalInserts)) {
+ // clear records
+ $sql = "DELETE puo FROM wcf".WCF_N."_package_update_optional puo
+ LEFT JOIN wcf".WCF_N."_package_update_version puv
+ ON (puv.packageUpdateVersionID = puo.packageUpdateVersionID)
+ LEFT JOIN wcf".WCF_N."_package_update pu
+ ON (pu.packageUpdateID = puv.packageUpdateID)
+ WHERE pu.packageUpdateServerID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($packageUpdateServerID));
+
+ // insert requirements
+ $sql = "INSERT INTO wcf".WCF_N."_package_update_optional
+ (packageUpdateVersionID, package)
+ VALUES (?, ?, ?)";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ foreach ($requirementInserts as $requirement) {
+ $statement->execute(array(
+ $requirement['packageUpdateVersionID'],
+ $requirement['package']
+ ));
+ }
+ }
+
if (!empty($excludedPackagesParameters)) {
// clear records
$sql = "DELETE pue FROM wcf".WCF_N."_package_update_exclusion pue
packageDescription VARCHAR(255) NOT NULL DEFAULT '',
author VARCHAR(255) NOT NULL DEFAULT '',
authorURL VARCHAR(255) NOT NULL DEFAULT '',
- isApplication TINYINT(1) NOT NULL DEFAULT 0,
- plugin VARCHAR(255) NOT NULL DEFAULT '',
+ isApplication TINYINT(1) NOT NULL DEFAULT 0
UNIQUE KEY packageUpdateServerID (packageUpdateServerID, package)
);
UNIQUE KEY packageUpdateVersionID (packageUpdateVersionID, fromversion)
);
+DROP TABLE IF EXISTS wcf1_package_update_optional;
+CREATE TABLE wcf1_package_update_optional (
+ packageUpdateVersionID INT(10) NOT NULL DEFAULT 0,
+ package VARCHAR(255) NOT NULL DEFAULT ''
+);
+
DROP TABLE IF EXISTS wcf1_package_update_requirement;
CREATE TABLE wcf1_package_update_requirement (
packageUpdateVersionID INT(10) NOT NULL,
updateType VARCHAR(10) NOT NULL DEFAULT '',
packageDate INT(10) NOT NULL DEFAULT 0,
filename VARCHAR(255) NOT NULL DEFAULT '',
+ license VARCHAR(255) NOT NULL DEFAULT '',
+ licenseURL VARCHAR(255) NOT NULL DEFAULT '',
+ accessible TINYINT(1) NOT NULL DEFAULT 1,
UNIQUE KEY packageUpdateID (packageUpdateID, packageVersion)
);