Ejemplo n.º 1
0
 public function manufacture($classname, $id, $row = null)
 {
     // Check that the id is valid
     if ((int) $id == 0) {
         throw new Exception('Invalid id');
     }
     // Set up the name for the factory array
     $factory_array_name = "_{$classname}s";
     $item = null;
     // Set up the manufactured array if it doesn't exist
     if (!isset($this->{$factory_array_name})) {
         TBGLogging::log("Setting up manufactured array for {$classname}");
         $this->{$factory_array_name} = array();
     }
     // If the current id doesn't exist in the manufactured array, manufacture it
     if (!array_key_exists($id, $this->{$factory_array_name})) {
         // Initialize a position for the item in the manufactured array
         $this->{$factory_array_name}[$id] = null;
         try {
             // Check if the class is cacheable as well
             $cacheable = false;
             // in_array($classname, array('TBGProject', 'TBGStatus', 'TBGPriority', 'TBGCategory', 'TBGUserstate'));
             $item = null;
             // If the class is cacheable, check if it exists in the cache
             if ($cacheable) {
                 if ($item = TBGCache::get(TBGCache::KEY_TBG_FACTORY . "{$factory_array_name}_{$id}")) {
                     TBGLogging::log("Using cached {$classname} with id {$id}");
                 }
             }
             // If we didn't get an item from the cache, manufacture it
             if (!$cacheable || !is_object($item)) {
                 $item = new $classname($id, $row);
                 TBGLogging::log("Manufacturing {$classname} with id {$id}");
                 // Add the item to the cache if it's cacheable
                 if ($cacheable) {
                     TBGCache::add(TBGCache::KEY_TBG_FACTORY . "{$factory_array_name}_{$id}", $item);
                 }
             }
             // Add the manufactured item to the manufactured array
             $this->{$factory_array_name}[$id] = $item;
         } catch (Exception $e) {
             throw $e;
         }
     } else {
         TBGLogging::log("Using previously manufactured {$classname} with id {$id}");
     }
     // Return the item at that id in the manufactured array
     return $this->{$factory_array_name}[$id];
 }
 public static function getAll()
 {
     if (self::$_userstates === null) {
         if (!($states = TBGCache::get(TBGCache::KEY_USERSTATES_CACHE))) {
             $res = TBGUserStateTable::getTable()->doSelectAll();
             $states = array();
             while ($row = $res->getNextRow()) {
                 $states[$row->get(TBGUserStateTable::ID)] = TBGContext::factory()->TBGUserstate($row->get(TBGUserStateTable::ID), $row);
             }
             TBGCache::add(TBGCache::KEY_USERSTATES_CACHE, $states);
         }
         self::$_userstates = $states;
     }
     return self::$_userstates;
 }
 public static function getIssueRegex()
 {
     if (!($regex = TBGCache::get(TBGCache::KEY_TEXTPARSER_ISSUE_REGEX))) {
         $issue_strings = array('bug', 'issue', 'ticket', 'story');
         foreach (TBGIssuetype::getAll() as $issuetype) {
             $issue_strings[] = $issuetype->getName();
         }
         $issue_string = join('|', $issue_strings);
         $issue_string = html_entity_decode($issue_string, ENT_QUOTES);
         $issue_string = str_replace(array(' ', "'"), array('\\s{1,1}', "\\'"), $issue_string);
         $regex = '#( |^)(?<!\\!)((' . $issue_string . ')\\s\\#?(([A-Z0-9]+\\-)?\\d+))#i';
         TBGCache::add(TBGCache::KEY_TEXTPARSER_ISSUE_REGEX, $regex);
     }
     return $regex;
 }
Ejemplo n.º 4
0
 public function cacheRoutes()
 {
     TBGCache::fileAdd(TBGCache::KEY_ROUTES_CACHE, $this->getRoutes());
     TBGCache::add(TBGCache::KEY_ROUTES_CACHE, $this->getRoutes());
 }
 protected function _postSave($is_new)
 {
     TBGCache::delete(TBGCache::KEY_TEXTPARSER_ISSUE_REGEX);
 }
Ejemplo n.º 6
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);
     }
 }
Ejemplo n.º 7
0
 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();
         }
     }
 }
