protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::EDITION, Core::getTable('TBGEditionsTable'), TBGEditionsTable::ID);
     parent::_addForeignKeyColumn(self::COMPONENT, Core::getTable('TBGComponentsTable'), TBGComponentsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::ISSUE_ID, TBGIssuesTable::getTable(), TBGIssuesTable::ID);
     parent::_addForeignKeyColumn(self::CUSTOMFIELDS_ID, Core::getTable('TBGCustomFieldsTable'), TBGCustomFieldsTable::ID);
     parent::_addText(self::OPTION_VALUE, false);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addBoolean(self::CONFIRMED);
     parent::_addForeignKeyColumn(self::BUILD, Core::getTable('TBGBuildsTable'), TBGBuildsTable::ID);
     parent::_addForeignKeyColumn(self::ISSUE, TBGIssuesTable::getTable(), TBGIssuesTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
     parent::_addForeignKeyColumn(self::STATUS, TBGListTypesTable::getTable(), TBGListTypesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::VALUE, 200);
     parent::_addVarchar(self::OPERATOR, 40);
     parent::_addVarchar(self::FILTER_KEY, 100);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
     parent::_addForeignKeyColumn(self::SEARCH_ID, Core::getTable('TBGSavedSearchesTable'), TBGSavedSearchesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::MODULE_NAME, 50);
     parent::_addBoolean(self::ALLOWED);
     parent::_addForeignKeyColumn(self::UID, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::GID, TBGGroupsTable::getTable(), TBGGroupsTable::ID);
     parent::_addForeignKeyColumn(self::TID, Core::getTable('TBGTeamsTable'), TBGTeamsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::MODULE_NAME, 50);
     parent::_addInteger(self::NOTIFY_TYPE, 5);
     parent::_addInteger(self::TARGET_ID, 10);
     parent::_addVarchar(self::TITLE, 100);
     parent::_addText(self::CONTENTS, false);
     parent::_addInteger(self::STATUS, 5);
     parent::_addForeignKeyColumn(self::UID, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::GID, TBGGroupsTable::getTable(), TBGGroupsTable::ID);
     parent::_addForeignKeyColumn(self::TID, Core::getTable('TBGTeamsTable'), TBGTeamsTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
 }
 public function saveSearch($saved_search_name, $saved_search_description, $saved_search_public, $filters, $groupby, $grouporder, $ipp, $templatename, $template_parameter, $project_id, $saved_search_id = null)
 {
     $crit = $this->getCriteria();
     if ($saved_search_id !== null) {
         $crit->addUpdate(self::NAME, $saved_search_name);
         $crit->addUpdate(self::DESCRIPTION, $saved_search_description);
         $crit->addUpdate(self::TEMPLATE_NAME, $templatename);
         $crit->addUpdate(self::TEMPLATE_PARAMETER, $template_parameter);
         $crit->addUpdate(self::GROUPBY, $groupby);
         $crit->addUpdate(self::GROUPORDER, $grouporder);
         $crit->addUpdate(self::ISSUES_PER_PAGE, $ipp);
         $crit->addUpdate(self::APPLIES_TO_PROJECT, $project_id);
         if (TBGContext::getUser()->canCreatePublicSearches()) {
             $crit->addUpdate(self::IS_PUBLIC, $saved_search_public);
             $crit->addUpdate(self::UID, (bool) $saved_search_public ? 0 : TBGContext::getUser()->getID());
         } else {
             $crit->addUpdate(self::IS_PUBLIC, false);
             $crit->addWhere(self::UID, TBGContext::getUser()->getID());
         }
         $crit->addUpdate(self::SCOPE, TBGContext::getScope()->getID());
         $this->doUpdateById($crit, $saved_search_id);
     } else {
         $crit->addInsert(self::NAME, $saved_search_name);
         $crit->addInsert(self::DESCRIPTION, $saved_search_description);
         $crit->addInsert(self::TEMPLATE_NAME, $templatename);
         $crit->addInsert(self::TEMPLATE_PARAMETER, $template_parameter);
         $crit->addInsert(self::GROUPBY, $groupby);
         $crit->addInsert(self::GROUPORDER, $grouporder);
         $crit->addInsert(self::ISSUES_PER_PAGE, $ipp);
         $crit->addInsert(self::APPLIES_TO_PROJECT, $project_id);
         if (TBGContext::getUser()->canCreatePublicSearches()) {
             $crit->addInsert(self::IS_PUBLIC, $saved_search_public);
             $crit->addInsert(self::UID, (bool) $saved_search_public ? 0 : TBGContext::getUser()->getID());
         } else {
             $crit->addInsert(self::IS_PUBLIC, false);
             $crit->addInsert(self::UID, TBGContext::getUser()->getID());
         }
         $crit->addInsert(self::SCOPE, TBGContext::getScope()->getID());
         $saved_search_id = $this->doInsert($crit)->getInsertID();
     }
     Core::getTable('TBGSavedSearchFiltersTable')->deleteBySearchID($saved_search_id);
     Core::getTable('TBGSavedSearchFiltersTable')->saveFiltersForSavedSearch($saved_search_id, $filters);
     return $saved_search_id;
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::UNAME, 50);
     parent::_addVarchar(self::PASSWORD, 100);
     parent::_addVarchar(self::BUDDYNAME, 50);
     parent::_addVarchar(self::REALNAME, 100);
     parent::_addVarchar(self::EMAIL, 200);
     parent::_addForeignKeyColumn(self::USERSTATE, Core::getTable('TBGUserStateTable'), TBGUserStateTable::ID);
     parent::_addBoolean(self::CUSTOMSTATE);
     parent::_addVarchar(self::HOMEPAGE, 250, '');
     parent::_addVarchar(self::LANGUAGE, 100, '');
     parent::_addInteger(self::LASTSEEN, 10);
     parent::_addInteger(self::QUOTA);
     parent::_addBoolean(self::ACTIVATED);
     parent::_addBoolean(self::ENABLED);
     parent::_addBoolean(self::DELETED);
     parent::_addVarchar(self::AVATAR, 30, '');
     parent::_addBoolean(self::USE_GRAVATAR, true);
     parent::_addBoolean(self::PRIVATE_EMAIL);
     parent::_addBoolean(self::OPENID_LOCKED);
     parent::_addInteger(self::JOINED, 10);
 }
Пример #9
0
 /**
  * Add or delete an issue field option
  *
  * @param TBGRequest $request
  */
 public function runConfigureIssuefieldsAction(TBGRequest $request)
 {
     $i18n = TBGContext::getI18n();
     $this->forward403unless($this->access_level == TBGSettings::ACCESS_FULL);
     $types = TBGDatatype::getTypes();
     switch ($request['mode']) {
         case 'saveorder':
             $itemtype = $request['type'];
             if (array_key_exists($itemtype, $types)) {
                 TBGListTypesTable::getTable()->saveOptionOrder($request[$itemtype . '_list'], $itemtype);
             } else {
                 $customtype = TBGCustomDatatype::getByKey($request['type']);
                 TBGCustomFieldOptionsTable::getTable()->saveOptionOrder($request[$itemtype . '_list'], $customtype->getID());
             }
             return $this->renderJSON('ok');
             break;
         case 'add':
             if ($request['name']) {
                 if (array_key_exists($request['type'], $types)) {
                     $type_name = $types[$request['type']];
                     $item = new $type_name();
                     $item->setName($request['name']);
                     $item->setItemdata($request['itemdata']);
                     $item->save();
                 } else {
                     $customtype = TBGCustomDatatype::getByKey($request['type']);
                     $item = $customtype->createNewOption($request['name'], $request['value'], $request['itemdata']);
                 }
                 return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The option was added'), 'content' => $this->getTemplateHTML('issuefield', array('item' => $item, 'access_level' => $this->access_level, 'type' => $request['type']))));
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid name')));
         case 'edit':
             if ($request['name']) {
                 if (array_key_exists($request['type'], $types)) {
                     $labname = $types[$request['type']];
                     $item = TBGContext::factory()->{$labname}($request['id']);
                 } else {
                     $customtype = TBGCustomDatatype::getByKey($request['type']);
                     $item = TBGContext::factory()->TBGCustomDatatypeOption($request['id']);
                 }
                 if ($item instanceof TBGDatatypeBase) {
                     $item->setName($request['name']);
                     $item->setItemdata($request['itemdata']);
                     if (!$item->isBuiltin()) {
                         $item->setValue($request['value']);
                     }
                     $item->save();
                     return $this->renderJSON(array('title' => TBGContext::getI18n()->__('The option was updated')));
                 } else {
                     $this->getResponse()->setHttpStatus(400);
                     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid id')));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Please provide a valid name')));
         case 'delete':
             if ($request->hasParameter('id')) {
                 if (array_key_exists($request['type'], $types)) {
                     $classname = 'TBG' . ucfirst($request['type']);
                     $item = TBGContext::factory()->{$classname}($request['id'])->delete();
                     return $this->renderJSON(array('title' => $i18n->__('The option was deleted')));
                 } else {
                     \b2db\Core::getTable('TBGCustomFieldOptionsTable')->doDeleteById($request['id']);
                     return $this->renderJSON(array('title' => $i18n->__('The option was deleted')));
                 }
             }
             $this->getResponse()->setHttpStatus(400);
             return $this->renderJSON(array('error' => $i18n->__('Invalid id or type')));
             break;
     }
 }
