示例#1
0
 public function hasCachedRoutes()
 {
     if ($this->has_cached_routes === null) {
         if (TBGContext::isInstallmode()) {
             $this->has_cached_routes = false;
         } else {
             $this->has_cached_routes = TBGCache::has(TBGCache::KEY_ROUTES_CACHE);
             if ($this->has_cached_routes) {
                 TBGLogging::log('Routes are cached', 'routing');
             } else {
                 TBGLogging::log('Routes are not cached', 'routing');
             }
         }
     }
     return $this->has_cached_routes;
 }
示例#2
0
 protected static function _populateCachedTableClassFiles($classname)
 {
     if (!array_key_exists($classname, self::$_cached_table_classes)) {
         $key = 'b2db_cache_' . $classname;
         if (self::$_cache_enabled && \TBGCache::has($key, false)) {
             self::$_cached_table_classes[$classname] = \TBGCache::get($key, false);
         } elseif (self::$_cache_enabled && \TBGCache::fileHas($key, false)) {
             self::$_cached_table_classes[$classname] = \TBGCache::fileGet($key, false);
         } else {
             self::cacheTableClass($classname);
         }
     }
     if (self::$_cached_table_classes[$classname] === null) {
         self::cacheTableClass($classname);
     }
 }
 public final function initialize()
 {
     $this->_initialize();
     if ($this->isEnabled()) {
         $this->_addAvailablePermissions();
         $this->_addListeners();
         if (!TBGCache::has(TBGCache::KEY_POSTMODULES_ROUTES_CACHE)) {
             $this->_addRoutes();
             $this->_loadRoutes();
         }
     }
 }
 /**
  * Loads and initializes all modules
  */
 public static function loadModules()
 {
     TBGLogging::log('Loading modules');
     if (self::$_modules === null) {
         self::$_modules = array();
         if (self::isInstallmode()) {
             return;
         }
         if (!TBGCache::has(TBGCache::KEY_MODULE_PATHS) || !TBGCache::has(TBGCache::KEY_MODULES)) {
             $modules = array();
             TBGLogging::log('getting modules from database');
             $module_paths = array();
             if ($res = B2DB::getTable('TBGModulesTable')->getAll()) {
                 while ($moduleRow = $res->getNextRow()) {
                     $module_name = $moduleRow->get(TBGModulesTable::MODULE_NAME);
                     $modules[$module_name] = $moduleRow;
                     $moduleClassPath = THEBUGGENIE_MODULES_PATH . $module_name . DS . "classes" . DS;
                     try {
                         self::addClasspath($moduleClassPath);
                         $module_paths[] = $moduleClassPath;
                         if (file_exists($moduleClassPath . 'B2DB')) {
                             self::addClasspath($moduleClassPath . 'B2DB' . DS);
                             $module_paths[] = $moduleClassPath . 'B2DB' . DS;
                         }
                     } catch (Exception $e) {
                     }
                     // ignore "dir not exists" errors
                 }
             }
             TBGLogging::log('done (getting modules from database)');
             TBGCache::add(TBGCache::KEY_MODULE_PATHS, $module_paths);
             TBGLogging::log('setting up module objects');
             foreach ($modules as $module_name => $moduleRow) {
                 $classname = $moduleRow->get(TBGModulesTable::CLASSNAME);
                 if ($classname != '' && $classname != 'TBGModule') {
                     if (class_exists($classname)) {
                         self::$_modules[$module_name] = new $classname($moduleRow->get(TBGModulesTable::ID), $moduleRow);
                     } else {
                         TBGLogging::log('Cannot load module "' . $module_name . '" as class "' . $classname . '", the class is not defined in the classpaths.', 'modules', TBGLogging::LEVEL_WARNING_RISK);
                         TBGLogging::log('Removing module "' . $module_name . '" as it cannot be loaded', 'modules', TBGLogging::LEVEL_NOTICE);
                         TBGModule::removeModule($moduleRow->get(TBGModulesTable::ID));
                     }
                 } else {
                     throw new Exception('Cannot load module "' . $module_name . '" as class TBGModule - modules should extend the TBGModule class with their own class.');
                 }
             }
             TBGCache::add(TBGCache::KEY_MODULES, self::$_modules);
             TBGLogging::log('done (setting up module objects)');
         } else {
             TBGLogging::log('using cached modules');
             $module_paths = TBGCache::get(TBGCache::KEY_MODULE_PATHS);
             foreach ($module_paths as $path) {
                 self::addClasspath($path);
             }
             self::$_modules = TBGCache::get(TBGCache::KEY_MODULES);
             TBGLogging::log('done (using cached modules)');
         }
         TBGLogging::log('initializing modules');
         if (!empty(self::$_modules)) {
             foreach (self::$_modules as $module_name => $module) {
                 $module->initialize();
             }
             TBGLogging::log('done (initializing modules)');
         } else {
             TBGLogging::log('no modules found');
         }
     } else {
         TBGLogging::log('Modules already loaded', 'core', TBGLogging::LEVEL_FATAL);
     }
     TBGLogging::log('...done');
 }