From: Alexander Ebert Date: Mon, 22 Sep 2014 16:08:36 +0000 (+0200) Subject: Restored PIP validation for WCF 2.1 X-Git-Tag: 2.1.0_Alpha_1~301 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9acbce07d0788a04c7836722b557320b1d5bf1c1;p=GitHub%2FWoltLab%2FWCF.git Restored PIP validation for WCF 2.1 --- 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 2b7186d699..d568c6084b 100644 --- a/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php +++ b/wcfsetup/install/files/lib/system/package/validation/PackageValidationArchive.class.php @@ -92,7 +92,7 @@ class PackageValidationArchive implements \RecursiveIterator { $this->archive->openArchive(); // check if package is installable or suitable for an update - $this->validateInstructions($requiredVersion); + $this->validateInstructions($requiredVersion, $validationMode); } catch (\Exception $e) { $this->exception = $e; @@ -184,8 +184,9 @@ class PackageValidationArchive implements \RecursiveIterator { * Validates if the package has suitable install or update instructions * * @param string $requiredVersion + * @param integer $validationMode */ - protected function validateInstructions($requiredVersion) { + protected function validateInstructions($requiredVersion, $validationMode) { $package = $this->getPackage(); // delivered package does not provide the minimum required version @@ -203,6 +204,10 @@ class PackageValidationArchive implements \RecursiveIterator { if (empty($instructions)) { throw new PackageValidationException(PackageValidationException::NO_INSTALL_PATH, array('packageName' => $this->archive->getPackageInfo('name'))); } + + if ($validationMode == PackageValidationManager::VALIDATION_RECURSIVE) { + $this->validatePackageInstallationPlugins('install', $instructions); + } } else { // package is already installed, check update path @@ -213,6 +218,29 @@ class PackageValidationArchive implements \RecursiveIterator { 'deliveredPackageVersion' => $this->archive->getPackageInfo('version') )); } + + if ($validationMode === PackageValidationManager::VALIDATION_RECURSIVE) { + $this->validatePackageInstallationPlugins('update', $this->archive->getUpdateInstructions()); + } + } + } + + /** + * Validates install or update instructions against the corresponding PIP, unknown PIPs will be silently ignored. + * + * @param string $type + * @param array $instructions + */ + protected function validatePackageInstallationPlugins($type, array $instructions) { + for ($i = 0, $length = count($instructions); $i < $length; $i++) { + $instruction = $instructions[$i]; + if (!PackageValidationManager::getInstance()->validatePackageInstallationPluginInstruction($this->archive, $instruction['pip'], $instruction['value'])) { + throw new PackageValidationException(PackageValidationException::MISSING_INSTRUCTION_FILE, array( + 'pip' => $instruction['pip'], + 'type' => $type, + 'value' => $instruction['value'] + )); + } } } diff --git a/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php b/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php index 7804873fb7..e0f19ab74f 100644 --- a/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php +++ b/wcfsetup/install/files/lib/system/package/validation/PackageValidationManager.class.php @@ -16,6 +16,12 @@ use wcf\system\SingletonFactory; * @category Community Framework */ class PackageValidationManager extends SingletonFactory { + /** + * list of known package installation plugins + * @var array + */ + protected $packageInstallationPlugins = array(); + /** * package validation archive object * @var \wcf\system\package\validation\PackageValidationArchive @@ -46,6 +52,17 @@ class PackageValidationManager extends SingletonFactory { */ const VALIDATION_EXCLUSION = 2; + /** + * @see \wcf\system\SingletonFactory::init() + */ + protected function init() { + $pipList = new PackageInstallationPluginList(); + $pipList->readObjects(); + foreach ($pipList as $pip) { + $this->packageInstallationPlugins[$pip->pluginName] = $pip->className; + } + } + /** * Validates given archive for existance and ability to be installed/updated. If you set the * second parameter $deepInspection to "false", the system will only check if the archive @@ -155,4 +172,22 @@ class PackageValidationManager extends SingletonFactory { return null; } + + /** + * Validates an instruction against the corresponding package installation plugin. + * + * Please be aware that unknown PIPs will silently ignored and cause no error. + * + * @param \wcf\data\package\PackageArchive $archive + * @param string $pip + * @param string $instruction + * @return boolean + */ + public function validatePackageInstallationPluginInstruction(PackageArchive $archive, $pip, $instruction) { + if (isset($this->packageInstallationPlugins[$pip])) { + return call_user_func(array($this->packageInstallationPlugins[$pip], 'isValid'), $archive, $instruction); + } + + return true; + } }