PackageDependencyHandler is now a singleton
authorAlexander Ebert <ebert@woltlab.com>
Mon, 5 Mar 2012 14:57:42 +0000 (15:57 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 5 Mar 2012 14:57:42 +0000 (15:57 +0100)
18 files changed:
wcfsetup/install/files/lib/acp/action/CacheClearAction.class.php
wcfsetup/install/files/lib/acp/page/CacheListPage.class.php
wcfsetup/install/files/lib/acp/page/CronjobListPage.class.php
wcfsetup/install/files/lib/acp/page/CronjobLogListPage.class.php
wcfsetup/install/files/lib/data/language/LanguageEditor.class.php
wcfsetup/install/files/lib/data/package/Package.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/cache/builder/ClipboardActionCacheBuilder.class.php
wcfsetup/install/files/lib/system/cache/builder/ClipboardPageCacheBuilder.class.php
wcfsetup/install/files/lib/system/cache/builder/CoreObjectCacheBuilder.class.php
wcfsetup/install/files/lib/system/cache/builder/CronjobCacheBuilder.class.php
wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php
wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCacheBuilder.class.php
wcfsetup/install/files/lib/system/cache/builder/TemplateListenerCodeCacheBuilder.class.php
wcfsetup/install/files/lib/system/cronjob/CronjobScheduler.class.php
wcfsetup/install/files/lib/system/package/PackageArchive.class.php
wcfsetup/install/files/lib/system/package/PackageDependencyHandler.class.php
wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php

index 1f7bc56567d6fb0cce82cbf9626e541cfd069595..51b5ab252a0c99304c4ce3427a129064cc66fb31 100644 (file)
@@ -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
index 89180ae405d3783037f81e5e90006376fa76b1a8..ec24dd894694a480c3b76163bb5ae537aaccd81d 100755 (executable)
@@ -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
index 8da63d65724dcf4552c7cbbdf3da3a18ddf94b6d..ef499c754cc97a570a80206bbd1911cb76be12df 100755 (executable)
@@ -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;
        }
        
index d2ee832e883e7857c500c4c14cc4fd1467c0a56b..267e61f1b977b16194eb32637308cb091b762f98 100755 (executable)
@@ -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()));
        }
        
        /**
index c4b7cfa1e98e983874dff6374576759a965ee37e..0979bfcfcbe2435b1e7e1479fbe333197aa3136f 100644 (file)
@@ -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
index e8174c66b86a70f94d7865c2de59d362847ed1df..6c9933128f182847aece97b45d7c4af7c34d61b1 100644 (file)
@@ -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;
index 7ca4ba9ed1875583762ae1a806b47bfd04c26fd2..c4f220a0a61bdfb04bee59d86adef4f66d89e8f9 100644 (file)
@@ -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();
        }
        
        /**
index e86c1ed042d679d26f27046ae77e9f0206bd40b9..49e1d3f4dad228bd30730eb5c152cc2e1ba5c4cb 100644 (file)
@@ -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();
                
index 1d752fad3fa055d6a214161e80fce7b84ef616b3..305f326eec2eae55c9f30b2e627efe6321acbf95 100644 (file)
@@ -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
index 79ccdc23216e8ce106cd96f15c2032e1cdfa1eaa..f840d61533e16444b014c71af5ee6f30534f945a 100644 (file)
@@ -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();
index b2ed6e7f010f20f09cf5768ffad5768c0452cc43..359741c70e5c2296e390b8ade9a859224069575b 100644 (file)
@@ -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
index 61da89bfbaf70043be03cb3298b986b872727146..8afc9060c2d1bd0c7ee471130cca65c88449c4d6 100644 (file)
@@ -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
index a8cfff349a8433af41eb71f3c981668d49c41b7a..f3ce33dcaee13caaf78e3b9c393e70b883278410 100644 (file)
@@ -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();
                
index 2e40be164fcbba23531c235d8befca9c7bfdb234..4c1c0814fcd0b4e621ef45c4647868d059c25ad1 100644 (file)
@@ -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();
                
index 02bd6ebd9865cda3e055a0da1b21623ba037194d..92875510b2148344771f18768977189c59f22259 100644 (file)
@@ -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));
index ca56bf10b7eae4bb97c3ee0d460faae522e3b1fc..e8f36593c80fde10824e4cc0935d65cbb7159396 100644 (file)
@@ -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;
index 3437bd60e1d6567b83951bf18823730cf013f0c4..0e3b061fd2787c1282d76514434e6ef3f7050d82 100644 (file)
@@ -1,24 +1,39 @@
 <?php
 namespace wcf\system\package;
 use wcf\system\cache\CacheHandler;
+use wcf\system\SingletonFactory;
 
 /**
  * PackageDependencyHandler stores package dependencies and providing a consistent interface for accessing.
  *
  * @author     Alexander Ebert
- * @copyright  2001-2011 WoltLab GmbH
+ * @copyright  2001-2012 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @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'];
        }
 }
index 0ebe1beda98d717259affbcab4dfe492040b19b6..121fb0a900afa3d0a85f0dedd607fd2e59b6c99c 100644 (file)
@@ -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