From 3262b692fb8b2f5d6e5b1c5cd7c2b998277f1263 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 19 Mar 2018 17:09:58 +0100 Subject: [PATCH] Prevent packages being installed more than once --- .../PackageValidationArchive.class.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php b/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php index ee17009f02..e1420c49e2 100644 --- a/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php +++ b/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php @@ -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; -- 2.20.1