* @param integer $packageUpdateServerID
*/
protected function savePackageUpdates(array &$allNewPackages, $packageUpdateServerID) {
- // find existing packages and delete them
- // get existing packages
- $existingPackages = array();
- $packageUpdateList = new PackageUpdateList();
- $packageUpdateList->getConditionBuilder()->add("package_update.packageUpdateServerID = ? AND package_update.package IN (?)", array($packageUpdateServerID, array_keys($allNewPackages)));
- $packageUpdateList->readObjects();
- $tmp = $packageUpdateList->getObjects();
-
- foreach ($tmp as $packageUpdate) {
- $existingPackages[$packageUpdate->package] = $packageUpdate;
- }
-
- // get existing versions
- $existingPackageVersions = array();
- if (!empty($existingPackages)) {
- // get package update ids
- $packageUpdateIDs = array();
- foreach ($existingPackages as $packageUpdate) {
- $packageUpdateIDs[] = $packageUpdate->packageUpdateID;
- }
-
- // get version list
- $versionList = new PackageUpdateVersionList();
- $versionList->getConditionBuilder()->add("package_update_version.packageUpdateID IN (?)", array($packageUpdateIDs));
- $versionList->readObjects();
- $tmp = $versionList->getObjects();
-
- foreach ($tmp as $version) {
- if (!isset($existingPackageVersions[$version->packageUpdateID])) $existingPackageVersions[$version->packageUpdateID] = array();
- $existingPackageVersions[$version->packageUpdateID][$version->packageVersion] = $version;
- }
- }
+ $sql = "DELETE FROM wcf".WCF_N."_package_update
+ WHERE packageUpdateServerID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($packageUpdateServerID));
// insert updates
$excludedPackagesParameters = $fromversionParameters = $insertParameters = $optionalInserts = $requirementInserts = array();
foreach ($allNewPackages as $identifier => $packageData) {
- if (isset($existingPackages[$identifier])) {
- $packageUpdateID = $existingPackages[$identifier]->packageUpdateID;
-
- // update database entry
- $packageUpdateEditor = new PackageUpdateEditor($existingPackages[$identifier]);
- $packageUpdateEditor->update(array(
- 'packageName' => $packageData['packageName'],
- 'packageDescription' => $packageData['packageDescription'],
- 'author' => $packageData['author'],
- 'authorURL' => $packageData['authorURL'],
- 'isApplication' => $packageData['isApplication']
- ));
- }
- else {
- // create new database entry
- $packageUpdate = PackageUpdateEditor::create(array(
- 'packageUpdateServerID' => $packageUpdateServerID,
- 'package' => $identifier,
- 'packageName' => $packageData['packageName'],
- 'packageDescription' => $packageData['packageDescription'],
- 'author' => $packageData['author'],
- 'authorURL' => $packageData['authorURL'],
- 'isApplication' => $packageData['isApplication']
- ));
-
- $packageUpdateID = $packageUpdate->packageUpdateID;
- }
+ // create new database entry
+ $packageUpdate = PackageUpdateEditor::create(array(
+ 'packageUpdateServerID' => $packageUpdateServerID,
+ 'package' => $identifier,
+ 'packageName' => $packageData['packageName'],
+ 'packageDescription' => $packageData['packageDescription'],
+ 'author' => $packageData['author'],
+ 'authorURL' => $packageData['authorURL'],
+ 'isApplication' => $packageData['isApplication']
+ ));
+
+ $packageUpdateID = $packageUpdate->packageUpdateID;
// register version(s) of this update package.
if (isset($packageData['versions'])) {
if (isset($versionData['file'])) $packageFile = $versionData['file'];
else $packageFile = '';
- if (isset($existingPackageVersions[$packageUpdateID]) && isset($existingPackageVersions[$packageUpdateID][$packageVersion])) {
- $packageUpdateVersionID = $existingPackageVersions[$packageUpdateID][$packageVersion]->packageUpdateVersionID;
-
- // update database entry
- $versionEditor = new PackageUpdateVersionEditor($existingPackageVersions[$packageUpdateID][$packageVersion]);
- $versionEditor->update(array(
- 'filename' => $packageFile,
- 'isAccessible' => ($versionData['isAccessible'] ? 1 : 0),
- 'isCritical' => ($versionData['isCritical'] ? 1 : 0),
- 'license' => (isset($versionData['license']['license']) ? $versionData['license']['license'] : ''),
- 'licenseURL' => (isset($versionData['license']['license']) ? $versionData['license']['licenseURL'] : ''),
- 'packageDate' => $versionData['packageDate']
- ));
- }
- else {
- // create new database entry
- $version = PackageUpdateVersionEditor::create(array(
- 'filename' => $packageFile,
- 'license' => (isset($versionData['license']['license']) ? $versionData['license']['license'] : ''),
- 'licenseURL' => (isset($versionData['license']['license']) ? $versionData['license']['licenseURL'] : ''),
- 'isAccessible' => ($versionData['isAccessible'] ? 1 : 0),
- 'isCritical' => ($versionData['isCritical'] ? 1 : 0),
- 'packageDate' => $versionData['packageDate'],
- 'packageUpdateID' => $packageUpdateID,
- 'packageVersion' => $packageVersion
- ));
-
- $packageUpdateVersionID = $version->packageUpdateVersionID;
- }
+ // create new database entry
+ $version = PackageUpdateVersionEditor::create(array(
+ 'filename' => $packageFile,
+ 'license' => (isset($versionData['license']['license']) ? $versionData['license']['license'] : ''),
+ 'licenseURL' => (isset($versionData['license']['license']) ? $versionData['license']['licenseURL'] : ''),
+ 'isAccessible' => ($versionData['isAccessible'] ? 1 : 0),
+ 'isCritical' => ($versionData['isCritical'] ? 1 : 0),
+ 'packageDate' => $versionData['packageDate'],
+ 'packageUpdateID' => $packageUpdateID,
+ 'packageVersion' => $packageVersion
+ ));
+
+ $packageUpdateVersionID = $version->packageUpdateVersionID;
// register requirement(s) of this update package version.
if (isset($versionData['requiredPackages'])) {