Skip to content

Commit

Permalink
[m1553] Don't use hardcoded default prefix/suffix for mantis table names
Browse files Browse the repository at this point in the history
 mantis_db_table_suffix

mantis_bug_table

mantis_project_table

mantis_user_table

mantis_config_table

various `mantis_xxx_table`

remaining mantis_xxx_table

Note: mantis_plugins needs to be updated !

INSTALL: db_table_prefix (not yet finished)

TODO: check mantis configuration to get real prefix/suffix !

update mantis plugins table_prefix/suffix

INSTALL: check db_table_prefix & suffix
  • Loading branch information
lbayle committed Apr 1, 2017
1 parent bc9624d commit 795ec7c
Show file tree
Hide file tree
Showing 51 changed files with 412 additions and 339 deletions.
6 changes: 3 additions & 3 deletions admin/edit_team.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ protected function display() {
private function getTeamMembers($teamid) {
$query = "SELECT user.id as user_id, user.username, user.realname, ".
"team_user.id, team_user.arrival_date, team_user.departure_date, team_user.team_id, team_user.access_level ".
"FROM `mantis_user_table` as user ".
"FROM `{user}` as user ".
"JOIN `codev_team_user_table` as team_user ON user.id = team_user.user_id ".
"WHERE team_user.team_id=$teamid ".
"ORDER BY user.username;";
Expand Down Expand Up @@ -353,7 +353,7 @@ private function getTeamMembers($teamid) {
private function getTeamProjects($teamid) {
$query = "SELECT project.id AS project_id, project.name, project.enabled, project.description, ".
"team_project.id, team_project.type ".
"FROM `mantis_project_table` as project ".
"FROM `{project}` as project ".
"JOIN `codev_team_project_table` as team_project ON project.id = team_project.project_id ".
"WHERE team_project.team_id=$teamid ".
"ORDER BY project.name;";
Expand Down Expand Up @@ -415,7 +415,7 @@ private function getOnDutyCandidates(Team $team, array $projList) {

$formatedInactivityCatList = implode( ', ', array_keys($inactivityCatList));

$query = "SELECT * FROM `mantis_bug_table` ".
$query = "SELECT * FROM `{bug}` ".
"WHERE project_id IN ($formatedInactivityCatList) ";

$astreintesList = $team->getOnDutyTasks();
Expand Down
2 changes: 1 addition & 1 deletion classes/Email.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function email_queue_add( EmailData $emailData ) {
$c_body = SqlWrapper::sql_real_escape_string($emailData->body);
$c_metadata = serialize( $emailData->metadata );

$query = "INSERT INTO `mantis_email_table` (`email`, `subject`, `body`, `submitted`, `metadata`) ".
$query = "INSERT INTO `{email}` (`email`, `subject`, `body`, `submitted`, `metadata`) ".
"VALUES ('$c_email', '$c_subject', '$c_body', ".$emailData->submitted.", '$c_metadata');";
#echo "queue email: $query<br>";
$result = SqlWrapper::getInstance()->sql_query($query);
Expand Down
6 changes: 3 additions & 3 deletions classes/command.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static function getCommandId($name) {
* parse all Commands for issues not found in mantis_bug_table. if any, remove them from the Commands.
*/
public static function checkCommands() {
$query0 = "SELECT command_id, bug_id FROM codev_command_bug_table WHERE bug_id NOT IN (SELECT id FROM mantis_bug_table)";
$query0 = "SELECT command_id, bug_id FROM codev_command_bug_table WHERE bug_id NOT IN (SELECT id FROM {bug})";
$result0 = SqlWrapper::getInstance()->sql_query($query0);
while ($row = SqlWrapper::getInstance()->sql_fetch_object($result0)) {
self::$logger->warn("issue $row->bug_id does not exist in Mantis: now removed from Command $row->command_id");
Expand Down Expand Up @@ -633,13 +633,13 @@ public function deleteProvision($provid) {
public function getIssueSelection() {
if(NULL == $this->issueSelection) {
$this->issueSelection = new IssueSelection($this->name);
$query = "SELECT bug.* FROM `mantis_bug_table` AS bug ".
$query = "SELECT bug.* FROM `{bug}` AS bug ".
"JOIN `codev_command_bug_table` AS command_bug ON bug.id = command_bug.bug_id " .
"WHERE command_bug.command_id = ".$this->id.";";
#", `mantis_bug_table`".
#"WHERE codev_command_bug_table.command_id=$this->id ".
#"AND codev_command_bug_table.bug_id = mantis_bug_table.id ".
#"ORDER BY mantis_bug_table.project_id ASC, mantis_bug_table.target_version DESC, mantis_bug_table.status ASC";
#"ORDER BY {bug}.project_id ASC, {bug}.target_version DESC, {bug}.status ASC";

$result = SqlWrapper::getInstance()->sql_query($query);
if (!$result) {
Expand Down
10 changes: 5 additions & 5 deletions classes/consistency_check.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function checkDeliveryDate() {

// select all issues which current status is 'analyzed'
$query = "SELECT * ".
"FROM `mantis_bug_table` ".
"FROM `{bug}` ".
"WHERE status >= get_project_resolved_status_threshold(project_id) ";

if (0 != count($this->projectList)) {
Expand Down Expand Up @@ -180,7 +180,7 @@ public function checkResolved() {

// select all issues which current status is 'analyzed'
$query = "SELECT * ".
"FROM `mantis_bug_table` ".
"FROM `{bug}` ".
"WHERE status >= get_project_resolved_status_threshold(project_id) ";

if (0 != count($this->projectList)) {
Expand Down Expand Up @@ -225,7 +225,7 @@ public function checkBadBacklog() {
$cerrList = array();

// select all issues which current status is 'analyzed'
$query = "SELECT * FROM `mantis_bug_table` ".
$query = "SELECT * FROM `{bug}` ".
#"WHERE status NOT IN (".Constants::$status_new.", ".Constants::$status_acknowledged.") ".
"WHERE status NOT IN (".Constants::$status_new.") ".
"AND status < get_project_resolved_status_threshold(project_id) ";
Expand Down Expand Up @@ -272,7 +272,7 @@ public function checkMgrEffortEstim() {

// select all issues
$query = "SELECT * ".
"FROM `mantis_bug_table` ".
"FROM `{bug}` ".
"WHERE status < get_project_resolved_status_threshold(project_id) ";

if (0 != count($this->projectList)) {
Expand Down Expand Up @@ -335,7 +335,7 @@ function checkTimeTracksOnNewIssues() {

// select all issues which current status is 'new'
$query = "SELECT * ".
"FROM `mantis_bug_table` ".
"FROM `{bug}` ".
"WHERE status = ".Constants::$status_new." ";

if (0 != count($this->projectList)) {
Expand Down
4 changes: 2 additions & 2 deletions classes/consistency_check2.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ public function checkTimetracksOnRemovedIssues() {
"FROM `codev_timetracking_table` ".
"WHERE date >= ".$team->getDate()." ".
"AND userid IN ($formatedUsers) ";
#"AND 0 = (SELECT COUNT(id) FROM `mantis_bug_table` WHERE id='codev_timetracking_table.bugid' ) ";
#"AND 0 = (SELECT COUNT(id) FROM `{bug}` WHERE id='codev_timetracking_table.bugid' ) ";

$result = SqlWrapper::getInstance()->sql_query($query);
if (!$result) {
Expand Down Expand Up @@ -771,7 +771,7 @@ public static function checkIncompleteDays(TimeTracking $timeTracking, $userid =

public static function checkMantisDefaultProjectWorkflow() {
$cerrList = array();
$query = "SELECT * FROM `mantis_config_table` ".
$query = "SELECT * FROM `{config}` ".
"WHERE project_id = 0 ".
"AND config_id = 'status_enum_workflow' ";

Expand Down
2 changes: 1 addition & 1 deletion classes/consistency_check_fdj.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function checkAnalyzed() {

// select all issues which current status is 'analyzed'
$query = "SELECT * ".
"FROM `mantis_bug_table` ".
"FROM `{bug}` ".
"WHERE status in ($status_analyzed, $status_accepted, ".Constants::$status_open.", $status_deferred) ";

if (0 != count($this->projectList)) {
Expand Down
13 changes: 13 additions & 0 deletions classes/constants.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Constants {
public static $severity_names;
public static $bug_resolved_status_threshold;
public static $status_enum_workflow;
public static $mantis_db_table_prefix = 'mantis_';
public static $mantis_db_table_suffix = '_table';

// --- RESOLUTION ---
public static $resolution_fixed;
Expand Down Expand Up @@ -197,6 +199,15 @@ public static function parseConfigFile() {
self::$severity_names = Tools::doubleExplode(':', ',', $mantis['severity_enum_string']);
self::$bug_resolved_status_threshold = $mantis['bug_resolved_status_threshold'];
self::$status_enum_workflow = json_decode($mantis['status_enum_workflow'], true); // jsonStr to array

self::$mantis_db_table_prefix = $mantis['db_table_prefix'];
self::$mantis_db_table_suffix = $mantis['db_table_suffix'];
if ( !empty( self::$mantis_db_table_prefix ) && ('_' != substr( self::$mantis_db_table_prefix, -1 )) ) {
self::$mantis_db_table_prefix .= '_';
}
if ( !empty( self::$mantis_db_table_suffix ) && ('_' != substr( self::$mantis_db_table_suffix, 0, 1 )) ) {
self::$mantis_db_table_suffix = '_' . self::$mantis_db_table_suffix;
}

$status = $ini_array['status'];
self::$status_new = $status['status_new'];
Expand Down Expand Up @@ -308,6 +319,8 @@ public static function writeConfigFile() {
$mantis['severity_enum_string'] = self::$severity_names ? Tools::doubleImplode(':', ',', self::$severity_names) : ' ';
$mantis['bug_resolved_status_threshold'] = self::$bug_resolved_status_threshold;
$mantis['status_enum_workflow'] = json_encode(self::$status_enum_workflow); // array to jsonStr
$mantis['db_table_prefix'] = self::$mantis_db_table_prefix;
$mantis['db_table_suffix'] = self::$mantis_db_table_suffix;

$status = array();
$status[] = '; Note: CodevTT needs some status to be defined (new, feedback, open, closed)';
Expand Down
2 changes: 1 addition & 1 deletion classes/crypto.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function auth_generate_unique_cookie_string() {
* @access public
*/
private function auth_is_cookie_string_unique($p_cookie_string) {
$query = "SELECT COUNT(*) FROM mantis_user_table WHERE cookie_string='$p_cookie_string'";
$query = "SELECT COUNT(*) FROM `{user}` WHERE cookie_string='$p_cookie_string'";
$result = SqlWrapper::getInstance()->sql_query($query);

if (!$result) {
Expand Down
Loading

0 comments on commit 795ec7c

Please sign in to comment.