forked from netcommons/NetCommons2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchtables.class.php
More file actions
149 lines (135 loc) · 5.31 KB
/
Searchtables.class.php
File metadata and controls
149 lines (135 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* DBテーブル名リスト取得コンポーネント
*
* @package NetCommons Components
* @author Noriko Arai,Ryuji Masukawa
* @copyright 2006-2007 NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @project NetCommons Project, supported by National Institute of Informatics
* @access public
*/
class Security_Components_Searchtables
{
// 値をセットするため
var $db = null;
var $dbtables = null;
/**
* コンストラクター
* @access public
*/
function Security_Components_Searchtables()
{
$container =& DIContainerFactory::getContainer();
$this->db =& $container->getComponent("DbObject");
}
/**
* DBテーブルリスト取得
* @access public
*/
function SearchTables()
{
// 使用中のプレフィックス名を取得
$used_prefix = $this->db->getPrefix();
// プレフィックスがないテーブルの場合
if ($used_prefix == "") {
$used_prefix = "NONE_PREFIX";
}
// DBテーブル名リストを取得
$sql_cmd = "show table status;";
$db_alltables = $this->db->execute($sql_cmd);
if ($db_alltables == false || empty($db_alltables)) return false;
$adodb = $this->db->getAdoDbObject();
// 全プレフィックス名取得
foreach($db_alltables as $db_table) {
// "config" テーブルから,プレフィックス名を取得
if(substr($db_table["Name"], -6) === 'config') {
$metaColumns = $adodb->MetaColumns($db_table["Name"]);
if(!isset($metaColumns["CONF_ID"]) || !isset($metaColumns["CONF_NAME"]) || !isset($metaColumns["CONF_VALUE"])) {
continue;
}
$prefix = substr($db_table["Name"], 0, (strrpos($db_table["Name"], "config")));
$prefixes[] = $prefix; // プレフィックス名リスト
if ($prefix == "") {
$prefix = "NONE_PREFIX";
}
// サイト名を取得
$sql_cmd = sprintf("select `conf_value` from %s where (`conf_name` = 'sitename')", $db_table["Name"]);
$sitename = $this->db->execute($sql_cmd);
if ($sitename == false || empty($sitename)) return false;
$db_sitename[$prefix] = $sitename[0]['conf_value']; // サイト名
if (!strcmp($prefix, $used_prefix)) {
$db_use_prefix[$prefix] = 1; // 使用中のプレフィックスの場合
$used_sitename = $db_sitename[$prefix]; // 使用中のサイト名
} else {
$db_use_prefix[$prefix] = 0; // 使用していないプレフィックスの場合
}
$db_tables[$prefix] = null;
$db_tables_num[$prefix] = 0;
$db_update_time[$prefix] = null;
}
}
$prefix_count = count($prefixes);
rsort($prefixes);
// プレフィックスごとにテーブル名を振り分け
foreach($db_alltables as $db_table) {
$db_table_found = FALSE;
for ($idx=0; $idx<$prefix_count; $idx++) {
if (empty($prefixes[$idx])) continue;
if (!strncmp($prefixes[$idx], $db_table["Name"], strlen($prefixes[$idx]))) {
$db_tables[$prefixes[$idx]][] = $db_table;
$db_table_found = TRUE;
break;
}
}
// プレフィックスがないテーブルの場合
if ($db_table_found == FALSE) {
$db_tables["NONE_PREFIX"][] = $db_table;
}
}
// プレフィックスごとのテーブル名リスト作成
sort($prefixes);
foreach($prefixes as $prefix) {
$same_dbtable = 0;
// プレフィックスがないテーブルの場合
if ($prefix == "") {
// 最終更新時間
usort($db_tables["NONE_PREFIX"], create_function('$a,$b', 'return $a["Update_time"] < $b["Update_time"] ? 1 : -1 ;'));
$db_update_time["NONE_PREFIX"] = $db_tables["NONE_PREFIX"][0]["Update_time"];
// テーブル数
$db_tables_num["NONE_PREFIX"] = count($db_tables["NONE_PREFIX"]);
if (!strcmp($used_sitename, $db_sitename["NONE_PREFIX"])) {
$same_dbtable = 1;
}
$this->dbtables[] = array(
'useprefix' => $db_use_prefix["NONE_PREFIX"],
'prefix' => "(none)",
'count' => $db_tables_num["NONE_PREFIX"],
'updated' => $db_update_time["NONE_PREFIX"],
'tables' => $db_tables["NONE_PREFIX"],
'usedtable' => $same_dbtable
);
} else {
// 最終更新時間
usort($db_tables[$prefix], create_function('$a,$b', 'return $a["Update_time"] < $b["Update_time"] ? 1 : -1 ;'));
$db_update_time[$prefix] = $db_tables[$prefix][0]["Update_time"];
// テーブル数
$db_tables_num[$prefix] = count($db_tables[$prefix]);
if (!strcmp($used_sitename, $db_sitename[$prefix])) {
$same_dbtable = 1;
}
$this->dbtables[] = array(
'useprefix' => $db_use_prefix[$prefix],
'prefix' => $prefix,
'count' => $db_tables_num[$prefix],
'updated' => $db_update_time[$prefix],
'tables' => $db_tables[$prefix],
'usedtable' => $same_dbtable
);
}
}
return $this->dbtables;
}
}
?>