| Total Complexity | 116 |
| Total Lines | 786 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like DatabaseController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DatabaseController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class DatabaseController extends BaseController |
||
| 11 | { |
||
| 12 | use AdminTrait; |
||
| 13 | public $script = 'database.php'; |
||
| 14 | public $_name = 'DatabaseController'; |
||
|
1 ignored issue
–
show
|
|||
| 15 | public $table_place = 'database-variables'; |
||
| 16 | |||
| 17 | public function _highlight($string, $term) |
||
| 20 | } |
||
| 21 | |||
| 22 | public function render() |
||
|
1 ignored issue
–
show
|
|||
| 23 | { |
||
| 24 | $conf = $this->conf; |
||
| 25 | $misc = $this->misc; |
||
| 26 | $lang = $this->lang; |
||
| 27 | $action = $this->action; |
||
| 28 | $data = $misc->getDatabaseAccessor(); |
||
| 29 | |||
| 30 | if ($action == 'tree') { |
||
| 31 | return $this->doTree(); |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($action == 'refresh_locks') { |
||
| 35 | return $this->currentLocks(true); |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($action == 'refresh_processes') { |
||
| 39 | return $this->currentProcesses(true); |
||
| 40 | } |
||
| 41 | $scripts = ''; |
||
| 42 | /* normal flow */ |
||
| 43 | if ($action == 'locks' || $action == 'processes') { |
||
| 44 | $scripts .= '<script src="' . SUBFOLDER . '/js/database.js" type="text/javascript"></script>'; |
||
| 45 | |||
| 46 | $refreshTime = $conf['ajax_refresh'] * 1500; |
||
| 47 | |||
| 48 | $scripts .= "<script type=\"text/javascript\">\n"; |
||
| 49 | $scripts .= "var Database = {\n"; |
||
| 50 | $scripts .= "ajax_time_refresh: {$refreshTime},\n"; |
||
| 51 | $scripts .= "str_start: {text:'{$lang['strstart']}',icon: '" . $misc->icon('Execute') . "'},\n"; |
||
| 52 | $scripts .= "str_stop: {text:'{$lang['strstop']}',icon: '" . $misc->icon('Stop') . "'},\n"; |
||
| 53 | $scripts .= "load_icon: '" . $misc->icon('Loading') . "',\n"; |
||
| 54 | $scripts .= "server:'{$_REQUEST['server']}',\n"; |
||
| 55 | $scripts .= "dbname:'{$_REQUEST['database']}',\n"; |
||
| 56 | $scripts .= "action:'refresh_{$action}',\n"; |
||
| 57 | $scripts .= "errmsg: '" . str_replace("'", "\'", $lang['strconnectionfail']) . "'\n"; |
||
| 58 | $scripts .= "};\n"; |
||
| 59 | $scripts .= "</script>\n"; |
||
| 60 | } |
||
| 61 | |||
| 62 | $header_template = 'header.twig'; |
||
| 63 | $footer_template = 'footer.twig'; |
||
| 64 | // @todo convert all these methods to return text instead of print text |
||
| 65 | ob_start(); |
||
| 66 | switch ($action) { |
||
| 67 | case 'find': |
||
| 68 | if (isset($_REQUEST['term'])) { |
||
| 69 | $this->doFind(false); |
||
| 70 | } else { |
||
| 71 | $this->doFind(true); |
||
| 72 | } |
||
| 73 | |||
| 74 | break; |
||
| 75 | case 'sql': |
||
| 76 | $this->doSQL(); |
||
| 77 | $header_template = 'header_sqledit.twig'; |
||
| 78 | $footer_template = 'footer_sqledit.twig'; |
||
| 79 | break; |
||
| 80 | case 'variables': |
||
| 81 | $this->doVariables(); |
||
| 82 | break; |
||
| 83 | case 'processes': |
||
| 84 | $this->doProcesses(); |
||
| 85 | break; |
||
| 86 | case 'locks': |
||
| 87 | $this->doLocks(); |
||
| 88 | break; |
||
| 89 | case 'export': |
||
| 90 | $this->doExport(); |
||
| 91 | break; |
||
| 92 | case 'signal': |
||
| 93 | $this->doSignal(); |
||
| 94 | break; |
||
| 95 | default: |
||
| 96 | if ($this->adminActions($action, 'database') === false) { |
||
| 97 | $header_template = 'header_sqledit.twig'; |
||
| 98 | $footer_template = 'footer_sqledit.twig'; |
||
| 99 | $this->doSQL(); |
||
| 100 | } |
||
| 101 | |||
| 102 | break; |
||
| 103 | } |
||
| 104 | $output = ob_get_clean(); |
||
| 105 | |||
| 106 | $this->printHeader($lang['strdatabase'], $scripts, true, $header_template); |
||
| 107 | $this->printBody(); |
||
| 108 | |||
| 109 | echo $output; |
||
| 110 | |||
| 111 | $this->printFooter(true, $footer_template); |
||
| 112 | |||
| 113 | return; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function doTree($print = true) |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Sends a signal to a process |
||
| 142 | */ |
||
| 143 | public function doSignal() |
||
| 144 | { |
||
| 145 | $conf = $this->conf; |
||
| 146 | $misc = $this->misc; |
||
| 147 | $lang = $this->lang; |
||
| 148 | $data = $misc->getDatabaseAccessor(); |
||
| 149 | |||
| 150 | $status = $data->sendSignal($_REQUEST['pid'], $_REQUEST['signal']); |
||
| 151 | if ($status == 0) { |
||
| 152 | $this->doProcesses($lang['strsignalsent']); |
||
| 153 | } else { |
||
| 154 | $this->doProcesses($lang['strsignalsentbad']); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Searches for a named database object |
||
| 160 | */ |
||
| 161 | public function doFind($confirm = true, $msg = '') |
||
| 162 | { |
||
| 163 | $conf = $this->conf; |
||
| 164 | $misc = $this->misc; |
||
| 165 | $lang = $this->lang; |
||
| 166 | $data = $misc->getDatabaseAccessor(); |
||
| 167 | |||
| 168 | if (!isset($_REQUEST['term'])) { |
||
| 169 | $_REQUEST['term'] = ''; |
||
| 170 | } |
||
| 171 | |||
| 172 | if (!isset($_REQUEST['filter'])) { |
||
| 173 | $_REQUEST['filter'] = ''; |
||
| 174 | } |
||
| 175 | |||
| 176 | $this->printTrail('database'); |
||
| 177 | $this->printTabs('database', 'find'); |
||
| 178 | $this->printMsg($msg); |
||
| 179 | |||
| 180 | echo '<form action="' . SUBFOLDER . "/src/views/database.php\" method=\"post\">\n"; |
||
| 181 | echo '<p><input name="term" value="', htmlspecialchars($_REQUEST['term']), |
||
| 182 | "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n"; |
||
| 183 | // Output list of filters. This is complex due to all the 'has' and 'conf' feature possibilities |
||
| 184 | echo "<select name=\"filter\">\n"; |
||
| 185 | echo "\t<option value=\"\"", ($_REQUEST['filter'] == '') ? ' selected="selected"' : '', ">{$lang['strallobjects']}</option>\n"; |
||
| 186 | echo "\t<option value=\"SCHEMA\"", ($_REQUEST['filter'] == 'SCHEMA') ? ' selected="selected"' : '', ">{$lang['strschemas']}</option>\n"; |
||
| 187 | echo "\t<option value=\"TABLE\"", ($_REQUEST['filter'] == 'TABLE') ? ' selected="selected"' : '', ">{$lang['strtables']}</option>\n"; |
||
| 188 | echo "\t<option value=\"VIEW\"", ($_REQUEST['filter'] == 'VIEW') ? ' selected="selected"' : '', ">{$lang['strviews']}</option>\n"; |
||
| 189 | echo "\t<option value=\"SEQUENCE\"", ($_REQUEST['filter'] == 'SEQUENCE') ? ' selected="selected"' : '', ">{$lang['strsequences']}</option>\n"; |
||
| 190 | echo "\t<option value=\"COLUMN\"", ($_REQUEST['filter'] == 'COLUMN') ? ' selected="selected"' : '', ">{$lang['strcolumns']}</option>\n"; |
||
| 191 | echo "\t<option value=\"RULE\"", ($_REQUEST['filter'] == 'RULE') ? ' selected="selected"' : '', ">{$lang['strrules']}</option>\n"; |
||
| 192 | echo "\t<option value=\"INDEX\"", ($_REQUEST['filter'] == 'INDEX') ? ' selected="selected"' : '', ">{$lang['strindexes']}</option>\n"; |
||
| 193 | echo "\t<option value=\"TRIGGER\"", ($_REQUEST['filter'] == 'TRIGGER') ? ' selected="selected"' : '', ">{$lang['strtriggers']}</option>\n"; |
||
| 194 | echo "\t<option value=\"CONSTRAINT\"", ($_REQUEST['filter'] == 'CONSTRAINT') ? ' selected="selected"' : '', ">{$lang['strconstraints']}</option>\n"; |
||
| 195 | echo "\t<option value=\"FUNCTION\"", ($_REQUEST['filter'] == 'FUNCTION') ? ' selected="selected"' : '', ">{$lang['strfunctions']}</option>\n"; |
||
| 196 | echo "\t<option value=\"DOMAIN\"", ($_REQUEST['filter'] == 'DOMAIN') ? ' selected="selected"' : '', ">{$lang['strdomains']}</option>\n"; |
||
| 197 | if ($conf['show_advanced']) { |
||
| 198 | echo "\t<option value=\"AGGREGATE\"", ($_REQUEST['filter'] == 'AGGREGATE') ? ' selected="selected"' : '', ">{$lang['straggregates']}</option>\n"; |
||
| 199 | echo "\t<option value=\"TYPE\"", ($_REQUEST['filter'] == 'TYPE') ? ' selected="selected"' : '', ">{$lang['strtypes']}</option>\n"; |
||
| 200 | echo "\t<option value=\"OPERATOR\"", ($_REQUEST['filter'] == 'OPERATOR') ? ' selected="selected"' : '', ">{$lang['stroperators']}</option>\n"; |
||
| 201 | echo "\t<option value=\"OPCLASS\"", ($_REQUEST['filter'] == 'OPCLASS') ? ' selected="selected"' : '', ">{$lang['stropclasses']}</option>\n"; |
||
| 202 | echo "\t<option value=\"CONVERSION\"", ($_REQUEST['filter'] == 'CONVERSION') ? ' selected="selected"' : '', ">{$lang['strconversions']}</option>\n"; |
||
| 203 | echo "\t<option value=\"LANGUAGE\"", ($_REQUEST['filter'] == 'LANGUAGE') ? ' selected="selected"' : '', ">{$lang['strlanguages']}</option>\n"; |
||
| 204 | } |
||
| 205 | echo "</select>\n"; |
||
| 206 | echo "<input type=\"submit\" value=\"{$lang['strfind']}\" />\n"; |
||
| 207 | echo $misc->form; |
||
| 208 | echo "<input type=\"hidden\" name=\"action\" value=\"find\" /></p>\n"; |
||
| 209 | echo "</form>\n"; |
||
| 210 | |||
| 211 | // Default focus |
||
| 212 | $this->setFocus('forms[0].term'); |
||
| 213 | |||
| 214 | // If a search term has been specified, then perform the search |
||
| 215 | // and display the results, grouped by object type |
||
| 216 | if ($_REQUEST['term'] != '') { |
||
| 217 | $rs = $data->findObject($_REQUEST['term'], $_REQUEST['filter']); |
||
| 218 | if ($rs->recordCount() > 0) { |
||
| 219 | $curr = ''; |
||
| 220 | while (!$rs->EOF) { |
||
| 221 | // Output a new header if the current type has changed, but not if it's just changed the rule type |
||
| 222 | if ($rs->fields['type'] != $curr) { |
||
| 223 | // Short-circuit in the case of changing from table rules to view rules; table cols to view cols; |
||
| 224 | // table constraints to domain constraints |
||
| 225 | if ($rs->fields['type'] == 'RULEVIEW' && $curr == 'RULETABLE') { |
||
| 226 | $curr = $rs->fields['type']; |
||
| 227 | } elseif ($rs->fields['type'] == 'COLUMNVIEW' && $curr == 'COLUMNTABLE') { |
||
| 228 | $curr = $rs->fields['type']; |
||
| 229 | } elseif ($rs->fields['type'] == 'CONSTRAINTTABLE' && $curr == 'CONSTRAINTDOMAIN') { |
||
| 230 | $curr = $rs->fields['type']; |
||
| 231 | } else { |
||
| 232 | if ($curr != '') { |
||
| 233 | echo "</ul>\n"; |
||
| 234 | } |
||
| 235 | |||
| 236 | $curr = $rs->fields['type']; |
||
| 237 | echo '<h3>'; |
||
| 238 | switch ($curr) { |
||
| 239 | case 'SCHEMA': |
||
| 240 | echo $lang['strschemas']; |
||
| 241 | break; |
||
| 242 | case 'TABLE': |
||
| 243 | echo $lang['strtables']; |
||
| 244 | break; |
||
| 245 | case 'VIEW': |
||
| 246 | echo $lang['strviews']; |
||
| 247 | break; |
||
| 248 | case 'SEQUENCE': |
||
| 249 | echo $lang['strsequences']; |
||
| 250 | break; |
||
| 251 | case 'COLUMNTABLE': |
||
| 252 | case 'COLUMNVIEW': |
||
| 253 | echo $lang['strcolumns']; |
||
| 254 | break; |
||
| 255 | case 'INDEX': |
||
| 256 | echo $lang['strindexes']; |
||
| 257 | break; |
||
| 258 | case 'CONSTRAINTTABLE': |
||
| 259 | case 'CONSTRAINTDOMAIN': |
||
| 260 | echo $lang['strconstraints']; |
||
| 261 | break; |
||
| 262 | case 'TRIGGER': |
||
| 263 | echo $lang['strtriggers']; |
||
| 264 | break; |
||
| 265 | case 'RULETABLE': |
||
| 266 | case 'RULEVIEW': |
||
| 267 | echo $lang['strrules']; |
||
| 268 | break; |
||
| 269 | case 'FUNCTION': |
||
| 270 | echo $lang['strfunctions']; |
||
| 271 | break; |
||
| 272 | case 'TYPE': |
||
| 273 | echo $lang['strtypes']; |
||
| 274 | break; |
||
| 275 | case 'DOMAIN': |
||
| 276 | echo $lang['strdomains']; |
||
| 277 | break; |
||
| 278 | case 'OPERATOR': |
||
| 279 | echo $lang['stroperators']; |
||
| 280 | break; |
||
| 281 | case 'CONVERSION': |
||
| 282 | echo $lang['strconversions']; |
||
| 283 | break; |
||
| 284 | case 'LANGUAGE': |
||
| 285 | echo $lang['strlanguages']; |
||
| 286 | break; |
||
| 287 | case 'AGGREGATE': |
||
| 288 | echo $lang['straggregates']; |
||
| 289 | break; |
||
| 290 | case 'OPCLASS': |
||
| 291 | echo $lang['stropclasses']; |
||
| 292 | break; |
||
| 293 | } |
||
| 294 | echo '</h3>'; |
||
| 295 | echo "<ul>\n"; |
||
| 296 | } |
||
| 297 | } |
||
| 298 | |||
| 299 | switch ($curr) { |
||
| 300 | case 'SCHEMA': |
||
| 301 | echo '<li><a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", $misc->printVal($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 302 | break; |
||
| 303 | case 'TABLE': |
||
| 304 | echo '<li>'; |
||
| 305 | echo "<a href=\"tables.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 306 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', |
||
| 307 | urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 308 | break; |
||
| 309 | case 'VIEW': |
||
| 310 | echo '<li>'; |
||
| 311 | echo "<a href=\"views.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 312 | echo '<a href="' . SUBFOLDER . "/redirect/view?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&view=', |
||
| 313 | urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 314 | break; |
||
| 315 | case 'SEQUENCE': |
||
| 316 | echo '<li>'; |
||
| 317 | echo "<a href=\"sequences.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 318 | echo "<a href=\"sequences.php?subject=sequence&action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), |
||
| 319 | '&sequence=', urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 320 | break; |
||
| 321 | case 'COLUMNTABLE': |
||
| 322 | echo '<li>'; |
||
| 323 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 324 | echo "<a href=\"tblproperties.php?subject=table&{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
| 325 | echo "<a href=\"colproperties.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', |
||
| 326 | urlencode($rs->fields['relname']), '&column=', urlencode($rs->fields['name']), '">', |
||
| 327 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 328 | break; |
||
| 329 | case 'COLUMNVIEW': |
||
| 330 | echo '<li>'; |
||
| 331 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 332 | echo "<a href=\"viewproperties.php?subject=view&{$misc->href}&view=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
| 333 | echo "<a href=\"colproperties.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&view=', |
||
| 334 | urlencode($rs->fields['relname']), '&column=', urlencode($rs->fields['name']), '">', |
||
| 335 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 336 | break; |
||
| 337 | case 'INDEX': |
||
| 338 | echo '<li>'; |
||
| 339 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 340 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
| 341 | echo "<a href=\"indexes.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', urlencode($rs->fields['relname']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 342 | break; |
||
| 343 | case 'CONSTRAINTTABLE': |
||
| 344 | echo '<li>'; |
||
| 345 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 346 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
| 347 | echo "<a href=\"constraints.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', |
||
| 348 | urlencode($rs->fields['relname']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 349 | break; |
||
| 350 | case 'CONSTRAINTDOMAIN': |
||
| 351 | echo '<li>'; |
||
| 352 | echo "<a href=\"domains.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 353 | echo "<a href=\"domains.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&domain=', urlencode($rs->fields['relname']), '">', |
||
| 354 | $misc->printVal($rs->fields['relname']), '.', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 355 | break; |
||
| 356 | case 'TRIGGER': |
||
| 357 | echo '<li>'; |
||
| 358 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 359 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
| 360 | echo "<a href=\"triggers.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', urlencode($rs->fields['relname']), '">', |
||
| 361 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 362 | break; |
||
| 363 | case 'RULETABLE': |
||
| 364 | echo '<li>'; |
||
| 365 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 366 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
| 367 | echo "<a href=\"rules.php?subject=table&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&reltype=table&table=', |
||
| 368 | urlencode($rs->fields['relname']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 369 | break; |
||
| 370 | case 'RULEVIEW': |
||
| 371 | echo '<li>'; |
||
| 372 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 373 | echo '<a href="' . SUBFOLDER . "/redirect/view?{$misc->href}&view=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
| 374 | echo "<a href=\"rules.php?subject=view&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&reltype=view&view=', |
||
| 375 | urlencode($rs->fields['relname']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 376 | break; |
||
| 377 | case 'FUNCTION': |
||
| 378 | echo '<li>'; |
||
| 379 | echo "<a href=\"functions.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 380 | echo "<a href=\"functions.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&function=', |
||
| 381 | urlencode($rs->fields['name']), '&function_oid=', urlencode($rs->fields['oid']), '">', |
||
| 382 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 383 | break; |
||
| 384 | case 'TYPE': |
||
| 385 | echo '<li>'; |
||
| 386 | echo "<a href=\"types.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 387 | echo "<a href=\"types.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&type=', |
||
| 388 | urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 389 | break; |
||
| 390 | case 'DOMAIN': |
||
| 391 | echo '<li>'; |
||
| 392 | echo "<a href=\"domains.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 393 | echo "<a href=\"domains.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&domain=', |
||
| 394 | urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 395 | break; |
||
| 396 | case 'OPERATOR': |
||
| 397 | echo '<li>'; |
||
| 398 | echo "<a href=\"operators.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 399 | echo "<a href=\"operators.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&operator=', |
||
| 400 | urlencode($rs->fields['name']), '&operator_oid=', urlencode($rs->fields['oid']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 401 | break; |
||
| 402 | case 'CONVERSION': |
||
| 403 | echo '<li>'; |
||
| 404 | echo "<a href=\"conversions.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 405 | echo "<a href=\"conversions.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), |
||
| 406 | '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 407 | break; |
||
| 408 | case 'LANGUAGE': |
||
| 409 | echo "<li><a href=\"languages.php?{$misc->href}\">", $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 410 | break; |
||
| 411 | case 'AGGREGATE': |
||
| 412 | echo '<li>'; |
||
| 413 | echo "<a href=\"aggregates.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 414 | echo "<a href=\"aggregates.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', |
||
| 415 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 416 | break; |
||
| 417 | case 'OPCLASS': |
||
| 418 | echo '<li>'; |
||
| 419 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
| 420 | echo "<a href=\"opclasses.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', |
||
| 421 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
| 422 | break; |
||
| 423 | } |
||
| 424 | $rs->moveNext(); |
||
| 425 | } |
||
| 426 | echo "</ul>\n"; |
||
| 427 | |||
| 428 | echo '<p>', $rs->recordCount(), ' ', $lang['strobjects'], "</p>\n"; |
||
| 429 | } else { |
||
| 430 | echo "<p>{$lang['strnoobjects']}</p>\n"; |
||
| 431 | } |
||
| 432 | } |
||
| 433 | } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Displays options for database download |
||
| 437 | */ |
||
| 438 | public function doExport($msg = '') |
||
| 439 | { |
||
| 440 | $conf = $this->conf; |
||
| 441 | $misc = $this->misc; |
||
| 442 | $lang = $this->lang; |
||
| 443 | $data = $misc->getDatabaseAccessor(); |
||
| 444 | |||
| 445 | $this->printTrail('database'); |
||
| 446 | $this->printTabs('database', 'export'); |
||
| 447 | $this->printMsg($msg); |
||
| 448 | |||
| 449 | echo '<form action="' . SUBFOLDER . "/src/views/dbexport.php\" method=\"post\">\n"; |
||
| 450 | echo "<table>\n"; |
||
| 451 | echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n"; |
||
| 452 | // Data only |
||
| 453 | echo '<tr><th class="data left" rowspan="2">'; |
||
| 454 | echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" checked=\"checked\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
||
| 455 | echo "<td>{$lang['strformat']}</td>\n"; |
||
| 456 | echo "<td><select name=\"d_format\">\n"; |
||
| 457 | echo "<option value=\"copy\">COPY</option>\n"; |
||
| 458 | echo "<option value=\"sql\">SQL</option>\n"; |
||
| 459 | echo "</select>\n</td>\n</tr>\n"; |
||
| 460 | echo "<tr><td><label for=\"d_oids\">{$lang['stroids']}</label></td><td><input type=\"checkbox\" id=\"d_oids\" name=\"d_oids\" /></td>\n</tr>\n"; |
||
| 461 | // Structure only |
||
| 462 | echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n"; |
||
| 463 | echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n"; |
||
| 464 | // Structure and data |
||
| 465 | echo '<tr><th class="data left" rowspan="3">'; |
||
| 466 | echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
||
| 467 | echo "<td>{$lang['strformat']}</td>\n"; |
||
| 468 | echo "<td><select name=\"sd_format\">\n"; |
||
| 469 | echo "<option value=\"copy\">COPY</option>\n"; |
||
| 470 | echo "<option value=\"sql\">SQL</option>\n"; |
||
| 471 | echo "</select>\n</td>\n</tr>\n"; |
||
| 472 | echo "<tr><td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n"; |
||
| 473 | echo "<tr><td><label for=\"sd_oids\">{$lang['stroids']}</label></td><td><input type=\"checkbox\" id=\"sd_oids\" name=\"sd_oids\" /></td>\n</tr>\n"; |
||
| 474 | echo "</table>\n"; |
||
| 475 | |||
| 476 | echo "<h3>{$lang['stroptions']}</h3>\n"; |
||
| 477 | echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
||
| 478 | echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label>\n"; |
||
| 479 | // MSIE cannot download gzip in SSL mode - it's just broken |
||
| 480 | if (!(strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS']))) { |
||
| 481 | echo "<br /><input type=\"radio\" id=\"output3\" name=\"output\" value=\"gzipped\" /><label for=\"output3\">{$lang['strdownloadgzipped']}</label>\n"; |
||
| 482 | } |
||
| 483 | echo "</p>\n"; |
||
| 484 | echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
||
| 485 | echo "<input type=\"hidden\" name=\"subject\" value=\"database\" />\n"; |
||
| 486 | echo $misc->form; |
||
| 487 | echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
||
| 488 | echo "</form>\n"; |
||
| 489 | } |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Show the current status of all database variables |
||
| 493 | */ |
||
| 494 | public function doVariables() |
||
| 520 | } |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Show all current database connections and any queries they |
||
| 524 | * are running. |
||
| 525 | */ |
||
| 526 | public function doProcesses($msg = '') |
||
| 544 | } |
||
| 545 | |||
| 546 | public function currentProcesses($isAjax = false) |
||
|
2 ignored issues
–
show
|
|||
| 547 | { |
||
| 548 | $conf = $this->conf; |
||
| 549 | $misc = $this->misc; |
||
| 550 | $lang = $this->lang; |
||
| 551 | $data = $misc->getDatabaseAccessor(); |
||
| 552 | |||
| 553 | // Display prepared transactions |
||
| 554 | if ($data->hasPreparedXacts()) { |
||
| 555 | echo "<h3>{$lang['strpreparedxacts']}</h3>\n"; |
||
| 556 | $prep_xacts = $data->getPreparedXacts($_REQUEST['database']); |
||
| 557 | |||
| 558 | $columns = [ |
||
| 559 | 'transaction' => [ |
||
| 560 | 'title' => $lang['strxactid'], |
||
| 561 | 'field' => Decorator::field('transaction'), |
||
| 562 | ], |
||
| 563 | 'gid' => [ |
||
| 564 | 'title' => $lang['strgid'], |
||
| 565 | 'field' => Decorator::field('gid'), |
||
| 566 | ], |
||
| 567 | 'prepared' => [ |
||
| 568 | 'title' => $lang['strstarttime'], |
||
| 569 | 'field' => Decorator::field('prepared'), |
||
| 570 | ], |
||
| 571 | 'owner' => [ |
||
| 572 | 'title' => $lang['strowner'], |
||
| 573 | 'field' => Decorator::field('owner'), |
||
| 574 | ], |
||
| 575 | ]; |
||
| 576 | |||
| 577 | $actions = []; |
||
| 578 | |||
| 579 | echo $this->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $lang['strnodata']); |
||
| 580 | } |
||
| 581 | |||
| 582 | // Fetch the processes from the database |
||
| 583 | echo "<h3>{$lang['strprocesses']}</h3>\n"; |
||
| 584 | $processes = $data->getProcesses($_REQUEST['database']); |
||
| 585 | |||
| 586 | $columns = [ |
||
| 587 | 'user' => [ |
||
| 588 | 'title' => $lang['strusername'], |
||
| 589 | 'field' => Decorator::field('usename'), |
||
| 590 | ], |
||
| 591 | 'process' => [ |
||
| 592 | 'title' => $lang['strprocess'], |
||
| 593 | 'field' => Decorator::field('pid'), |
||
| 594 | ], |
||
| 595 | 'application_name' => [ |
||
| 596 | 'title' => 'application', |
||
| 597 | 'field' => Decorator::field('application_name'), |
||
| 598 | ], |
||
| 599 | 'client_addr' => [ |
||
| 600 | 'title' => 'address', |
||
| 601 | 'field' => Decorator::field('client_addr'), |
||
| 602 | ], |
||
| 603 | 'blocked' => [ |
||
| 604 | 'title' => $lang['strblocked'], |
||
| 605 | 'field' => Decorator::field('waiting'), |
||
| 606 | ], |
||
| 607 | 'query' => [ |
||
| 608 | 'title' => $lang['strsql'], |
||
| 609 | 'field' => Decorator::field('query'), |
||
| 610 | ], |
||
| 611 | 'start_time' => [ |
||
| 612 | 'title' => $lang['strstarttime'], |
||
| 613 | 'field' => Decorator::field('query_start'), |
||
| 614 | ], |
||
| 615 | ]; |
||
| 616 | |||
| 617 | // Build possible actions for our process list |
||
| 618 | $columns['actions'] = ['title' => $lang['stractions']]; |
||
| 619 | |||
| 620 | $actions = []; |
||
| 621 | if ($data->hasUserSignals() || $data->isSuperUser()) { |
||
| 622 | $actions = [ |
||
| 623 | 'cancel' => [ |
||
| 624 | 'content' => $lang['strcancel'], |
||
| 625 | 'attr' => [ |
||
| 626 | 'href' => [ |
||
| 627 | 'url' => 'database.php', |
||
| 628 | 'urlvars' => [ |
||
| 629 | 'action' => 'signal', |
||
| 630 | 'signal' => 'CANCEL', |
||
| 631 | 'pid' => Decorator::field('pid'), |
||
| 632 | ], |
||
| 633 | ], |
||
| 634 | ], |
||
| 635 | ], |
||
| 636 | 'kill' => [ |
||
| 637 | 'content' => $lang['strkill'], |
||
| 638 | 'attr' => [ |
||
| 639 | 'href' => [ |
||
| 640 | 'url' => 'database.php', |
||
| 641 | 'urlvars' => [ |
||
| 642 | 'action' => 'signal', |
||
| 643 | 'signal' => 'KILL', |
||
| 644 | 'pid' => Decorator::field('pid'), |
||
| 645 | ], |
||
| 646 | ], |
||
| 647 | ], |
||
| 648 | ], |
||
| 649 | ]; |
||
| 650 | |||
| 651 | // Remove actions where not supported |
||
| 652 | if (!$data->hasQueryKill()) { |
||
| 653 | unset($actions['kill']); |
||
| 654 | } |
||
| 655 | |||
| 656 | if (!$data->hasQueryCancel()) { |
||
| 657 | unset($actions['cancel']); |
||
| 658 | } |
||
| 659 | } |
||
| 660 | |||
| 661 | if (count($actions) == 0) { |
||
| 662 | unset($columns['actions']); |
||
| 663 | } |
||
| 664 | |||
| 665 | echo $this->printTable($processes, $columns, $actions, 'database-processes', $lang['strnodata']); |
||
| 666 | |||
| 667 | return; |
||
| 668 | } |
||
| 669 | |||
| 670 | public function currentLocks($isAjax = false) |
||
| 720 | } |
||
| 721 | |||
| 722 | /** |
||
| 723 | * Show the existing table locks in the current database |
||
| 724 | */ |
||
| 725 | public function doLocks() |
||
| 726 | { |
||
| 727 | $conf = $this->conf; |
||
| 728 | $misc = $this->misc; |
||
| 729 | $lang = $this->lang; |
||
| 730 | $data = $misc->getDatabaseAccessor(); |
||
| 731 | |||
| 732 | $this->printTrail('database'); |
||
| 733 | $this->printTabs('database', 'locks'); |
||
| 734 | |||
| 735 | echo '<br /><a id="control" href=""><img src="' . $misc->icon('Refresh') . "\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/> {$lang['strrefresh']}</a>"; |
||
| 736 | |||
| 737 | echo '<div id="data_block">'; |
||
| 738 | $this->currentLocks(); |
||
| 739 | echo '</div>'; |
||
| 740 | } |
||
| 741 | |||
| 742 | /** |
||
| 743 | * Allow execution of arbitrary SQL statements on a database |
||
| 744 | */ |
||
| 745 | public function doSQL() |
||
| 783 | } |
||
| 784 | |||
| 785 | /** |
||
| 786 | * This functions does pretty much nothing. It's meant to implement |
||
| 787 | * an abstract method of AdminTrait |
||
| 788 | * |
||
| 789 | * @param string $msg The message |
||
| 790 | * |
||
| 791 | * @return string The message |
||
| 792 | */ |
||
| 793 | public function doDefault($msg = '') |
||
| 798 |