Purging package update database prior to inserting package list
authorAlexander Ebert <ebert@woltlab.com>
Sun, 25 May 2014 21:48:59 +0000 (23:48 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 25 May 2014 21:48:59 +0000 (23:48 +0200)
I don't really get why this wasn't done like that initially, I mean there is no point in _not_ deleting it. Weird.

wcfsetup/install/files/lib/system/package/PackageUpdateDispatcher.class.php

index 5f5aa1979c0f42267f6e8e503cfad63fda4658d3..fb35a1602cf375fd12869f70583400bb72275048 100644 (file)
@@ -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'])) {