Пример #10
0
 public static function findClients($details)
 {
     $crit = new \b2db\Criteria();
     $crit->addWhere(TBGClientsTable::NAME, "%{$details}%", \b2db\Criteria::DB_LIKE);
     $clients = array();
     if ($res = \b2db\Core::getTable('TBGClientsTable')->doSelect($crit)) {
         while ($row = $res->getNextRow()) {
             $clients[$row->get(TBGClientsTable::ID)] = TBGContext::factory()->TBGClient($row->get(TBGClientsTable::ID), $row);
         }
     }
     return $clients;
 }
Пример #11
0
 /**
  * Delete a custom type by id
  *
  * @param integer $id
  */
 protected function _preDelete()
 {
     TBGCustomFieldOptionsTable::getTable()->deleteCustomFieldOptions($this->getID());
     \b2db\Core::getTable('TBGIssueFieldsTable')->deleteByIssueFieldKey($this->getKey());
 }
Пример #12
0
 /**
  * Return an array of issues that has changes pending
  * 
  * @param int $number number of issues to be retrieved
  * 
  * @return array
  */
 public function getIssues($number = null)
 {
     $retval = array();
     if ($res = \b2db\Core::getTable('TBGIssuesTable')->getIssuesPostedByUser($this->getID(), $number)) {
         while ($row = $res->getNextRow()) {
             $issue = TBGContext::factory()->TBGIssue($row->get(TBGIssuesTable::ID), $row);
             $retval[$issue->getID()] = $issue;
         }
     }
     return $retval;
 }
Пример #13
0
 /**
  * Removes an existing component from the edition
  *
  * @param TBGComponent|integer $c_id
  */
 public function removeComponent($c_id)
 {
     if ($c_id instanceof TBGComponent) {
         $c_id = $c_id->getID();
     }
     \b2db\Core::getTable('TBGEditionComponentsTable')->removeEditionComponent($this->getID(), $c_id);
 }
Пример #14
0
 public final function install($scope)
 {
     try {
         framework\Context::clearRoutingCache();
         framework\Context::clearPermissionsCache();
         $this->_install($scope);
         $b2db_classpath = THEBUGGENIE_MODULES_PATH . $this->_name . DS . 'entities' . DS . 'tables';
         if ($scope == framework\Settings::getDefaultScopeID() && is_dir($b2db_classpath)) {
             $b2db_classpath_handle = opendir($b2db_classpath);
             while ($table_class_file = readdir($b2db_classpath_handle)) {
                 if (($tablename = mb_substr($table_class_file, 0, mb_strpos($table_class_file, '.'))) != '') {
                     \b2db\Core::getTable("\\thebuggenie\\modules\\" . $this->_name . "\\entities\\tables\\" . $tablename)->create();
                 }
             }
         }
         $this->_loadFixtures($scope);
     } catch (\Exception $e) {
         throw $e;
     }
 }
Пример #15
0
 public static function getAllModulePermissions($module, $uid, $tid, $gid)
 {
     $crit = new \b2db\Criteria();
     $crit->addWhere(TBGModulePermissionsTable::MODULE_NAME, $module);
     //$sql = "select b2mp.allowed from tbg_2_modulepermissions b2mp where b2mp.module_name = '$module'";
     switch (true) {
         case $uid != 0:
             //$sql .= " and uid = $uid";
             $crit->addWhere(TBGModulePermissionsTable::UID, $uid);
         case $tid != 0:
             //$sql .= " and tid = $tid";
             $crit->addWhere(TBGModulePermissionsTable::TID, $tid);
         case $gid != 0:
             //$sql .= " and gid = $gid";
             $crit->addWhere(TBGModulePermissionsTable::GID, $gid);
     }
     if ($uid + $tid + $gid == 0) {
         //$sql .= " and uid = $uid and tid = $tid and gid = $gid";
         $crit->addWhere(TBGModulePermissionsTable::UID, $uid);
         $crit->addWhere(TBGModulePermissionsTable::TID, $tid);
         $crit->addWhere(TBGModulePermissionsTable::GID, $gid);
     }
     //$sql .= " AND b2mp.scope = " . TBGContext::getScope()->getID();
     $crit->addWhere(TBGModulePermissionsTable::SCOPE, TBGContext::getScope()->getID());
     //$res = b2db_sql_query($sql, \b2db\Core::getDBlink());
     #print $sql;
     $permissions = array();
     $res = \b2db\Core::getTable('TBGModulePermissionsTable')->doSelect($crit);
     while ($row = $res->getNextRow()) {
         $permissions[] = array('allowed' => $row->get(TBGModulePermissionsTable::ALLOWED));
     }
     return $permissions;
 }
Пример #16
0
 /**
  * Cache all permissions
  */
 public static function cacheAllPermissions()
 {
     TBGLogging::log('caches permissions');
     self::$_permissions = array();
     if (!self::isInstallmode() && ($permissions = TBGCache::get(TBGCache::KEY_PERMISSIONS_CACHE))) {
         self::$_permissions = $permissions;
         TBGLogging::log('Using cached permissions');
     } else {
         if (self::isInstallmode() || !($permissions = TBGCache::fileGet(TBGCache::KEY_PERMISSIONS_CACHE))) {
             TBGLogging::log('starting to cache access permissions');
             if ($res = \b2db\Core::getTable('TBGPermissionsTable')->getAll()) {
                 while ($row = $res->getNextRow()) {
                     if (!array_key_exists($row->get(TBGPermissionsTable::MODULE), self::$_permissions)) {
                         self::$_permissions[$row->get(TBGPermissionsTable::MODULE)] = array();
                     }
                     if (!array_key_exists($row->get(TBGPermissionsTable::PERMISSION_TYPE), self::$_permissions[$row->get(TBGPermissionsTable::MODULE)])) {
                         self::$_permissions[$row->get(TBGPermissionsTable::MODULE)][$row->get(TBGPermissionsTable::PERMISSION_TYPE)] = array();
                     }
                     if (!array_key_exists($row->get(TBGPermissionsTable::TARGET_ID), self::$_permissions[$row->get(TBGPermissionsTable::MODULE)][$row->get(TBGPermissionsTable::PERMISSION_TYPE)])) {
                         self::$_permissions[$row->get(TBGPermissionsTable::MODULE)][$row->get(TBGPermissionsTable::PERMISSION_TYPE)][$row->get(TBGPermissionsTable::TARGET_ID)] = array();
                     }
                     self::$_permissions[$row->get(TBGPermissionsTable::MODULE)][$row->get(TBGPermissionsTable::PERMISSION_TYPE)][$row->get(TBGPermissionsTable::TARGET_ID)][] = array('uid' => $row->get(TBGPermissionsTable::UID), 'gid' => $row->get(TBGPermissionsTable::GID), 'tid' => $row->get(TBGPermissionsTable::TID), 'allowed' => (bool) $row->get(TBGPermissionsTable::ALLOWED));
                 }
             }
             TBGLogging::log('done (starting to cache access permissions)');
             if (!self::isInstallmode()) {
                 TBGCache::fileAdd(TBGCache::KEY_PERMISSIONS_CACHE, self::$_permissions);
             }
         } else {
             self::$_permissions = $permissions;
         }
         if (!self::isInstallmode()) {
             TBGCache::add(TBGCache::KEY_PERMISSIONS_CACHE, self::$_permissions);
         }
     }
     TBGLogging::log('...cached');
 }
Пример #17
0
 /**
  * Return an instance of TBGModulesTable
  *
  * @return TBGModulesTable
  */
 public static function getTable()
 {
     return Core::getTable('TBGModulesTable');
 }
