From bfb9ac09aa7ddb37389fb9efd9156be3ae106c91 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 13 Apr 2021 17:06:56 +0200 Subject: [PATCH] Only create one `DevtoolsPackageArchive` object in `DevtoolsProject` --- .../project/DevtoolsProject.class.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/data/devtools/project/DevtoolsProject.class.php b/wcfsetup/install/files/lib/data/devtools/project/DevtoolsProject.class.php index f6164a63d9..3c4f41c472 100644 --- a/wcfsetup/install/files/lib/data/devtools/project/DevtoolsProject.class.php +++ b/wcfsetup/install/files/lib/data/devtools/project/DevtoolsProject.class.php @@ -50,6 +50,12 @@ class DevtoolsProject extends DatabaseObject */ protected $packageArchive; + /** + * @var PackageValidationException + * @since 5.4 + */ + protected $packageValidationException; + /** * Returns a list of decorated PIPs. * @@ -123,12 +129,11 @@ class DevtoolsProject extends DatabaseObject */ public function validatePackageXml() { - $packageXml = $this->getPackageXmlPath(); - $this->packageArchive = new DevtoolsPackageArchive($packageXml); - try { - $this->packageArchive->openArchive(); - } catch (PackageValidationException $e) { - return $e->getErrorMessage(); + // Make sure that the package archive is read and any validation exception while opening the + // archive is caught. + $this->getPackageArchive(); + if ($this->packageValidationException) { + return $this->packageValidationException->getErrorMessage(); } if ($this->getPackage() === null) { @@ -180,13 +185,12 @@ class DevtoolsProject extends DatabaseObject public function getPackageArchive() { if ($this->packageArchive === null) { - $this->packageArchive = new DevtoolsPackageArchive($this->path . ($this->isCore() ? 'com.woltlab.wcf/' : '') . 'package.xml'); + $this->packageArchive = new DevtoolsPackageArchive($this->getPackageXmlPath()); try { $this->packageArchive->openArchive(); } catch (PackageValidationException $e) { - // we do not care for errors here, `validatePackageXml()` - // takes care of that + $this->packageValidationException = $e; } } -- 2.20.1