From: Matthias Schmidt Date: Wed, 2 Jan 2013 13:29:13 +0000 (+0100) Subject: Fixes Package::getDependentPackages() X-Git-Tag: 2.0.0_Beta_1~606^2~4^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=38bbf0b4860340dbd5b3ff783c1649670ae24db0;p=GitHub%2FWoltLab%2FWCF.git Fixes Package::getDependentPackages() Also optimizes Package:: getRequiredPackages() --- diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index 4fbbe42417..f133fd82b5 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -25,6 +25,12 @@ class Package extends DatabaseObject { */ protected $dependencies = null; + /** + * list of packages that require this package + * @var array + */ + protected $dependentPackages = null; + /** * installation directory * @var string @@ -118,6 +124,7 @@ class Package extends DatabaseObject { */ public function getDependencies() { if ($this->dependencies === null) { + // todo throw new SystemException("Package::getDependencies()"); } @@ -125,24 +132,21 @@ class Package extends DatabaseObject { } /** - * Returns a list of the requirements of this package. - * Contains the content of the tag in the package.xml of this package. + * Returns the list of packages which are required by this package. The + * returned packages are the packages given in the tag + * in the package.xml of this package. * * @return array */ public function getRequiredPackages() { if ($this->requiredPackages === null) { - $this->requiredPackages = array(); + self::loadRequirements(); - $sql = "SELECT package.* - FROM wcf".WCF_N."_package_requirement package_requirement - LEFT JOIN wcf".WCF_N."_package package ON (package.packageID = package_requirement.requirement) - WHERE package_requirement.packageID = ? - ORDER BY packageName ASC"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($this->packageID)); - while ($package = $statement->fetchObject('wcf\data\package\Package')) { - $this->requiredPackages[$package->packageID] = $package; + $this->requiredPackages = array(); + if (isset(self::$requirements[$this->packageID])) { + foreach (self::$requirements[$this->packageID] as $packageID) { + $this->requiredPackages[$packageID] = PackageCache::getInstance()->getPackage($packageID); + } } } @@ -178,16 +182,18 @@ class Package extends DatabaseObject { * @return array */ public function getDependentPackages() { - self::loadRequirements(); - - $packages = array(); - if (isset(self::$requirements[$this->packageID])) { - foreach (self::$requirements[$this->packageID] as $packageID) { - $packages[$packageID] = PackageCache::getInstance()->getPackage($packageID); + if ($this->dependentPackages === null) { + self::loadRequirements(); + + $this->dependentPackages = array(); + foreach (self::$requirements as $packageID => $requiredPackageIDs) { + if (in_array($this->packageID, $requiredPackageIDs)) { + $this->dependentPackages[$packageID] = PackageCache::getInstance()->getPackage($packageID); + } } } - return $packages; + return $this->dependentPackages; } /**