Пример #18
0
 protected function _uninstall()
 {
     if (TBGContext::getScope()->getID() == 1) {
         TBGArticlesTable::getTable()->drop();
         \b2db\Core::getTable('TBGBillboardPostsTable')->drop();
     }
     TBGLinksTable::getTable()->removeByTargetTypeTargetIDandLinkID('wiki', 0);
     parent::_uninstall();
 }
Пример #19
0
 public function do_execute()
 {
     if (file_exists(THEBUGGENIE_PATH . 'installed')) {
         $this->cliEcho("The Bug Genie seems to already be installed.\n", 'red', 'bold');
         $this->cliEcho('Please remove the file ');
         $this->cliEcho(THEBUGGENIE_PATH . 'installed', 'white', 'bold');
         $this->cliEcho(' and try again.');
         $this->cliEcho("\n");
         return;
     }
     $this->cliEcho("\nWelcome to the \"The Bug Genie\" installation wizard!\n", 'white', 'bold');
     $this->cliEcho("This wizard will take you through the installation of The Bug Genie.\nRemember that you can also install The Bug Genie from your web-browser.\n");
     $this->cliEcho("Simply point your web-browser to the The Bug Genie subdirectory on your web server,\nand the installation will start.\n\n");
     $this->cliEcho("Press ENTER to continue with the installation: ");
     $this->pressEnterToContinue();
     $this->cliEcho("\n");
     $this->cliEcho("How to support future development\n", 'green', 'bold');
     $this->cliEcho("Even though this software has been provided to you free of charge,\ndeveloping it would not have been possible without support from our users.\n");
     $this->cliEcho("By making a donation, or buying a support contract you can help us continue development.\n\n");
     $this->cliEcho("If this software is valuable to you - please consider supporting it.\n\n");
     $this->cliEcho("More information about supporting The Bug Genie's development can be found here:\n");
     $this->cliEcho("http://www.thebuggenie.com/support\n\n", 'blue', 'underline');
     $this->cliEcho("Press ENTER to continue: ");
     $this->pressEnterToContinue();
     $this->cliEcho("\n");
     try {
         $this->cliEcho("License information\n", 'green', 'bold');
         $this->cliEcho("This software is Open Source Initiative approved Open Source Software.\nOpen Source Initiative Approved is a trademark of the Open Source Initiative.\n\n");
         $this->cliEcho("True to the the Open Source Definition, The Bug Genie is released\nunder the MPL 2.0. You can read the full license here:\n");
         $this->cliEcho("http://opensource.org/licenses/MPL-2.0\n\n", 'blue', 'underline');
         if ($this->getProvidedArgument('accept_license') != 'yes') {
             $this->cliEcho("Before you can continue the installation, you need to confirm that you \nagree to be bound by the terms in this license.\n\n");
             $this->cliEcho("Do you agree to be bound by the terms in the MPL 2.0 license?\n(type \"yes\" to agree, anything else aborts the installation): ");
             if (!$this->askToAccept()) {
                 throw new \Exception($this->cliEcho('You need to accept the license to continue', 'red', 'bold'));
             }
         } else {
             $this->cliEcho('You have accepted the license', 'yellow', 'bold');
             $this->cliEcho("\n\n");
         }
         $not_well = array();
         if (!is_writable(\THEBUGGENIE_CONFIGURATION_PATH)) {
             $not_well[] = 'b2db_perm';
         }
         if (!is_writable(THEBUGGENIE_PATH)) {
             $not_well[] = 'root';
         }
         if (count($not_well) > 0) {
             $this->cliEcho("\n");
             foreach ($not_well as $afail) {
                 switch ($afail) {
                     case 'b2db_perm':
                         $this->cliEcho("Could not write to the B2DB directory\n", 'red', 'bold');
                         $this->cliEcho('The folder ');
                         $this->cliEcho(\THEBUGGENIE_CONFIGURATION_PATH, 'white', 'bold');
                         $this->cliEcho(' folder needs to be writable');
                         break;
                     case 'root':
                         $this->cliEcho("Could not write to the main directory\n", 'red', 'bold');
                         $this->cliEcho('The top level folder must be writable during installation');
                         break;
                 }
             }
             throw new \Exception("\n\nYou need to correct the above errors before the installation can continue.");
         } else {
             $this->cliEcho("Step 1 - database information\n");
             if (file_exists($this->_b2db_config_file)) {
                 $this->cliEcho("You seem to already have completed this step successfully.\n");
                 if ($this->getProvidedArgument('use_existing_db_info') == 'yes') {
                     $this->cliEcho("\n");
                     $this->cliEcho("Using existing database information\n", 'yellow', 'bold');
                     $use_existing_db_info = true;
                 } else {
                     $this->cliEcho("Do you want to use the stored settings?\n", 'white', 'bold');
                     $this->cliEcho("\nType \"no\" to enter new settings, press ENTER to use existing: ", 'white', 'bold');
                     $use_existing_db_info = $this->askToDecline();
                 }
                 $this->cliEcho("\n");
             } else {
                 $use_existing_db_info = false;
             }
             if (!$use_existing_db_info) {
                 $this->cliEcho("The Bug Genie uses a database to store information. To be able to connect\nto your database, The Bug Genie needs some information, such as\ndatabase type, username, password, etc.\n\n");
                 $this->cliEcho("Please select what kind of database you are installing The Bug Genie on:\n");
                 $db_types = array();
                 foreach (\b2db\Core::getDBtypes() as $db_type => $db_desc) {
                     $db_types[] = $db_type;
                     $this->cliEcho(count($db_types) . ': ' . $db_desc . "\n", 'white', 'bold');
                 }
                 do {
                     $this->cliEcho('Enter the corresponding number for the database (1-' . count($db_types) . '): ');
                     $db_selection = $this->getInput();
                     if (!isset($db_types[(int) $db_selection - 1])) {
                         throw new \Exception($db_selection . ' is not a valid database type selection');
                     }
                     $db_type = $db_types[(int) $db_selection - 1];
                     $this->cliEcho("Selected database type: ");
                     $this->cliEcho($db_type . "\n\n");
                     $this->cliEcho("Please enter the database hostname: \n");
                     $this->cliEcho('Database hostname [localhost]: ', 'white', 'bold');
                     $db_hostname = $this->getInput();
                     $db_hostname = $db_hostname == '' ? 'localhost' : $db_hostname;
                     $this->cliEcho("\nPlease enter the username The Bug Genie will use to connect to the database: \n");
                     $this->cliEcho('Database username: '******'white', 'bold');
                     $db_username = $this->getInput();
                     $this->cliEcho("Database password (press ENTER if blank): ", 'white', 'bold');
                     $db_password = $this->getInput();
                     $this->cliEcho("\nPlease enter the database The Bug Genie will use.\nIf it does not exist, The Bug Genie will create it for you.\n(the default database name is ");
                     $this->cliEcho("thebuggenie_db", 'white', 'bold');
                     $this->cliEcho(" - press ENTER to use that):\n");
                     $this->cliEcho('Database name: ', 'white', 'bold');
                     $db_name = $this->getInput('thebuggenie_db');
                     $this->cliEcho("\n");
                     $this->cliEcho("The following settings will be used:\n");
                     $this->cliEcho("Database type: \t\t", 'white', 'bold');
                     $this->cliEcho($db_type . "\n");
                     $this->cliEcho("Database hostname: \t", 'white', 'bold');
                     $this->cliEcho($db_hostname . "\n");
                     $this->cliEcho("Database username: \t", 'white', 'bold');
                     $this->cliEcho($db_username . "\n");
                     $this->cliEcho("Database password: \t", 'white', 'bold');
                     $this->cliEcho($db_password . "\n");
                     $this->cliEcho("Database name: \t\t", 'white', 'bold');
                     $this->cliEcho($db_name . "\n");
                     $this->cliEcho("\nIf these settings are ok, press ENTER, or anything else to retry: ");
                     $e_ok = $this->askToDecline();
                 } while (!$e_ok);
                 try {
                     \b2db\Core::setHost($db_hostname);
                     \b2db\Core::setUname($db_username);
                     \b2db\Core::setPasswd($db_password);
                     \b2db\Core::setDBtype($db_type);
                     \b2db\Core::setTablePrefix('tbg_');
                     \b2db\Core::doConnect();
                     \b2db\Core::createDatabase($db_name);
                     \b2db\Core::setDBname($db_name);
                     \b2db\Core::doConnect();
                 } catch (\Exception $e) {
                     throw new \Exception("Could not connect to the database:\n" . $e->getMessage());
                 }
                 \b2db\Core::setDBname($db_name);
                 $this->cliEcho("\nSuccessfully connected to the database.\n", 'green');
                 $this->cliEcho("Press ENTER to continue ... ");
                 $this->pressEnterToContinue();
                 $this->cliEcho("\n");
                 $this->cliEcho("Saving database connection information ... ", 'white', 'bold');
                 $this->cliEcho("\n");
                 \b2db\Core::saveConnectionParameters($this->_b2db_config_file);
                 $this->cliEcho("Successfully saved database connection information.\n", 'green');
                 $this->cliEcho("\n");
             } else {
                 $b2db_config = \Spyc::YAMLLoad($this->_b2db_config_file);
                 if (!array_key_exists("b2db", $b2db_config)) {
                     throw new \Exception("Could not find database configuration in file " . $this->_b2db_config_file);
                 }
                 try {
                     \b2db\Core::initialize($b2db_config["b2db"], \thebuggenie\core\framework\Context::getCache());
                     \b2db\Core::doConnect();
                 } catch (\Exception $e) {
                     throw new \Exception("Could not connect to the database:\n" . $e->getMessage() . "\nPlease check your configuration file " . $this->_b2db_config_file);
                 }
                 $this->cliEcho("Successfully connected to the database.\n", 'green');
             }
             $this->cliEcho("\nThe Bug Genie needs some server settings to function properly...\n\n");
             do {
                 $this->cliEcho("URL rewriting\n", 'cyan', 'bold');
                 $this->cliEcho("The Bug Genie uses a technique called \"url rewriting\" - which allows for pretty\nURLs such as ") . $this->cliEcho('/issue/1', 'white', 'bold') . $this->cliEcho(' instead of ') . $this->cliEcho("viewissue.php?issue_id=1\n", 'white', 'bold');
                 $this->cliEcho("Make sure you have read the URL_REWRITE document located in the root\nfolder, or at http://www.thebuggenie.com before you continue\n");
                 if (!$this->hasProvidedArgument('url_subdir')) {
                     $this->cliEcho("Press ENTER to continue ... ");
                     $this->pressEnterToContinue();
                 }
                 $this->cliEcho("\n");
                 $this->cliEcho("The Bug Genie subdir\n", 'white', 'bold');
                 $this->cliEcho("This is the sub-path of the Web server where The Bug Genie will be located.\n");
                 if ($this->hasProvidedArgument('url_subdir')) {
                     $this->cliEcho('The Bug Genie subdir: ', 'white', 'bold');
                     $url_subdir = $this->getProvidedArgument('url_subdir');
                     $this->cliEcho($url_subdir, 'yellow', 'bold');
                     $this->cliEcho("\n");
                 } else {
                     $this->cliEcho('Start and end this with a forward slash', 'white', 'bold');
                     $this->cliEcho(". (ex: \"/thebuggenie/\")\nIf The Bug Genie is running at the root directory, just type \"/\" (without the quotes)\n\n");
                     $this->cliEcho('The Bug Genie subdir: ', 'white', 'bold');
                     $url_subdir = $this->getInput();
                 }
                 $this->cliEcho("\n");
                 $this->cliEcho("The Bug Genie will now be accessible at\n");
                 $this->cliEcho("http://example.com" . $url_subdir, 'white', 'bold');
                 if ($this->hasProvidedArgument('url_subdir')) {
                     $this->cliEcho("\n");
                     $this->cliEcho("Using existing values", 'yellow', 'bold');
                     $this->cliEcho("\n");
                     $e_ok = true;
                 } else {
                     $this->cliEcho("\nPress ENTER if ok, or \"no\" to try again: ");
                     $e_ok = $this->askToDecline();
                 }
                 $this->cliEcho("\n");
             } while (!$e_ok);
             if ($this->getProvidedArgument('setup_htaccess') != 'yes') {
                 $this->cliEcho("Setup can autoconfigure your .htaccess and .user.ini files (located in the thebuggenie/ subfolder), so you don't have to.\n");
                 $this->cliEcho('Would you like setup to auto-generate those files for you?');
                 $this->cliEcho("\nPress ENTER if ok, or \"no\" to not set up the .htaccess and .user.ini files: ");
                 $htaccess_ok = $this->askToDecline();
             } else {
                 $this->cliEcho('Autoconfiguring .htaccess and .user.ini', 'yellow', 'bold');
                 $this->cliEcho("\n");
                 $htaccess_ok = true;
             }
             $this->cliEcho("\n");
             if ($htaccess_ok) {
                 if (!is_writable(THEBUGGENIE_PATH . 'thebuggenie/') || file_exists(THEBUGGENIE_PATH . 'thebuggenie/.htaccess') && !is_writable(THEBUGGENIE_PATH . 'thebuggenie/.htaccess')) {
                     $this->cliEcho("Permission denied when trying to save the [main folder]/thebuggenie/.htaccess\n", 'red', 'bold');
                     $this->cliEcho("You will have to set up the .htaccess file yourself. See the README file for more information.\n", 'white', 'bold');
                     $this->cliEcho('Please note: ', 'white', 'bold');
                     $this->cliEcho("The Bug Genie will not function properly until the .htaccess file is properly set up!\n");
                 } else {
                     $content = str_replace('###PUT URL SUBDIRECTORY HERE###', $url_subdir, file_get_contents(THEBUGGENIE_CORE_PATH . 'templates/htaccess.template'));
                     file_put_contents(THEBUGGENIE_PATH . 'thebuggenie/.htaccess', $content);
                     if (file_get_contents(THEBUGGENIE_PATH . 'thebuggenie/.htaccess') != $content) {
                         $this->cliEcho("Permission denied when trying to save the [main folder]/thebuggenie/.htaccess\n", 'red', 'bold');
                         $this->cliEcho("You will have to set up the .htaccess file yourself. See the README file for more information.\n", 'white', 'bold');
                         $this->cliEcho('Please note: ', 'white', 'bold');
                         $this->cliEcho("The Bug Genie will not function properly until the .htaccess file is properly set up!\n");
                     } else {
                         $this->cliEcho("The .htaccess file was successfully set up...\n", 'green', 'bold');
                     }
                 }
                 if (!is_writable(THEBUGGENIE_PATH . 'thebuggenie/') || file_exists(THEBUGGENIE_PATH . 'thebuggenie/.user.ini') && !is_writable(THEBUGGENIE_PATH . 'thebuggenie/.user.ini')) {
                     $this->cliEcho("Permission denied when trying to save the [main folder]/thebuggenie/.user.ini\n", 'red', 'bold');
                     $this->cliEcho("You will have to set up the .user.ini file yourself. See the README file for more information.\n", 'white', 'bold');
                     $this->cliEcho('Please note: ', 'white', 'bold');
                     $this->cliEcho("If you're using PHP-FPM, The Bug Genie might not function properly until the .user.ini file is properly set up\n");
                 } else {
                     $content = file_get_contents(THEBUGGENIE_CORE_PATH . 'templates/htaccess.template');
                     file_put_contents(THEBUGGENIE_PATH . 'thebuggenie/.user.ini', $content);
                     if (file_get_contents(THEBUGGENIE_PATH . 'thebuggenie/.user.ini') != $content) {
                         $this->cliEcho("Permission denied when trying to save the [main folder]/thebuggenie/.user.ini\n", 'red', 'bold');
                         $this->cliEcho("You will have to set up the .user.ini file yourself. See the README file for more information.\n", 'white', 'bold');
                         $this->cliEcho('Please note: ', 'white', 'bold');
                         $this->cliEcho("If you're using PHP-FPM, The Bug Genie might not function properly until the .user.ini file is properly set up\n");
                     } else {
                         $this->cliEcho("The .user.ini file was successfully set up...\n", 'green', 'bold');
                     }
                 }
             } else {
                 $this->cliEcho("Skipping .htaccess and .user.ini auto-setup.");
             }
             if ($this->getProvidedArgument('setup_htaccess') != 'yes') {
                 $this->cliEcho("Press ENTER to continue ... ");
                 $this->pressEnterToContinue();
                 $this->cliEcho("\n");
             }
             $this->cliEcho("\n");
             $this->cliEcho("Creating tables ...\n", 'white', 'bold');
             $b2db_entities_path = THEBUGGENIE_CORE_PATH . 'entities' . DS . 'tables' . DS;
             $tables_created = array();
             foreach (scandir($b2db_entities_path) as $tablefile) {
                 if (in_array($tablefile, array('.', '..'))) {
                     continue;
                 }
                 if (($tablename = mb_substr($tablefile, 0, mb_strpos($tablefile, '.'))) != '') {
                     $tablename = "\\thebuggenie\\core\\entities\\tables\\{$tablename}";
                     $reflection = new \ReflectionClass($tablename);
                     $docblock = $reflection->getDocComment();
                     $annotationset = new \b2db\AnnotationSet($docblock);
                     if ($annotationset->hasAnnotation('Table')) {
                         \b2db\Core::getTable($tablename)->create();
                         \b2db\Core::getTable($tablename)->createIndexes();
                         $tables_created[] = $tablename;
                     }
                 }
             }
             $this->cliEcho("\n");
             $this->cliEcho("All tables successfully created...\n\n", 'green', 'bold');
             $this->cliEcho("Setting up initial scope... \n", 'white', 'bold');
             \thebuggenie\core\framework\Context::reinitializeI18n('en_US');
             $scope = new \thebuggenie\core\entities\Scope();
             $scope->setName('The default scope');
             $scope->addHostname('*');
             $scope->setEnabled();
             \thebuggenie\core\framework\Context::setScope($scope);
             $scope->save();
             \thebuggenie\core\framework\Settings::saveSetting('language', 'en_US');
             $this->cliEcho("Initial scope setup successfully... \n\n", 'green', 'bold');
             $this->cliEcho("Setting up modules... \n", 'white', 'bold');
             try {
                 foreach (array('publish', 'mailing', 'vcs_integration') as $module) {
                     $this->cliEcho("Installing {$module}... \n");
                     \thebuggenie\core\entities\Module::installModule($module);
                 }
                 $this->cliEcho("\n");
                 $this->cliEcho("All modules installed successfully...\n", 'green', 'bold');
                 $this->cliEcho("\n");
                 $this->cliEcho("Finishing installation... \n", 'white', 'bold');
                 $installed_string = \thebuggenie\core\framework\Settings::getMajorVer() . '.' . \thebuggenie\core\framework\Settings::getMinorVer() . ', installed ' . date('d.m.Y H:i');
                 if (file_exists(THEBUGGENIE_PATH . 'installed') && !is_writable(THEBUGGENIE_PATH . 'installed') || !file_exists(THEBUGGENIE_PATH . 'installed') && !is_writable(THEBUGGENIE_PATH)) {
                     $this->cliEcho("\n");
                     $this->cliEcho("Could not create the 'installed' file.\n", 'red', 'bold');
                     $this->cliEcho("Please create the file ");
                     $this->cliEcho(THEBUGGENIE_PATH . "installed\n", 'white', 'bold');
                     $this->cliEcho("with the following line inside:\n");
                     $this->cliEcho($installed_string, 'blue', 'bold');
                     $this->cliEcho("\n");
                     $this->cliEcho("This can be done by running the following command when installation has finished:\n");
                     $this->cliEcho('echo "' . $installed_string . '" > ' . THEBUGGENIE_PATH . 'installed', 'white', 'bold');
                     $this->cliEcho("\n");
                     $this->cliEcho("Press ENTER to continue ... ");
                     $this->pressEnterToContinue();
                     $this->cliEcho("\n");
                     $this->cliEcho("\n");
                 } else {
                     file_put_contents(THEBUGGENIE_PATH . 'installed', $installed_string);
                 }
                 $this->cliEcho("The installation was completed successfully!\n", 'green', 'bold');
                 $this->cliEcho("\nTo use The Bug Genie, access http://example.com" . $url_subdir . "index.php with a web-browser.\n");
                 $this->cliEcho("The default username is ") . $this->cliEcho('Administrator') . $this->cliEcho(' and the password is ') . $this->cliEcho('admin');
                 $this->cliEcho("\n\nFor support, please visit ") . $this->cliEcho('http://www.thebuggenie.com/', 'blue', 'underline');
                 $this->cliEcho("\n");
             } catch (\Exception $e) {
                 throw new \Exception("Could not install the {$module} module:\n" . $e->getMessage());
             }
         }
     } catch (\Exception $e) {
         $this->cliEcho("\n\nThe installation was interrupted\n", 'red');
         $this->cliEcho($e->getMessage() . "\n");
     }
     $this->cliEcho("\n");
 }
