예제 #1
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;
 }
예제 #2
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 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;
 }
 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;
 }
예제 #5
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 static function loadSettings($uid = 0)
 {
     TBGLogging::log("Loading settings");
     if (self::$_settings === null || $uid > 0 && !array_key_exists($uid, self::$_loadedsettings)) {
         TBGLogging::log('Loading settings');
         if (self::$_settings === null) {
             self::$_settings = array();
         }
         if (!TBGContext::isInstallmode() && $uid == 0 && (self::$_settings = TBGCache::get(TBGCache::KEY_SETTINGS))) {
             TBGLogging::log('Using cached settings');
         } else {
             TBGLogging::log('Settings not cached or install mode enabled. Retrieving from database');
             if ($res = B2DB::getTable('TBGSettingsTable')->getSettingsForScope(TBGContext::getScope()->getID(), $uid)) {
                 $cc = 0;
                 while ($row = $res->getNextRow()) {
                     $cc++;
                     self::$_settings[$row->get(TBGSettingsTable::MODULE)][$row->get(TBGSettingsTable::NAME)][$row->get(TBGSettingsTable::UID)] = $row->get(TBGSettingsTable::VALUE);
                 }
                 if ($cc == 0 && !TBGContext::isInstallmode() && $uid == 0) {
                     TBGLogging::log('There were no settings stored in the database!', 'main', TBGLogging::LEVEL_FATAL);
                     throw new TBGSettingsException('Could not retrieve settings from database (no settings stored)');
                 }
             } elseif (!TBGContext::isInstallmode() && $uid == 0) {
                 TBGLogging::log('Settings could not be retrieved from the database!', 'main', TBGLogging::LEVEL_FATAL);
                 throw new TBGSettingsException('Could not retrieve settings from database');
             }
             self::$_loadedsettings[$uid] = true;
             TBGLogging::log('Retrieved');
             TBGCache::add(TBGCache::KEY_SETTINGS, self::$_settings);
         }
     }
     TBGLogging::log("...done");
 }
예제 #7
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);
 }
예제 #8
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;
 }
예제 #9
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;
 }