From 3e737caf9b5cf0a2be3b9472495e5c0b388d59ec Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 5 Nov 2012 17:21:26 +0100 Subject: [PATCH] Added dependency injection for application groups --- .../application/ApplicationAction.class.php | 15 ++++--- .../files/lib/data/package/Package.class.php | 44 ++++++++++++++++++- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/lib/data/application/ApplicationAction.class.php b/wcfsetup/install/files/lib/data/application/ApplicationAction.class.php index 88f53ffafe..7a16d1880b 100644 --- a/wcfsetup/install/files/lib/data/application/ApplicationAction.class.php +++ b/wcfsetup/install/files/lib/data/application/ApplicationAction.class.php @@ -1,6 +1,7 @@ commitTransaction(); - $this->clearCache(); + $this->rebuild(); } /** @@ -94,7 +95,7 @@ class ApplicationAction extends AbstractDatabaseObjectAction { if (empty($this->objects)) { $this->readObjects(); } - $this->clearCache(); + $sql = "UPDATE wcf".WCF_N."_application SET groupID = ?, cookieDomain = domainName, @@ -111,18 +112,22 @@ class ApplicationAction extends AbstractDatabaseObjectAction { } WCF::getDB()->commitTransaction(); - $this->clearCache(); + $this->rebuild(); } /** - * Clears application cache. + * Rebuilds application cache and dependencies. */ - protected function clearCache() { + protected function rebuild() { foreach ($this->objects as $application) { + // reset cache $directory = PackageCache::getInstance()->getPackage($application->packageID)->packageDir; $directory = FileUtil::getRealPath(WCF_DIR.$directory); CacheHandler::getInstance()->clear($directory.'cache', '*.php'); + + // rebuild dependencies + Package::rebuildPackageDependencies($application->packageID); } } } diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index 8aedb7863d..7c83387aee 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -1,6 +1,7 @@ prepareStatement($sql); - $insertedDependencies = array(); + $insertedDependencies = self::insertApplicationDependencies($packageID, $statement); + $shiftPriority = (empty($insertedDependencies)) ? false : true; foreach ($requirements as $dependency => $priority) { - $statement->execute(array($packageID, $dependency, $priority)); + $statement->execute(array( + $packageID, + $dependency, + ($shiftPriority ? ($priority + 1) : $priority) + )); if (!isset($insertedDependencies[$packageID])) { $insertedDependencies[$packageID] = array(); @@ -521,6 +527,40 @@ class Package extends DatabaseObject { } } + /** + * Inserts dependencies on applications within the same application group. + * + * @param integer $packageID + * @param wcf\system\database\statement\PreparedStatement $insertStatement + * @return array + */ + protected static function insertApplicationDependencies($packageID, PreparedStatement $insertStatement) { + $insertedDependencies = array(); + + // check for application group + $sql = "SELECT groupID + FROM wcf".WCF_N."_application + WHERE packageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($packageID)); + $row = $statement->fetchArray(); + if ($row !== false && $row['groupID'] !== null) { + // select application ids + $sql = "SELECT packageID + FROM wcf".WCF_N."_application + WHERE groupID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($row['groupID'])); + while ($row = $statement->fetchArray()) { + $insertStatement->execute(array( + $packageID, + $row['packageID'], + 1 + )); + } + } + } + /** * Writes the config.inc.php for an application. * -- 2.20.1