Пример #20
0
 /**
  * Adds this build to all open issues in this edition or project
  * Returns true if any issues were updated, false if not
  * 
  * @param integer $limit_status Limit to only a specific status type
  * @param integer $limit_category Limit to only a specific category
  * @param integer $limit_issuetype Limit to only a specific issue type
  * 
  * @return boolean
  */
 public function addToOpenParentIssues($limit_status = null, $limit_category = null, $limit_issuetype = null)
 {
     if ($this->isEditionBuild()) {
         $res = \b2db\Core::getTable('TBGIssueAffectsEditionTable')->getOpenAffectedIssuesByEditionID($this->getParent()->getID(), $limit_status, $limit_category, $limit_issuetype);
     } else {
         $res = TBGIssuesTable::getTable()->getOpenAffectedIssuesByProjectID($this->getParent()->getID(), $limit_status, $limit_category, $limit_issuetype);
     }
     $retval = false;
     if ($res) {
         while ($row = $res->getNextRow()) {
             $issue_id = $row->get(TBGIssuesTable::ID);
             if (\b2db\Core::getTable('TBGIssueAffectsBuildTable')->setIssueAffected($issue_id, $this->getID())) {
                 $retval = true;
             }
         }
     }
     return $retval;
 }
Пример #21
0
 protected function _upgrade()
 {
     switch ($this->_version) {
         case "1.0":
             // Upgrade tables
             \b2db\Core::getTable('TBGVCSIntegrationCommitsTable')->create();
             \b2db\Core::getTable('TBGVCSIntegrationFilesTable')->create();
             \b2db\Core::getTable('TBGVCSIntegrationIssueLinksTable')->create();
             TBGVCSIntegrationCommitsTable::getTable()->createIndexes();
             TBGVCSIntegrationFilesTable::getTable()->createIndexes();
             TBGVCSIntegrationIssueLinksTable::getTable()->createIndexes();
             // Migrate data from old table to new tables
             $crit = new \b2db\Criteria();
             $crit->addOrderBy(TBGVCSIntegrationTable::DATE, \b2db\Criteria::SORT_DESC);
             $results = TBGVCSIntegrationTable::getTable()->doSelect($crit);
             if ($results instanceof \b2db\Resultset && $results->count() > 0) {
                 $commits = array();
                 while ($row = $results->getNextRow()) {
                     $rev = $row->get(TBGVCSIntegrationTable::NEW_REV);
                     if (array_key_exists($rev, $commits)) {
                         // Add a new file or issue to the commit data
                         $commits[$rev]['files'][$row->get(TBGVCSIntegrationTable::FILE_NAME)] = array('file_name' => $row->get(TBGVCSIntegrationTable::FILE_NAME), 'action' => $row->get(TBGVCSIntegrationTable::ACTION));
                         $commits[$rev]['issues'][$row->get(TBGVCSIntegrationTable::ISSUE_NO)] = $row->get(TBGVCSIntegrationTable::ISSUE_NO);
                     } else {
                         // All issues will be of the same project, so use one issue
                         $issue = TBGContext::factory()->TBGIssue($results->get(TBGVCSIntegrationTable::ISSUE_NO));
                         // Add details of a new commit
                         $commits[$rev] = array('commit' => array(), 'files' => array(), 'issues' => array());
                         $commits[$rev]['commit'] = array('new_rev' => $rev, 'old_rev' => $row->get(TBGVCSIntegrationTable::OLD_REV), 'author' => $row->get(TBGVCSIntegrationTable::AUTHOR), 'date' => $row->get(TBGVCSIntegrationTable::DATE), 'log' => $row->get(TBGVCSIntegrationTable::LOG), 'scope' => $row->get(TBGVCSIntegrationTable::SCOPE), 'project' => $issue->getProject());
                         $commits[$rev]['files'][$row->get(TBGVCSIntegrationTable::FILE_NAME)] = array('file_name' => $row->get(TBGVCSIntegrationTable::FILE_NAME), 'action' => $row->get(TBGVCSIntegrationTable::ACTION));
                         $commits[$rev]['issues'][$row->get(TBGVCSIntegrationTable::ISSUE_NO)] = $row->get(TBGVCSIntegrationTable::ISSUE_NO);
                     }
                 }
                 foreach ($commits as $commit) {
                     $files = array();
                     $issues = array();
                     $scope = TBGContext::factory()->TBGScope($commit['commit']['scope']);
                     try {
                         $author = TBGContext::factory()->TBGUser($commit['commit']['author']);
                     } catch (Exception $e) {
                         $author = TBGContext::factory()->TBGUser(TBGSettings::getDefaultUserID());
                     }
                     if (!$author instanceof TBGUser) {
                         $author = TBGContext::factory()->TBGUser(TBGSettings::getDefaultUserID());
                     }
                     // Add the commit
                     $inst = new TBGVCSIntegrationCommit();
                     $inst->setAuthor($author);
                     $inst->setDate($commit['commit']['date']);
                     $inst->setLog($commit['commit']['log']);
                     $inst->setPreviousRevision($commit['commit']['old_rev']);
                     $inst->setRevision($commit['commit']['new_rev']);
                     $inst->setProject($commit['commit']['project']);
                     $inst->setScope($scope);
                     $inst->save();
                     // Process issue list, remove duplicates
                     $issues = $commit['issues'];
                     $files = $commit['files'];
                     $commit = $inst;
                     foreach ($files as $file) {
                         // Add affected files
                         $inst = new TBGVCSIntegrationFile();
                         $inst->setCommit($commit);
                         $inst->setFile($file['file_name']);
                         $inst->setAction($file['action']);
                         $inst->setScope($scope);
                         $inst->save();
                     }
                     foreach ($issues as $issue) {
                         // Add affected issues
                         $issue = TBGContext::factory()->TBGIssue($issue);
                         $inst = new TBGVCSIntegrationIssueLink();
                         $inst->setIssue($issue);
                         $inst->setCommit($commit);
                         $inst->setScope($scope);
                         $inst->save();
                     }
                 }
             }
             // Migrate settings to new format
             $access_method = $this->getSetting('use_web_interface');
             $passkey = $this->getSetting('vcs_passkey');
             foreach (TBGProject::getAll() as $project) {
                 $projectId = $project->getID();
                 $web_path = $this->getSetting('web_path_' . $projectId);
                 $web_repo = $this->getSetting('web_repo_' . $projectId);
                 // Check if enabled
                 if ($web_path == '') {
                     continue;
                 }
                 switch ($this->getSetting('web_type_' . $projectId)) {
                     case 'viewvc':
                         $base_url = $web_path . '/' . '?root=' . $web_repo;
                         $link_rev = '&view=rev&revision=%revno';
                         $link_file = '&view=log';
                         $link_diff = '&r1=%revno&r2=%oldrev';
                         $link_view = '&revision=%revno&view=markup';
                         break;
                     case 'viewvc_repo':
                         $base_url = $web_path;
                         $link_rev = '/?view=rev&revision=%revno';
                         $link_file = '/%file?view=log';
                         $link_diff = '/%file?r1=%revno&r2=%oldrev';
                         $link_view = '/%file?revision=%revno&view=markup';
                         break;
                     case 'websvn':
                         $base_url = $web_path;
                         $link_rev = '/revision.php?repname=' . $web_repo . '&isdir=1&rev=%revno';
                         $link_file = '/log.php?repname=' . $web_repo . '&path=/$%file';
                         $link_diff = '/comp.php?repname=' . $web_repo . '&compare[]=/%file@%revno&compare[]=/%file@%oldrev';
                         $link_view = '/filedetails.php?repname=' . $web_repo . '&path=/%file&rev=%revno';
                         break;
                     case 'websvn_mv':
                         $base_url = $web_path;
                         $link_rev = '/' . '?repname=' . $web_repo . '&op=log&isdir=1&rev=%revno';
                         $link_file = '/%file?repname=' . $web_repo;
                         $link_diff = '/%file?repname=' . $web_repo . '&compare[]=/%file@%revno&compare[]=/%file@%oldrev';
                         $link_view = '/%file?repname=' . $web_repo . '&rev=%revno';
                         break;
                     case 'loggerhead':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/revision/%revno';
                         $link_file = '/changes';
                         $link_diff = '/revision/%revno?compare_revid=%oldrev';
                         $link_view = '/annotate/head:/%file';
                         break;
                     case 'gitweb':
                         $base_url = $web_path . '/' . '?p=' . $web_repo;
                         $link_rev = ';a=commitdiff;h=%revno';
                         $link_file = ';a=history;f=%file;hb=HEAD';
                         $link_diff = ';a=blobdiff;f=%file;hb=%revno;hpb=%oldrev';
                         $link_view = ';a=blob;f=%file;hb=%revno';
                         break;
                     case 'cgit':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/commit/?id=%revno';
                         $link_file = '/log';
                         $link_diff = '/diff/%file?id=%revno?id2=%oldrev';
                         $link_view = '/tree/%file?id=%revno';
                         break;
                     case 'hgweb':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/rev/%revno';
                         $link_file = '/log/tip/%file';
                         $link_diff = '/diff/%revno/%file';
                         $link_view = '/file/%revno/%file';
                         break;
                     case 'github':
                         $base_url = 'http://github.com/' . $web_repo;
                         $link_rev = '/commit/%revno';
                         $link_file = '/commits/master/%file';
                         $link_diff = '/commit/%revno';
                         $link_view = '/blob/%revno/%file';
                         break;
                     case 'gitlab':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/commit/%revno';
                         $link_file = '/commits/%branch/%file';
                         $link_diff = '/commit/%revno';
                         $link_view = '/blob/%revno/%file';
                         break;
                     case 'bitbucket':
                         $base_url = 'https://bitbucket.org/' . $web_repo;
                         $link_rev = '/changeset/%revno';
                         $link_file = '/history/%file';
                         $link_diff = '/changeset/%revno#chg-%file';
                         $link_view = '/src/%revno/%file';
                         break;
                     case 'gitorious':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/commit/%revno';
                         $link_file = '/blobs/history/master/%file';
                         $link_diff = '/commit/%revno';
                         $link_view = '/blobs/%revno/%file';
                         break;
                     case 'rhodecode':
                         $base_url = $web_path . '/' . $web_repo;
                         $link_rev = '/changeset/%revno';
                         $link_file = '/changelog/%revno/%file';
                         $link_diff = '/diff/%file?diff2=%revno&diff1=%oldrev&fulldiff=1&diff=diff';
                         $link_view = '/files/%revno/%file';
                         break;
                 }
                 $this->saveSetting('browser_url_' . $projectId, $base_url);
                 $this->saveSetting('log_url_' . $projectId, $link_file);
                 $this->saveSetting('blob_url_' . $projectId, $link_diff);
                 $this->saveSetting('diff_url_' . $projectId, $link_view);
                 $this->saveSetting('commit_url_' . $projectId, $link_rev);
                 // Access method
                 $this->saveSetting('access_method_' . $projectId, $access_method);
                 if ($access_method == self::ACCESS_HTTP) {
                     $this->saveSetting('access_passkey_' . $projectId, $passkey);
                 }
                 // Enable VCS Integration
                 $this->saveSetting('vcs_mode_' . $projectId, self::MODE_ISSUECOMMITS);
                 // Remove old settings
                 $this->deleteSetting('web_type_' . $projectId);
                 $this->deleteSetting('web_path_' . $projectId);
                 $this->deleteSetting('web_repo_' . $projectId);
             }
             // Remove old settings
             $this->deleteSetting('use_web_interface');
             $this->deleteSetting('vcs_passkey');
             // Upgrade module version
             $this->_version = $this->_module_version;
             $this->save();
             break;
     }
 }
