1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved |
4
|
|
|
* |
5
|
|
|
* This file is a part of Codendi. |
6
|
|
|
* |
7
|
|
|
* Codendi is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* Codendi is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with Codendi. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Data Access Object for DB Tables |
23
|
|
|
*/ |
24
|
|
|
class DBTablesDao extends DataAccessObject { |
25
|
|
|
/** |
26
|
|
|
* Gets a log files |
27
|
|
|
* @return object a result object |
28
|
|
|
*/ |
29
|
|
|
function searchAll() { |
30
|
|
|
$sql="SHOW TABLES"; |
31
|
|
|
return $this->retrieve($sql); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function analyzeTable($name) { |
35
|
|
|
$sql = "ANALYZE TABLE ".$name; |
36
|
|
|
return $this->retrieve($sql); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function checkTable($name) { |
40
|
|
|
$sql = "CHECK TABLE ".$name; |
41
|
|
|
return $this->retrieve($sql); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function convertToUTF8($name) { |
45
|
|
|
$field_changes = array(); |
46
|
|
|
$sql = "SHOW FULL COLUMNS FROM ".$name; |
47
|
|
|
foreach($this->retrieve($sql) as $field) { |
|
|
|
|
48
|
|
|
if ($field['Collation']) { |
49
|
|
|
if (preg_match('/_bin$/', $field['Collation'])) { |
50
|
|
|
$collate = 'bin'; |
51
|
|
|
} else { |
52
|
|
|
$collate = 'general_ci'; |
53
|
|
|
} |
54
|
|
|
$field_changes[] = " CHANGE ". $field['Field'] ." ". |
55
|
|
|
$field['Field'] ." ". |
56
|
|
|
$field['Type'] ." CHARACTER SET utf8 COLLATE utf8_". $collate ." ". |
57
|
|
|
(strtolower($field['Null']) == 'no' ? 'NOT NULL' : 'NULL') ." ". |
58
|
|
|
($field['Default'] ? "DEFAULT '". $field['Default'] ."'" : ''); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
$sql = "ALTER TABLE ". $name ." "; |
62
|
|
|
if (count($field_changes)) { |
63
|
|
|
$sql .= implode(",\n", $field_changes).",\n"; |
64
|
|
|
} |
65
|
|
|
$sql .= " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
66
|
|
|
return $this->update($sql); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Gets a log files |
71
|
|
|
* @return object a result object |
72
|
|
|
*/ |
73
|
|
|
function searchByName($name) { |
74
|
|
|
$sql = "DESC ".$name; |
75
|
|
|
return $this->retrieve($sql); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
function updateFromFile($filename) { |
79
|
|
|
$file_content = file($filename); |
80
|
|
|
$query = ""; |
81
|
|
|
foreach($file_content as $sql_line){ |
82
|
|
|
if(trim($sql_line) != "" && strpos($sql_line, "--") === false){ |
83
|
|
|
$query .= $sql_line; |
84
|
|
|
if(preg_match("/;\s*(\r\n|\n|$)/", $sql_line)){ |
85
|
|
|
if (!$this->update($query)) { |
86
|
|
|
return false; |
87
|
|
|
} |
88
|
|
|
$query = ""; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
return true; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
?> |
96
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.