Prevent packages being installed more than once
authorAlexander Ebert <ebert@woltlab.com>
Mon, 19 Mar 2018 16:09:58 +0000 (17:09 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 19 Mar 2018 16:09:58 +0000 (17:09 +0100)
wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php

index ee17009f02c786e1ee4ffa5d6af5794e471968d6..e1420c49e227cf00e6f1d6c5fc6bcf20c3eb68c1 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\system\package\validation;
 use wcf\data\package\Package;
 use wcf\data\package\PackageCache;
+use wcf\data\package\PackageList;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\package\PackageArchive;
 use wcf\system\WCF;
@@ -373,7 +374,23 @@ class PackageValidationArchive implements \RecursiveIterator {
         */
        public function getPackage() {
                if ($this->package === null) {
-                       $this->package = PackageCache::getInstance()->getPackageByIdentifier($this->archive->getPackageInfo('name'));
+                       static $packages;
+                       if ($packages === null) {
+                               $packages = [];
+                               
+                               // Do not rely on PackageCache here, it may be outdated if a previous installation of a package has failed
+                               // and the user attempts to install it again in a secondary browser tab!
+                               $packageList = new PackageList();
+                               $packageList->readObjects();
+                               foreach ($packageList as $package) {
+                                       $packages[$package->package] = $package;
+                               }
+                       }
+                       
+                       $identifier = $this->archive->getPackageInfo('name');
+                       if (isset($packages[$identifier])) {
+                               $this->package = $packages[$identifier];
+                       }
                }
                
                return $this->package;