/** * Return all permissions available * * @param string $type * @param integer $uid * @param integer $tid * @param integer $gid * @param integer $target_id [optional] * @param boolean $all [optional] * * @return array */ public static function getAllPermissions($type, $uid, $tid, $gid, $target_id = null, $all = false) { $crit = new \b2db\Criteria(); $crit->addWhere(Permissions::SCOPE, self::getScope()->getID()); $crit->addWhere(Permissions::PERMISSION_TYPE, $type); if ($uid + $tid + $gid == 0 && !$all) { $crit->addWhere(Permissions::UID, $uid); $crit->addWhere(Permissions::TID, $tid); $crit->addWhere(Permissions::GID, $gid); } else { switch (true) { case $uid != 0: $crit->addWhere(Permissions::UID, $uid); case $tid != 0: $crit->addWhere(Permissions::TID, $tid); case $gid != 0: $crit->addWhere(Permissions::GID, $gid); } } if ($target_id !== null) { $crit->addWhere(Permissions::TARGET_ID, $target_id); } $permissions = array(); if ($res = Permissions::getTable()->doSelect($crit)) { while ($row = $res->getNextRow()) { $permissions[] = array('p_type' => $row->get(Permissions::PERMISSION_TYPE), 'target_id' => $row->get(Permissions::TARGET_ID), 'allowed' => $row->get(Permissions::ALLOWED), 'uid' => $row->get(Permissions::UID), 'gid' => $row->get(Permissions::GID), 'tid' => $row->get(Permissions::TID), 'id' => $row->get(Permissions::ID)); } } return $permissions; }
private static function _loadSetting($name, $module = 'core', $scope = 0) { $crit = new \b2db\Criteria(); $crit->addWhere(tables\Settings::NAME, $name); $crit->addWhere(tables\Settings::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(tables\Settings::SCOPE, $scope); $res = tables\Settings::getTable()->doSelect($crit); if ($res) { $retarr = array(); while ($row = $res->getNextRow()) { $retarr[$row->get(tables\Settings::UID)] = $row->get(tables\Settings::VALUE); } return $retarr; } else { return null; } }
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; }
public static function findTeams($details) { $crit = new \b2db\Criteria(); $crit->addWhere(tables\Teams::NAME, "%{$details}%", \b2db\Criteria::DB_LIKE); $crit->addWhere(tables\Teams::ONDEMAND, false); $teams = array(); if ($res = tables\Teams::getTable()->doSelect($crit)) { while ($row = $res->getNextRow()) { $teams[$row->get(tables\Teams::ID)] = new \thebuggenie\core\entities\Team($row->get(tables\Teams::ID), $row); } } return $teams; }
/** * Return the time when the issue was reopened * * @return false if closed, otherwise a timestamp */ public function whenReopened() { if ($this->isClosed()) { return false; } $crit = new \b2db\Criteria(); $crit->addSelectionColumn(tables\Log::TIME); $crit->addWhere(tables\Log::TARGET, $this->_id); $crit->addWhere(tables\Log::TARGET_TYPE, 1); $crit->addWhere(tables\Log::CHANGE_TYPE, 22); $crit->addOrderBy(tables\Log::TIME, 'desc'); $res = tables\Log::getTable()->doSelect($crit); $ret_arr = array(); if (count($res) == 0) { return false; } $row = $res->getNextRow(); return $row->get(tables\Log::TIME); }
public function enable() { $crit = new \b2db\Criteria(); $crit->addUpdate(tables\Modules::ENABLED, 1); tables\Modules::getTable()->doUpdateById($crit, $this->getID()); $this->_enabled = true; }
static function getTask() { try { $crit = new \b2db\Criteria(); $crit->addWhere(TBGIssueTypesTable::ICON, 'task'); $crit->addWhere(TBGIssueTypesTable::SCOPE, TBGContext::getScope()->getID()); $row = TBGIssueTypesTable::getTable()->doSelectOne($crit); if ($row instanceof \b2db\Row) { return TBGContext::factory()->TBGIssuetype($row->get(TBGIssueTypesTable::ID), $row); } else { throw new Exception("Couldn't find any 'task' issue types"); } } catch (Exception $e) { throw $e; } }
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; } }
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; }