Пример #22
0
 /**
  * Return an array specifying visibility, requirement and choices for fields in issues
  * 
  * @param integer $issue_type
  * @param boolean $reportable[optional] Whether to only include fields that can be reported
  * 
  * @return array
  */
 protected function _getFieldsArray($issue_type, $reportable = true)
 {
     $issue_type = is_object($issue_type) ? $issue_type->getID() : $issue_type;
     if (!isset($this->_fieldsarrays[$issue_type][(int) $reportable])) {
         $retval = array();
         $res = \b2db\Core::getTable('TBGIssueFieldsTable')->getBySchemeIDandIssuetypeID($this->getIssuetypeScheme()->getID(), $issue_type);
         if ($res) {
             $builtin_types = TBGDatatype::getAvailableFields(true);
             while ($row = $res->getNextRow()) {
                 if (!$reportable || (bool) $row->get(TBGIssueFieldsTable::REPORTABLE) == true) {
                     if ($reportable) {
                         if (in_array($row->get(TBGIssueFieldsTable::FIELD_KEY), $builtin_types) && (!$this->fieldPermissionCheck($row->get(TBGIssueFieldsTable::FIELD_KEY), $reportable) && !($row->get(TBGIssueFieldsTable::REQUIRED) && $reportable))) {
                             continue;
                         } elseif (!in_array($row->get(TBGIssueFieldsTable::FIELD_KEY), $builtin_types) && (!$this->fieldPermissionCheck($row->get(TBGIssueFieldsTable::FIELD_KEY), $reportable, true) && !($row->get(TBGIssueFieldsTable::REQUIRED) && $reportable))) {
                             continue;
                         }
                     }
                     $field_key = $row->get(TBGIssueFieldsTable::FIELD_KEY);
                     $retval[$field_key] = array('required' => (bool) $row->get(TBGIssueFieldsTable::REQUIRED), 'additional' => (bool) $row->get(TBGIssueFieldsTable::ADDITIONAL));
                     if (!in_array($field_key, $builtin_types)) {
                         $retval[$field_key]['custom'] = true;
                         $custom_type = TBGCustomDatatype::getByKey($field_key);
                         if ($custom_type instanceof TBGCustomDatatype) {
                             $retval[$field_key]['custom_type'] = $custom_type->getType();
                         } else {
                             unset($retval[$field_key]);
                         }
                     }
                 }
             }
             if (array_key_exists('user_pain', $retval)) {
                 $retval['pain_bug_type'] = array('required' => $retval['user_pain']['required']);
                 $retval['pain_likelihood'] = array('required' => $retval['user_pain']['required']);
                 $retval['pain_effect'] = array('required' => $retval['user_pain']['required']);
             }
             if ($reportable) {
                 foreach ($retval as $key => $return_details) {
                     if ($key == 'edition' || array_key_exists('custom', $return_details) && $return_details['custom'] && $return_details['custom_type'] == TBGCustomDatatype::EDITIONS_CHOICE) {
                         $retval[$key]['values'] = array();
                         $retval[$key]['values'][''] = TBGContext::getI18n()->__('None');
                         foreach ($this->getEditions() as $edition) {
                             $retval[$key]['values'][$edition->getID()] = $edition->getName();
                         }
                         if (!$this->isEditionsEnabled() || empty($retval[$key]['values'])) {
                             if (!$retval[$key]['required']) {
                                 unset($retval[$key]);
                             } else {
                                 unset($retval[$key]['values']);
                             }
                         }
                         if (array_key_exists($key, $retval) && array_key_exists('values', $retval[$key])) {
                             asort($retval[$key]['values'], SORT_STRING);
                         }
                     } elseif ($key == 'status' || array_key_exists('custom', $return_details) && $return_details['custom'] && $return_details['custom_type'] == TBGCustomDatatype::STATUS_CHOICE) {
                         $retval[$key]['values'] = array();
                         foreach (TBGStatus::getAll() as $status) {
                             $retval[$key]['values'][$status->getID()] = $status->getName();
                         }
                         if (empty($retval[$key]['values'])) {
                             if (!$retval[$key]['required']) {
                                 unset($retval[$key]);
                             } else {
                                 unset($retval[$key]['values']);
                             }
                         }
                         if (array_key_exists($key, $retval) && array_key_exists('values', $retval[$key])) {
                             asort($retval[$key]['values'], SORT_STRING);
                         }
                     } elseif ($key == 'component' || array_key_exists('custom', $return_details) && $return_details['custom'] && $return_details['custom_type'] == TBGCustomDatatype::COMPONENTS_CHOICE) {
                         $retval[$key]['values'] = array();
                         $retval[$key]['values'][''] = TBGContext::getI18n()->__('None');
                         foreach ($this->getComponents() as $component) {
                             $retval[$key]['values'][$component->getID()] = $component->getName();
                         }
                         if (!$this->isComponentsEnabled() || empty($retval[$key]['values'])) {
                             if (!$retval[$key]['required']) {
                                 unset($retval[$key]);
                             } else {
                                 unset($retval[$key]['values']);
                             }
                         }
                         if (array_key_exists($key, $retval) && array_key_exists('values', $retval[$key])) {
                             asort($retval[$key]['values'], SORT_STRING);
                         }
                     } elseif ($key == 'build' || array_key_exists('custom', $return_details) && $return_details['custom'] && $return_details['custom_type'] == TBGCustomDatatype::RELEASES_CHOICE) {
                         $retval[$key]['values'] = array();
                         $retval[$key]['values'][''] = TBGContext::getI18n()->__('None');
                         foreach ($this->getBuilds() as $build) {
                             if ($build->isLocked()) {
                                 continue;
                             }
                             $retval[$key]['values'][$build->getID()] = $build->getName() . ' (' . $build->getVersion() . ')';
                         }
                         if (!$this->isBuildsEnabled() || empty($retval[$key]['values'])) {
                             if (!$retval[$key]['required']) {
                                 unset($retval[$key]);
                             } else {
                                 unset($retval[$key]['values']);
                             }
                         }
                     } elseif ($key == 'milestone') {
                         $retval[$key]['values'] = array();
                         $retval[$key]['values'][''] = TBGContext::getI18n()->__('None');
                         foreach ($this->getMilestones() as $milestone) {
                             $retval[$key]['values'][$milestone->getID()] = $milestone->getName();
                         }
                         if (empty($retval[$key]['values'])) {
                             if (!$retval[$key]['required']) {
                                 unset($retval[$key]);
                             } else {
                                 unset($retval[$key]['values']);
                             }
                         }
                     }
                 }
             }
         }
         $this->_fieldsarrays[$issue_type][(int) $reportable] = $retval;
     }
     return $this->_fieldsarrays[$issue_type][(int) $reportable];
 }