Ejemplo n.º 8
0
 public static function saveSetting($name, $value, $module = 'core', $scope = 0, $uid = 0)
 {
     if ($scope == 0 && $name != 'defaultscope' && $module == 'core') {
         if (($scope = TBGContext::getScope()) instanceof TBGScope) {
             $scope = $scope->getID();
         } else {
             throw new Exception('No scope loaded, cannot autoload it');
         }
     }
     B2DB::getTable('TBGSettingsTable')->saveSetting($name, $module, $value, $uid, $scope);
     if ($scope != 0 && (!TBGContext::getScope() instanceof TBGScope || $scope == TBGContext::getScope()->getID())) {
         self::$_settings[$module][$name][$uid] = $value;
     }
     TBGCache::delete('settings');
 }
Ejemplo n.º 9
0
 public static function isEnabled()
 {
     if (self::$_enabled === null || self::$_enabled == true) {
         self::$_enabled = function_exists('apc_add');
     }
     return self::$_enabled;
 }
Ejemplo n.º 10
0
 public static function setPrefix($prefix)
 {
     self::$_prefix = $prefix;
 }
Ejemplo n.º 11
0
 public function runSaveMenuOrder(TBGRequest $request)
 {
     $target_type = $request['target_type'];
     $target_id = $request['target_id'];
     TBGLinksTable::getTable()->saveLinkOrder($request[$target_type . '_' . $target_id . '_links']);
     if ($target_type == 'main_menu') {
         TBGCache::delete(TBGCache::KEY_MAIN_MENU_LINKS);
         TBGCache::fileDelete(TBGCache::KEY_MAIN_MENU_LINKS);
     }
     return $this->renderJSON('ok');
 }
Ejemplo n.º 12
0
 /** 
  * Returns an array of regular expressions that should be used for matching
  * the issue numbers and workflow transitions in a VCS commit.
  *
  * Each element of an array is a single regular expression that will be
  * applied against the incoming commit message. Each regular expression
  * should have two named patterns - one denoting the issue number (should
  * include prefix if used in project), and one denoting workflow
  * transitions.
  *
  * Simple example would be:
  *
  * '#fixes issue #(?P<issues>([A-Z0-9]+\-)?\d+) (?P<transitions> \(.*?\))?#i'
  * 
  * @return array
  */
 public static function getIssueRegex()
 {
     // Try getting the regexes from cache first.
     if (!($regex = TBGCache::get(TBGCache::KEY_TEXTPARSER_ISSUE_REGEX))) {
         // List of keywords that are expected to prefix the issue number in a
         // commit message (these are _not_ project prefixes).
         $issue_strings = array('bug', 'issue', 'ticket', 'fix', 'fixes', 'fixed', 'fixing', 'applies to', 'closes', 'references', 'ref', 'addresses', 're', 'see', 'according to', 'also see', 'story');
         // Add the issue types as prefixes as well.
         foreach (TBGIssuetype::getAll() as $issuetype) {
             $issue_strings[] = $issuetype->getName();
         }
         // Construct the OR'ed (|) regex out of issue prefixes.
         $issue_string = join('|', $issue_strings);
         $issue_string = html_entity_decode($issue_string, ENT_QUOTES);
         $issue_string = str_replace(array(' ', "'"), array('\\s{1,1}', "\\'"), $issue_string);
         // Store all regular expressions for mathces in an array.
         $regex = array();
         // This regex will match messages that contain template like "KEYWORD
         // (#)ISSUE_NUMBER (TRANSITIONS)" (parenthesis means optional). For
         // example:
         // "Resolves issue #2 (Resolve issue)"
         $regex[] = '#( |^)(?<!\\!)((' . $issue_string . ')\\s\\#?(?P<issues>([A-Z0-9]+\\-)?\\d+))( \\((?P<transitions>.*?)\\))?#i';
         // This regex will match messages that contain template at the beginning
         // of message in format "ISSUE_NUMBER: (TRANSITIONS)".
         $regex[] = '#^(?<!\\!)((?P<issues>([A-Z0-9]+\\-)?\\d+)):( \\((?P<transitions>.*?)\\))?#i';
         // Add the constructed regexes to cache.
         TBGCache::add(TBGCache::KEY_TEXTPARSER_ISSUE_REGEX, $regex);
     }
     // Return the regular expressions.
     return $regex;
 }
