From: Alexander Ebert Date: Fri, 24 Feb 2012 14:04:05 +0000 (+0100) Subject: Fixed requirements detection during installation X-Git-Tag: 2.0.0_Beta_1~1309^2~6 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a1ece4d95a64b824af6ee588d6e21626a3f587b5;p=GitHub%2FWoltLab%2FWCF.git Fixed requirements detection during installation --- diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index c7253a7e71..e92e785f7b 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -167,6 +167,42 @@ class PackageInstallationDispatcher { protected function installPackage(array $nodeData) { $installationStep = new PackageInstallationStep(); + // check requirements + if (!empty($nodeData['requirements'])) { + foreach ($nodeData['requirements'] as $package => $requirementData) { + // get existing package + if ($requirementData['packageID']) { + $sql = "SELECT packageName, packageVersion + FROM wcf".WCF_N."_package + WHERE packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($requirementData['packageID'])); + } + else { + // try to find matching package + $sql = "SELECT packageName, packageVersion + FROM wcf".WCF_N."_package + WHERE package = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($package)); + } + $row = $statement->fetchArray(); + + // package is required but not available + if ($row === false) { + throw new SystemException("Package '".$package."' is required by '".$nodeData['packageName']."', but is neither installed nor shipped."); + } + + // check version requirements + if ($requirementData['minVersion']) { + if (Package::compareVersion($row['packageVersion'], $requirementData['minVersion']) < 0) { + throw new SystemException("Package '".$nodeData['packageName']."' requires the package '".$row['packageName']."' in version '".$requirementData['minVersion']."', but version '".$row['packageVersion']."'"); + } + } + } + } + unset($nodeData['requirements']); + if (!$this->queue->packageID) { // create package entry $package = PackageEditor::create($nodeData); diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php index 502e2eace7..8f641d0cb3 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php @@ -41,6 +41,12 @@ class PackageInstallationNodeBuilder { */ public $parentNode = ''; + /** + * list of requirements to be checked before package installation + * @var array + */ + public $requirements = array(); + /** * current sequence number within one node * @@ -397,7 +403,8 @@ class PackageInstallationNodeBuilder { 'author' => $this->installation->getArchive()->getAuthorInfo('author'), 'authorURL' => $this->installation->getArchive()->getAuthorInfo('authorURL') !== null ? $this->installation->getArchive()->getAuthorInfo('authorURL') : '', 'installDate' => TIME_NOW, - 'updateDate' => TIME_NOW + 'updateDate' => TIME_NOW, + 'requirements' => $this->requirements )) )); } @@ -414,25 +421,12 @@ class PackageInstallationNodeBuilder { $requiredPackages = $this->installation->getArchive()->getOpenRequirements(); foreach ($requiredPackages as $packageName => $package) { if (!isset($package['file'])) { - // package is installed but version does not match - if ($package['packageID']) { - // get package version - $sql = "SELECT packageVersion - FROM wcf".WCF_N."_package - WHERE packageID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($package['packageID'])); - $row = $statement->fetchArray(); - - throw new SystemException("Package '".$this->installation->getArchive()->getPackageInfo('packageName')."' requires the package '".$packageName."' in version '".$package['minversion']."', but '".$row['packageVersion']."' is installed."); - } - - // package is required but not installed - if (!$package['packageID']) { - throw new SystemException("Package '".$this->installation->getArchive()->getPackageInfo('packageName')."' requires the package '".$packageName."', but it is neither installed nor shipped."); - } + // requirements will be checked once package is about to be installed + $this->requirements[$packageName] = array( + 'minVersion' => (isset($package['minversion'])) ?: '', + 'packageID' => $package['packageID'] + ); - // ignore requirements which are not to be installed, but are already available continue; }