Skip to content

Commit 931a726

Browse files
committed
adodb: enable mantis prefix/suffix
Usage: mantis tables : "{user}" instead of "mantis_user_table" codevtt tables: always use full name "codev_team_user_table"
1 parent 96898eb commit 931a726

File tree

5 files changed

+40
-42
lines changed

5 files changed

+40
-42
lines changed

classes/AdodbWrapper.php

+27-29
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,31 @@ public static function getInstance() {
143143
*/
144144
private function __construct($hostname, $username, $password, $database_name, $database_type, $persistConnect = false) {
145145

146+
$this->isLog = self::$logger->isDebugEnabled();
147+
146148
$this->server = $hostname;
147149
$this->username = $username;
148150
$this->password = $password;
149151
$this->database_name = $database_name;
150-
151-
$this->isLog = self::$logger->isDebugEnabled();
152+
153+
$this->mantis_db_table_prefix = 'mantis_'; # TODO make it configurable, see git fffeb846bd
154+
$this->mantis_db_table_suffix = '_table'; # TODO
155+
156+
// TODO enable mantis prefix/suffix in CodevTT
157+
/*
158+
if( $this->mantis_db_table_prefix === null ) {
159+
# Determine table prefix and suffixes including trailing and leading '_'
160+
$this->mantis_db_table_prefix = trim( config_get_global( 'db_table_prefix' ) );
161+
$this->mantis_db_table_suffix = trim( config_get_global( 'db_table_suffix' ) );
162+
163+
if( !empty( $this->mantis_db_table_prefix ) && '_' != substr( $this->mantis_db_table_prefix, -1 ) ) {
164+
$this->mantis_db_table_prefix .= '_';
165+
}
166+
if( !empty( $this->mantis_db_table_suffix ) && '_' != substr( $this->mantis_db_table_suffix, 0, 1 ) ) {
167+
$this->mantis_db_table_suffix = '_' . $this->mantis_db_table_suffix;
168+
}
169+
}
170+
*/
152171

153172
switch ($database_type) {
154173
case 'mysqli':
@@ -387,35 +406,14 @@ public function sql_query($p_query, array $p_arr_parms = null, $p_isParamPush =
387406
}
388407
}
389408

390-
/* bypass prefix/suffix in CodevTT */
391-
$s_prefix = '';
392-
$s_suffix = '';
409+
// replace table prefix/suffix (ONLY for mantis tables)
393410
$p_query = strtr($p_query, array(
394-
'{' => $s_prefix,
395-
'}' => $s_suffix,
396-
) );
397-
/* TODO enable prefix/suffix in CodevTT
398-
399-
static $s_prefix;
400-
static $s_suffix;
401-
if( $s_prefix === null ) {
402-
# Determine table prefix and suffixes including trailing and leading '_'
403-
$s_prefix = trim( config_get_global( 'db_table_prefix' ) );
404-
$s_suffix = trim( config_get_global( 'db_table_suffix' ) );
405-
406-
if( !empty( $s_prefix ) && '_' != substr( $s_prefix, -1 ) ) {
407-
$s_prefix .= '_';
408-
}
409-
if( !empty( $s_suffix ) && '_' != substr( $s_suffix, 0, 1 ) ) {
410-
$s_suffix = '_' . $s_suffix;
411-
}
412-
}
413-
414-
$p_query = strtr($p_query, array(
415-
'{' => $s_prefix,
416-
'}' => $s_suffix,
411+
'{' => $this->mantis_db_table_prefix,
412+
'}' => $this->mantis_db_table_suffix,
417413
) );
418-
*/
414+
415+
#self::$logger->error("raw p_query=$p_query");
416+
419417
# Pushing params to safeguard the ADOdb parameter count (required for pgsql)
420418
$this->db_param->push();
421419

classes/config.class.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public static function staticInit() {
191191
*/
192192
private function __construct() {
193193
self::$configVariables = array();
194-
$query = 'SELECT * FROM {codev_config_table}';
194+
$query = 'SELECT * FROM codev_config_table';
195195

196196
$result = AdodbWrapper::getInstance()->sql_query($query);
197197
if (!$result) {
@@ -381,7 +381,7 @@ public static function setValue($id, $value, $type, $desc=NULL, $project_id=0, $
381381
$sql = AdodbWrapper::getInstance();
382382

383383
// add/update DB
384-
$query = 'SELECT * FROM {codev_config_table} ' .
384+
$query = 'SELECT * FROM codev_config_table ' .
385385
'WHERE config_id ='. $sql->db_param().
386386
' AND project_id ='. $sql->db_param().
387387
' AND user_id ='. $sql->db_param().
@@ -398,7 +398,7 @@ public static function setValue($id, $value, $type, $desc=NULL, $project_id=0, $
398398
exit;
399399
}
400400
if (0 != $sql->getNumRows($result)) {
401-
$query = 'UPDATE {codev_config_table} ' .
401+
$query = 'UPDATE codev_config_table ' .
402402
' SET value = '.$sql->db_param(). // $formattedValue.
403403
' WHERE config_id ='. $sql->db_param().
404404
' AND project_id ='. $sql->db_param().
@@ -416,7 +416,7 @@ public static function setValue($id, $value, $type, $desc=NULL, $project_id=0, $
416416
self::$logger->debug("UPDATE query = $query");
417417
}
418418
} else {
419-
$query = 'INSERT INTO {codev_config_table} ' .
419+
$query = 'INSERT INTO codev_config_table ' .
420420
'(config_id, value, type, description, project_id, user_id, team_id, command_id, commandset_id, servicecontract_id) '.
421421
' VALUES ( ' . $sql->db_param() . ',' . $sql->db_param() . ',' . $sql->db_param() . ',' . $sql->db_param() . ',
422422
' . $sql->db_param() . ',' . $sql->db_param() . ',' . $sql->db_param() . ',' . $sql->db_param() . ',
@@ -461,7 +461,7 @@ public static function deleteValue($id, $arr_subid=NULL) {
461461
$sql = AdodbWrapper::getInstance();
462462

463463
// delete from DB
464-
$query = "DELETE FROM {codev_config_table} WHERE config_id = " . $sql->db_param();
464+
$query = "DELETE FROM codev_config_table WHERE config_id = " . $sql->db_param();
465465
$query_params = array($id);
466466

467467
$cols = array("user_id", "project_id", "team_id", "servicecontract_id", "commandset_id", "command_id");

classes/user.class.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function __construct($user_id, $details = NULL) {
189189
private function initialize($row) {
190190
if(NULL == $row) {
191191
$sql = AdodbWrapper::getInstance();
192-
$query = 'SELECT username, realname, enabled FROM {mantis_user_table} WHERE id = '. $sql->db_param();
192+
$query = 'SELECT username, realname, enabled FROM {user} WHERE id = '. $sql->db_param();
193193

194194
$result = $sql->sql_query($query, array($this->id));
195195
if (!$result) {
@@ -376,7 +376,7 @@ public function isTeamMember($team_id, $accessLevel = NULL, $startTimestamp = NU
376376
$key = $team_id . '_' . $accessLevel . ' ' . $startTimestamp . ' ' . $endTimestamp;
377377

378378
if (!array_key_exists($key, $this->teamMemberCache)) {
379-
$query = "SELECT COUNT(id) FROM {codev_team_user_table} " .
379+
$query = "SELECT COUNT(id) FROM codev_team_user_table " .
380380
" WHERE team_id = " . $sql->db_param().
381381
" AND user_id = ". $sql->db_param();
382382
$q_params = array($team_id, $this->id);
@@ -896,8 +896,8 @@ public function getTeamList($accessLevel = NULL, $withDisabled=false) {
896896
$sql = AdodbWrapper::getInstance();
897897

898898
$query = "SELECT team.id, team.name " .
899-
"FROM {codev_team_table} as team " .
900-
"JOIN {codev_team_user_table} as team_user ON team.id = team_user.team_id ".
899+
"FROM codev_team_table as team " .
900+
"JOIN codev_team_user_table as team_user ON team.id = team_user.team_id ".
901901
"WHERE team_user.user_id = " . $sql->db_param();
902902
$query_params = array($this->id);
903903

login.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function login($username, $password) {
5151
$password = md5($password);
5252
$now = time();
5353

54-
$query = "SELECT id, username, realname, last_visit FROM {mantis_user_table} " .
54+
$query = "SELECT id, username, realname, last_visit FROM {user} " .
5555
" WHERE username = " . $sql->db_param() .
5656
" AND password = " . $sql->db_param() .
5757
" AND enabled = 1";
@@ -80,7 +80,7 @@ function login($username, $password) {
8080
} else {
8181
// no default team (user's first connection):
8282
// find out if user is already affected to a team and set as default team
83-
$query = 'SELECT team_id FROM {codev_team_user_table} WHERE user_id = ' . $sql->db_param() .
83+
$query = 'SELECT team_id FROM codev_team_user_table WHERE user_id = ' . $sql->db_param() .
8484
' ORDER BY arrival_date DESC';
8585
$query_params = array($user->getId());
8686

@@ -96,7 +96,7 @@ function login($username, $password) {
9696
$projid = $user->getDefaultProject();
9797
if (0 != $projid) { $_SESSION['projectid'] = $projid; }
9898

99-
$query2 = "UPDATE {mantis_user_table} SET last_visit = ".$sql->db_param().
99+
$query2 = "UPDATE {user} SET last_visit = ".$sql->db_param().
100100
" WHERE username = ".$sql->db_param();
101101
$sql->sql_query($query2, array($now, $username));
102102

tests/adodb.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function staticInit() {
4141
private function bug_get_bugnote_count($id) {
4242

4343
$sql = AdodbWrapper::getInstance();
44-
$query = 'SELECT COUNT(1) FROM {mantis_bugnote_table} WHERE bug_id =' . $sql->db_param();
44+
$query = 'SELECT COUNT(1) FROM {bugnote} WHERE bug_id =' . $sql->db_param();
4545
$result = $sql->sql_query($query, array($id));
4646
return $sql->sql_result($result);
4747
}

0 commit comments

Comments
 (0)