Ejemplo n.º 13
0
require THEBUGGENIE_CORE_PATH . 'classes' . DS . 'TBGContext.class.php';
// Load the logging class so we can log stuff
require THEBUGGENIE_CORE_PATH . 'classes' . DS . 'TBGLogging.class.php';
// Start loading The Bug Genie
try {
    // Set the start time
    TBGContext::setLoadStart($starttime[1] + $starttime[0]);
    TBGLogging::log('Initializing Caspar framework');
    TBGLogging::log('PHP_SAPI says "' . PHP_SAPI . '"');
    if (!isset($argc) && !ini_get('session.auto_start')) {
        session_name(THEBUGGENIE_SESSION_NAME);
        session_start();
    }
    // Add classpath so we can find the TBG* classes
    TBGContext::addClasspath(THEBUGGENIE_CORE_PATH . 'classes' . DS);
    TBGLogging::log(TBGCache::isEnabled() ? 'APC cache is enabled' : 'APC cache is not enabled');
    TBGLogging::log('Loading B2DB');
    try {
        TBGLogging::log('Adding B2DB classes to autoload path');
        define('B2DB_BASEPATH', THEBUGGENIE_CORE_PATH . 'B2DB' . DS);
        define('B2DB_CACHEPATH', THEBUGGENIE_CORE_PATH . 'cache' . DS . 'B2DB' . DS);
        TBGContext::addClasspath(THEBUGGENIE_CORE_PATH . 'B2DB' . DS . 'classes' . DS);
        TBGLogging::log('...done (Adding B2DB classes to autoload path)');
        TBGLogging::log('Initializing B2DB');
        if (!isset($argc)) {
            B2DB::setHTMLException(true);
        }
        B2DB::initialize(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php');
        TBGLogging::log('...done (Initializing B2DB)');
        if (B2DB::isInitialized()) {
            TBGLogging::log('Database connection details found, connecting');
Ejemplo n.º 14
0
 protected function loadStrings($module = null)
 {
     $strings_key = $module !== null ? 'i18n_strings' : "i18n_strings_{$module}";
     if (!($strings = TBGCache::get($strings_key))) {
         $filename = '';
         if ($module !== null) {
             if (file_exists(THEBUGGENIE_PATH . 'i18n' . DS . $this->_language . DS . "{$module}.inc.php")) {
                 $filename = THEBUGGENIE_PATH . 'i18n' . DS . $this->_language . DS . "{$module}.inc.php";
             } else {
                 $filename = THEBUGGENIE_MODULES_PATH . $module . DS . 'i18n' . DS . $this->_language . DS . "{$module}.inc.php";
             }
         } else {
             $filename = $this->getStringsFilename();
         }
         if (file_exists($filename)) {
             TBGLogging::log("Loading strings from file '{$filename}", 'i18n');
             $strings = array();
             require $filename;
             TBGCache::add($strings_key, $strings);
         } else {
             $message = 'Could not find language file ' . $filename;
             TBGLogging::log($message, 'i18n', TBGLogging::LEVEL_NOTICE);
         }
     } else {
         TBGLogging::log('Using cached strings', 'i18n');
     }
     $this->addStrings($strings);
 }
Ejemplo n.º 15
0
 /**
  * Returns all the links on the frontpage
  * 
  * @return array
  */
 public static function getMainLinks()
 {
     if (!($links = TBGCache::get('core_main_links'))) {
         $links = B2DB::getTable('TBGLinksTable')->getMainLinks();
         TBGCache::add('core_main_links', $links);
     }
     return $links;
 }
Ejemplo n.º 16
0
 public function saveLinkOrder($links)
 {
     foreach ($links as $key => $link_id) {
         $crit = $this->getCriteria();
         $crit->addUpdate(self::LINK_ORDER, $key + 1);
         $crit->addWhere(self::SCOPE, TBGContext::getScope()->getID());
         $this->doUpdateById($crit, $link_id);
     }
     TBGCache::clearCacheKeys(array(TBGCache::KEY_MAIN_MENU_LINKS));
 }
Ejemplo n.º 17
0
 /**
  * Returns all the links on the frontpage
  * 
  * @return array
  */
 public static function getMainLinks()
 {
     if (!($links = TBGCache::get(TBGCache::KEY_MAIN_MENU_LINKS))) {
         $links = TBGLinksTable::getTable()->getMainLinks();
         if (!self::isInstallmode()) {
             TBGCache::add(TBGCache::KEY_MAIN_MENU_LINKS, $links);
         }
     }
     return $links;
 }