From 6eb121400f68e60cefb5a01f8e2d181c14bd4c7c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 5 Mar 2012 15:57:42 +0100 Subject: [PATCH] PackageDependencyHandler is now a singleton --- .../lib/acp/action/CacheClearAction.class.php | 2 +- .../lib/acp/page/CacheListPage.class.php | 4 +- .../lib/acp/page/CronjobListPage.class.php | 2 +- .../lib/acp/page/CronjobLogListPage.class.php | 2 +- .../data/language/LanguageEditor.class.php | 2 +- .../files/lib/data/package/Package.class.php | 2 +- .../install/files/lib/system/WCF.class.php | 2 +- .../ClipboardActionCacheBuilder.class.php | 2 +- .../ClipboardPageCacheBuilder.class.php | 2 +- .../builder/CoreObjectCacheBuilder.class.php | 2 +- .../builder/CronjobCacheBuilder.class.php | 2 +- .../cache/builder/IconCacheBuilder.class.php | 2 +- .../TemplateListenerCacheBuilder.class.php | 2 +- ...TemplateListenerCodeCacheBuilder.class.php | 2 +- .../system/cronjob/CronjobScheduler.class.php | 2 +- .../system/package/PackageArchive.class.php | 2 +- .../PackageDependencyHandler.class.php | 53 ++++++++----------- .../user/storage/UserStorageHandler.class.php | 2 +- 18 files changed, 41 insertions(+), 48 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/action/CacheClearAction.class.php b/wcfsetup/install/files/lib/acp/action/CacheClearAction.class.php index 1f7bc56567..51b5ab252a 100644 --- a/wcfsetup/install/files/lib/acp/action/CacheClearAction.class.php +++ b/wcfsetup/install/files/lib/acp/action/CacheClearAction.class.php @@ -35,7 +35,7 @@ class CacheClearAction extends AbstractAction { LanguageFactory::getInstance()->deleteLanguageCache(); $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs diff --git a/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php b/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php index 89180ae405..ec24dd8946 100755 --- a/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CacheListPage.class.php @@ -110,7 +110,7 @@ class CacheListPage extends AbstractPage { $this->cacheData['version'] = WCF_VERSION; $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs @@ -140,7 +140,7 @@ class CacheListPage extends AbstractPage { $this->cacheData['version'] = phpversion('apc'); $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("isApplication = ?", array(1)); // get package dirs diff --git a/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php b/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php index 8da63d6572..ef499c754c 100755 --- a/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php @@ -47,7 +47,7 @@ class CronjobListPage extends SortablePage { public function initObjectList() { parent::initObjectList(); - $this->objectList->getConditionBuilder()->add("cronjob.packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $this->objectList->getConditionBuilder()->add("cronjob.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $this->sqlOrderBy = "cronjob.".$this->sortField." ".$this->sortOrder; } diff --git a/wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php b/wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php index d2ee832e88..267e61f1b9 100755 --- a/wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php @@ -59,7 +59,7 @@ class CronjobLogListPage extends SortablePage { $this->objectList->sqlSelects = "cronjob.*"; $this->objectList->sqlJoins = "LEFT JOIN wcf".WCF_N."_cronjob cronjob ON (cronjob.cronjobID = cronjob_log.cronjobID)"; - $this->objectList->getConditionBuilder()->add("cronjob_log.cronjobID IN (SELECT cronjobID FROM wcf".WCF_N."_cronjob WHERE packageID IN (?))", array(PackageDependencyHandler::getDependencies())); + $this->objectList->getConditionBuilder()->add("cronjob_log.cronjobID IN (SELECT cronjobID FROM wcf".WCF_N."_cronjob WHERE packageID IN (?))", array(PackageDependencyHandler::getInstance()->getDependencies())); } /** diff --git a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php index c4b7cfa1e9..0979bfcfcb 100644 --- a/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php +++ b/wcfsetup/install/files/lib/data/language/LanguageEditor.class.php @@ -533,7 +533,7 @@ class LanguageEditor extends DatabaseObjectEditor { } $conditionBuilder->add($searchCondition, $statementParameters); - $conditionBuilder->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $conditionBuilder->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); if ($languageID !== null) $conditionBuilder->add("languageID = ?", array($languageID)); // search diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index e8174c66b8..6c9933128f 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -585,7 +585,7 @@ class Package extends DatabaseObject { */ public static function getPluginList() { $pluginList = new PackageList(); - $pluginList->getConditionBuilder()->add("package.packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $pluginList->getConditionBuilder()->add("package.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $pluginList->getConditionBuilder()->add("package.isApplication = ?", array(0)); return $pluginList; diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 7ca4ba9ed1..c4f220a0a6 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -477,7 +477,7 @@ class WCF { } self::$coreObjectCache = CacheHandler::getInstance()->get('coreObjects-'.PACKAGE_ID); - self::$packageDependencies = \wcf\system\package\PackageDependencyHandler::getDependencies(); + self::$packageDependencies = \wcf\system\package\PackageDependencyHandler::getInstance()->getDependencies(); } /** diff --git a/wcfsetup/install/files/lib/system/cache/builder/ClipboardActionCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ClipboardActionCacheBuilder.class.php index e86c1ed042..49e1d3f4da 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/ClipboardActionCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/ClipboardActionCacheBuilder.class.php @@ -19,7 +19,7 @@ class ClipboardActionCacheBuilder implements ICacheBuilder { */ public function getData(array $cacheResource) { $actionList = new ClipboardActionList(); - $actionList->getConditionBuilder()->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $actionList->getConditionBuilder()->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $actionList->sqlLimit = 0; $actionList->readObjects(); diff --git a/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php index 1d752fad3f..305f326eec 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php @@ -20,7 +20,7 @@ class ClipboardPageCacheBuilder implements ICacheBuilder { */ public function getData(array $cacheResource) { $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $sql = "SELECT pageClassName, actionID FROM wcf".WCF_N."_clipboard_page diff --git a/wcfsetup/install/files/lib/system/cache/builder/CoreObjectCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/CoreObjectCacheBuilder.class.php index 79ccdc2321..f840d61533 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/CoreObjectCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/CoreObjectCacheBuilder.class.php @@ -22,7 +22,7 @@ class CoreObjectCacheBuilder implements ICacheBuilder { $data = array(); $coreObjectList = new CoreObjectList(); - $coreObjectList->getConditionBuilder()->add("core_object.packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $coreObjectList->getConditionBuilder()->add("core_object.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $coreObjectList->sqlLimit = 0; $coreObjectList->readObjects(); $coreObjects = $coreObjectList->getObjects(); diff --git a/wcfsetup/install/files/lib/system/cache/builder/CronjobCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/CronjobCacheBuilder.class.php index b2ed6e7f01..359741c70e 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/CronjobCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/CronjobCacheBuilder.class.php @@ -21,7 +21,7 @@ class CronjobCacheBuilder implements ICacheBuilder { public function getData(array $cacheResource) { // get next execution time $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $conditionBuilder->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $sql = "SELECT MIN(nextExec) AS nextExec, MIN(afterNextExec) AS afterNextExec diff --git a/wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php index 61da89bfba..8afc9060c2 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php @@ -31,7 +31,7 @@ class IconCacheBuilder implements ICacheBuilder { // get package dirs $packageDirs = array(); $conditionBuilder = new PreparedStatementConditionBuilder(); - $conditionBuilder->add("dependency.packageID IN (?) AND package.packageDir <> ''", array(PackageDependencyHandler::getDependencies())); + $conditionBuilder->add("dependency.packageID IN (?) AND package.packageDir <> ''", array(PackageDependencyHandler::getInstance()->getDependencies())); $sql = "SELECT DISTINCT package.packageDir, dependency.priority FROM wcf".WCF_N."_package_dependency dependency LEFT JOIN wcf".WCF_N."_package package diff --git a/wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCacheBuilder.class.php index a8cfff349a..f3ce33dcae 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCacheBuilder.class.php @@ -24,7 +24,7 @@ class TemplateListenerCacheBuilder implements ICacheBuilder { $templateListenerList = new TemplateListenerList(); $templateListenerList->getConditionBuilder()->add("template_listener.environment = ?", array($environment)); // work-around during setup - if (PACKAGE_ID) $templateListenerList->getConditionBuilder()->add("template_listener.packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + if (PACKAGE_ID) $templateListenerList->getConditionBuilder()->add("template_listener.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $templateListenerList->sqlLimit = 0; $templateListenerList->readObjects(); diff --git a/wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCodeCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCodeCacheBuilder.class.php index 2e40be164f..4c1c0814fc 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCodeCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCodeCacheBuilder.class.php @@ -24,7 +24,7 @@ class TemplateListenerCodeCacheBuilder implements ICacheBuilder { $templateListenerList = new TemplateListenerList(); $templateListenerList->getConditionBuilder()->add("template_listener.environment = ?", array($environment)); $templateListenerList->getConditionBuilder()->add("template_listener.templateName = ?", array($templateName)); - $templateListenerList->getConditionBuilder()->add("template_listener.packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $templateListenerList->getConditionBuilder()->add("template_listener.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $templateListenerList->sqlLimit = 0; $templateListenerList->readObjects(); diff --git a/wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php b/wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php index 02bd6ebd98..92875510b2 100644 --- a/wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php @@ -96,7 +96,7 @@ class CronjobScheduler extends SingletonFactory { */ protected function loadCronjobs() { $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("cronjob.packageID IN (?)", array(PackageDependencyHandler::getDependencies())); + $conditions->add("cronjob.packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies())); $conditions->add("(cronjob.nextExec <= ? OR cronjob.afterNextExec <= ?)", array(TIME_NOW, TIME_NOW)); $conditions->add("cronjob.active = ?", array(1)); $conditions->add("cronjob.failCount < ?", array(3)); diff --git a/wcfsetup/install/files/lib/system/package/PackageArchive.class.php b/wcfsetup/install/files/lib/system/package/PackageArchive.class.php index ca56bf10b7..e8f36593c8 100644 --- a/wcfsetup/install/files/lib/system/package/PackageArchive.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageArchive.class.php @@ -478,7 +478,7 @@ class PackageArchive { } // determine if plugin is unique within current application - $packageIDs = PackageDependencyHandler::getDependencies(); + $packageIDs = PackageDependencyHandler::getInstance()->getDependencies(); foreach ($parentPackageIDs as $packageID) { if (in_array($packageID, $packageIDs)) { return true; diff --git a/wcfsetup/install/files/lib/system/package/PackageDependencyHandler.class.php b/wcfsetup/install/files/lib/system/package/PackageDependencyHandler.class.php index 3437bd60e1..0e3b061fd2 100644 --- a/wcfsetup/install/files/lib/system/package/PackageDependencyHandler.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageDependencyHandler.class.php @@ -1,24 +1,39 @@ * @package com.woltlab.wcf * @subpackage system.package * @category Community Framework */ -abstract class PackageDependencyHandler { +class PackageDependencyHandler extends SingletonFactory { /** * cache of package dependencies * * @var array */ - protected static $packageDependencyCache = null; + protected $packageDependencyCache = null; + + /** + * @see wcf\system\SingletonFactory::init() + */ + protected function init() { + $cacheName = 'packageDependencies-'.PACKAGE_ID; + CacheHandler::getInstance()->addResource( + $cacheName, + WCF_DIR.'cache/cache.'.$cacheName.'.php', + 'wcf\system\cache\builder\PackageDependencyCacheBuilder' + ); + + $this->packageDependencyCache = CacheHandler::getInstance()->get($cacheName); + } /** * Returns the id of a specific package in the active dependencies. @@ -26,17 +41,13 @@ abstract class PackageDependencyHandler { * @param string $package package identifier * @return mixed */ - public static function getPackageID($package) { + public function getPackageID($package) { if (!defined('PACKAGE_ID')) { return null; } - if (self::$packageDependencyCache === null) { - self::readCache(); - } - - if (isset(self::$packageDependencyCache['resolve'][$package])) { - $packageID = self::$packageDependencyCache['resolve'][$package]; + if (isset($this->packageDependencyCache['resolve'][$package])) { + $packageID = $this->packageDependencyCache['resolve'][$package]; if (is_array($packageID)) { $packageID = array_shift($packageID); @@ -53,29 +64,11 @@ abstract class PackageDependencyHandler { * * @return array */ - public static function getDependencies() { + public function getDependencies() { if (!defined('PACKAGE_ID')) { return null; } - if (self::$packageDependencyCache === null) { - self::readCache(); - } - - return self::$packageDependencyCache['dependency']; - } - - /** - * Reads package dependency cache. - */ - protected static function readCache() { - $cacheName = 'packageDependencies-'.PACKAGE_ID; - CacheHandler::getInstance()->addResource( - $cacheName, - WCF_DIR.'cache/cache.'.$cacheName.'.php', - 'wcf\system\cache\builder\PackageDependencyCacheBuilder' - ); - - self::$packageDependencyCache = CacheHandler::getInstance()->get($cacheName); + return $this->packageDependencyCache['dependency']; } } diff --git a/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php b/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php index 0ebe1beda9..121fb0a900 100644 --- a/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php @@ -51,7 +51,7 @@ class UserStorageHandler extends SingletonFactory { $conditions = new PreparedStatementConditionBuilder(); $conditions->add("userID IN (?)", array($tmp)); - $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getDependencies($packageID))); + $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies($packageID))); $sql = "SELECT * FROM wcf".WCF_N."_user_storage -- 2.20.1