Пример #23
0
 public function runDetachFile(TBGrequest $request)
 {
     try {
         switch ($request['mode']) {
             case 'issue':
                 $issue = TBGContext::factory()->TBGIssue($request['issue_id']);
                 if ($issue->canRemoveAttachments() && (int) $request->getParameter('file_id', 0)) {
                     \b2db\Core::getTable('TBGIssueFilesTable')->removeByIssueIDAndFileID($issue->getID(), (int) $request['file_id']);
                     return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($issue->getFiles()) + count($issue->getLinks()), 'message' => TBGContext::getI18n()->__('The attachment has been removed')));
                 }
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You can not remove items from this issue')));
                 break;
             case 'article':
                 $article = TBGWikiArticle::getByName($request['article_name']);
                 if ($article instanceof TBGWikiArticle && $article->canEdit() && (int) $request->getParameter('file_id', 0)) {
                     $article->removeFile(TBGContext::factory()->TBGFile((int) $request['file_id']));
                     return $this->renderJSON(array('file_id' => $request['file_id'], 'attachmentcount' => count($article->getFiles()), 'message' => TBGContext::getI18n()->__('The attachment has been removed')));
                 }
                 $this->getResponse()->setHttpStatus(400);
                 return $this->renderJSON(array('error' => TBGContext::getI18n()->__('You can not remove items from this issue')));
                 break;
         }
     } catch (Exception $e) {
         throw $e;
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('error' => TBGContext::getI18n()->__('Invalid mode')));
 }
