From f216b8291b8cfdb996dd1ae4a257090e58e8f591 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 25 May 2014 23:48:59 +0200 Subject: [PATCH] Purging package update database prior to inserting package list I don't really get why this wasn't done like that initially, I mean there is no point in _not_ deleting it. Weird. --- .../package/PackageUpdateDispatcher.class.php | 117 +++++------------- 1 file changed, 29 insertions(+), 88 deletions(-) diff --git a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php index 5f5aa1979c..fb35a1602c 100644 --- a/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php @@ -283,69 +283,26 @@ class PackageUpdateDispatcher extends SingletonFactory { * @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'])) { @@ -353,35 +310,19 @@ class PackageUpdateDispatcher extends SingletonFactory { 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'])) { -- 2.20.1