Пример #24
0
 private static function _loadSetting($name, $module = 'core', $scope = 0)
 {
     $crit = new \b2db\Criteria();
     $crit->addWhere(TBGSettingsTable::NAME, $name);
     $crit->addWhere(TBGSettingsTable::MODULE, $module);
     if ($scope == 0) {
         throw new Exception('The Bug Genie has not been correctly installed. Please check that the default scope exists');
     }
     $crit->addWhere(TBGSettingsTable::SCOPE, $scope);
     $res = \b2db\Core::getTable('TBGSettingsTable')->doSelect($crit);
     if ($res) {
         $retarr = array();
         while ($row = $res->getNextRow()) {
             $retarr[$row->get(TBGSettingsTable::UID)] = $row->get(TBGSettingsTable::VALUE);
         }
         return $retarr;
     } else {
         return null;
     }
 }
Пример #25
0
 /**
  * Remove a link
  * 
  * @param integer $link_id The link ID to remove
  */
 public function removeLink($link_id)
 {
     if ($res = \b2db\Core::getTable('TBGLinksTable')->removeByIssueIDandLinkID($this->getID(), $link_id)) {
         if (is_array($this->_links) && array_key_exists($link_id, $this->_links)) {
             unset($this->_links[$link_id]);
         }
     }
 }
Пример #26
0
 public function hasLinkedWorkflowStep()
 {
     return (bool) \b2db\Core::getTable('TBGWorkflowStepsTable')->countByStatusID($this->getID());
 }
Пример #27
0
 /**
  * Runs the action for the third step of the installation
  * where it tests the connection, sets up the database and the initial scope
  * 
  * @param TBGRequest $request The request object
  * 
  * @return null
  */
 public function runInstallStep3(TBGRequest $request)
 {
     $this->selected_connection_detail = $request['connection_type'];
     try {
         if ($this->username = $request['db_username']) {
             \b2db\Core::setUname($this->username);
             \b2db\Core::setTablePrefix($request['db_prefix']);
             if ($this->password = $request->getRawParameter('db_password')) {
                 \b2db\Core::setPasswd($this->password);
             }
             if ($this->selected_connection_detail == 'dsn') {
                 if (($this->dsn = $request['db_dsn']) != '') {
                     \b2db\Core::setDSN($this->dsn);
                 } else {
                     throw new Exception('You must provide a valid DSN');
                 }
             } else {
                 if ($this->db_type = $request['db_type']) {
                     \b2db\Core::setDBtype($this->db_type);
                     if ($this->db_hostname = $request['db_hostname']) {
                         \b2db\Core::setHost($this->db_hostname);
                     } else {
                         throw new Exception('You must provide a database hostname');
                     }
                     if ($this->db_port = $request['db_port']) {
                         \b2db\Core::setPort($this->db_port);
                     }
                     if ($this->db_databasename = $request['db_name']) {
                         \b2db\Core::setDBname($this->db_databasename);
                     } else {
                         throw new Exception('You must provide a database to use');
                     }
                 } else {
                     throw new Exception('You must provide a database type');
                 }
             }
             \b2db\Core::initialize(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php');
             \b2db\Core::doConnect();
             if (\b2db\Core::getDBname() == '') {
                 throw new Exception('You must provide a database to use');
             }
             \b2db\Core::saveConnectionParameters(THEBUGGENIE_CORE_PATH . 'b2db_bootstrap.inc.php');
         } else {
             throw new Exception('You must provide a database username');
         }
         // Add table classes to classpath
         $tables_path = THEBUGGENIE_CORE_PATH . 'classes' . DS . 'B2DB' . DS;
         TBGContext::addAutoloaderClassPath($tables_path);
         $tables_path_handle = opendir($tables_path);
         $tables_created = array();
         while ($table_class_file = readdir($tables_path_handle)) {
             if (($tablename = mb_substr($table_class_file, 0, mb_strpos($table_class_file, '.'))) != '') {
                 \b2db\Core::getTable($tablename)->create();
                 \b2db\Core::getTable($tablename)->createIndexes();
                 $tables_created[] = $tablename;
             }
         }
         sort($tables_created);
         $this->tables_created = $tables_created;
         //TBGScope::setupInitialScope();
     } catch (Exception $e) {
         throw $e;
         $this->error = $e->getMessage();
     }
 }
Пример #28
0
 /**
  * Runs the action for the third step of the installation
  * where it tests the connection, sets up the database and the initial scope
  *
  * @param framework\Request $request The request object
  *
  * @return null
  */
 public function runInstallStep3(framework\Request $request)
 {
     $this->selected_connection_detail = $request['connection_type'];
     try {
         if ($this->username = $request['db_username']) {
             \b2db\Core::setUname($this->username);
             \b2db\Core::setTablePrefix($request['db_prefix']);
             if ($this->password = $request->getRawParameter('db_password')) {
                 \b2db\Core::setPasswd($this->password);
             }
             if ($this->selected_connection_detail == 'dsn') {
                 if (($this->dsn = $request['db_dsn']) != '') {
                     \b2db\Core::setDSN($this->dsn);
                 } else {
                     throw new \Exception('You must provide a valid DSN');
                 }
             } else {
                 if ($this->db_type = $request['db_type']) {
                     \b2db\Core::setDBtype($this->db_type);
                     if ($this->db_hostname = $request['db_hostname']) {
                         \b2db\Core::setHost($this->db_hostname);
                     } else {
                         throw new \Exception('You must provide a database hostname');
                     }
                     if ($this->db_port = $request['db_port']) {
                         \b2db\Core::setPort($this->db_port);
                     }
                     if ($this->db_databasename = $request['db_name']) {
                         \b2db\Core::setDBname($this->db_databasename);
                     } else {
                         throw new \Exception('You must provide a database to use');
                     }
                 } else {
                     throw new \Exception('You must provide a database type');
                 }
             }
             try {
                 \b2db\Core::doConnect();
             } catch (\b2db\Exception $e) {
                 throw new \Exception('There was an error connecting to the database: ' . $e->getMessage());
             }
             if (\b2db\Core::getDBname() == '') {
                 throw new \Exception('You must provide a database to use');
             }
             \b2db\Core::saveConnectionParameters(\THEBUGGENIE_CONFIGURATION_PATH . "b2db.yml");
         } else {
             throw new \Exception('You must provide a database username');
         }
         // Create v4 tables
         $b2db_entities_path = THEBUGGENIE_CORE_PATH . 'entities' . DS . 'tables' . DS;
         $tables_created = array();
         foreach (scandir($b2db_entities_path) as $tablefile) {
             if (in_array($tablefile, array('.', '..'))) {
                 continue;
             }
             if (($tablename = mb_substr($tablefile, 0, mb_strpos($tablefile, '.'))) != '') {
                 $tablename = "\\thebuggenie\\core\\entities\\tables\\{$tablename}";
                 $reflection = new \ReflectionClass($tablename);
                 $docblock = $reflection->getDocComment();
                 $annotationset = new \b2db\AnnotationSet($docblock);
                 if ($annotationset->hasAnnotation('Table')) {
                     \b2db\Core::getTable($tablename)->create();
                     \b2db\Core::getTable($tablename)->createIndexes();
                     $tables_created[] = $tablename;
                 }
             }
         }
         sort($tables_created);
         $this->tables_created = $tables_created;
     } catch (\Exception $e) {
         $this->error = $e->getMessage();
     }
     $server_type = strtolower(trim($_SERVER['SERVER_SOFTWARE']));
     switch (true) {
         case stripos($server_type, 'apache') !== false:
             $this->server_type = 'apache';
             break;
         case stripos($server_type, 'nginx') !== false:
             $this->server_type = 'nginx';
             break;
         case stripos($server_type, 'iis') !== false:
             $this->server_type = 'iis';
             break;
         default:
             $this->server_type = 'unknown';
     }
     $dirname = dirname($_SERVER['PHP_SELF']);
     if (mb_stristr(PHP_OS, 'WIN')) {
         $dirname = str_replace("\\", "/", $dirname);
         /* Windows adds a \ to the URL which we don't want */
     }
     $this->dirname = $dirname != '/' ? $dirname . '/' : $dirname;
 }
Пример #29
0
 /**
  * Makes sure adding a user happens without errors
  * 
  * @link http://issues.thebuggenie.com/thebuggenie/issues/2494
  *
  * @covers thebuggenie\core\modules\configuration\Actions::runAddUser
  * @dataProvider addUserRequestProvider
  */
 public function testRunAddUser($username, $buddyname, $email, $password, $group_id)
 {
     \b2db\Core::resetMocks();
     $scope = $this->getMockBuilder('thebuggenie\\core\\entities\\Scope')->setMethods(array('hasUsersAvailable'))->getMock();
     $scope->method('hasUsersAvailable')->willReturn(true);
     \thebuggenie\core\framework\Context::setScope($scope);
     $request = new \thebuggenie\core\framework\Request();
     $request->setParameter('username', $username);
     $request->setParameter('buddyname', $buddyname);
     $request->setParameter('email', $email);
     $request->setParameter('password', $password);
     $request->setParameter('password_repeat', $password);
     $request->setParameter('group_id', $group_id);
     $usertablestub = $this->getMockBuilder('b2db\\Table')->setMethods(array('isUsernameAvailable'))->getMock();
     $userscopestablestub = $this->getMockBuilder('b2db\\Table')->getMock();
     \b2db\Core::setTableMock('thebuggenie\\core\\entities\\tables\\UserScopes', $userscopestablestub);
     \b2db\Core::setTableMock('thebuggenie\\core\\entities\\User', $usertablestub);
     \b2db\Core::setTableMock('thebuggenie\\core\\entities\\tables\\Users', $usertablestub);
     $usertablestub->method('isUsernameAvailable')->will($this->returnValue(true));
     // Expect action to verify that username is available
     $usertablestub->expects($this->once())->method('isUsernameAvailable')->with($username);
     $userscopestablestub->expects($this->once())->method('countUsers');
     $this->object->runAddUser($request);
     $userobject = \b2db\Core::getTable('thebuggenie\\core\\entities\\tables\\Users')->getLastMockObject();
     // Expect action to set correct user properties
     $this->assertEquals($userobject->getUsername(), $username);
     $this->assertEquals($userobject->getBuddyname(), $buddyname);
     $this->assertEquals($userobject->getRealname(), $username);
     $this->assertEquals($userobject->getEmail(), $email);
 }