Total Complexity | 117 |
Total Lines | 775 |
Duplicated Lines | 17.16 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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'; |
||
15 | public $table_place = 'database-variables'; |
||
16 | |||
17 | public function _highlight($string, $term) |
||
20 | } |
||
21 | |||
22 | public function render() |
||
112 | } |
||
113 | |||
114 | View Code Duplication | public function doTree($print = true) |
|
136 | } |
||
137 | |||
138 | /** |
||
139 | * Sends a signal to a process |
||
140 | */ |
||
141 | public function doSignal() |
||
142 | { |
||
143 | $conf = $this->conf; |
||
144 | $misc = $this->misc; |
||
145 | $lang = $this->lang; |
||
146 | $data = $misc->getDatabaseAccessor(); |
||
147 | |||
148 | $status = $data->sendSignal($_REQUEST['pid'], $_REQUEST['signal']); |
||
149 | if ($status == 0) { |
||
150 | $this->doProcesses($lang['strsignalsent']); |
||
151 | } else { |
||
152 | $this->doProcesses($lang['strsignalsentbad']); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Searches for a named database object |
||
158 | */ |
||
159 | public function doFind($confirm = true, $msg = '') |
||
160 | { |
||
161 | $conf = $this->conf; |
||
162 | $misc = $this->misc; |
||
163 | $lang = $this->lang; |
||
164 | $data = $misc->getDatabaseAccessor(); |
||
165 | |||
166 | if (!isset($_REQUEST['term'])) { |
||
167 | $_REQUEST['term'] = ''; |
||
168 | } |
||
169 | |||
170 | if (!isset($_REQUEST['filter'])) { |
||
171 | $_REQUEST['filter'] = ''; |
||
172 | } |
||
173 | |||
174 | $this->printTrail('database'); |
||
175 | $this->printTabs('database', 'find'); |
||
176 | $this->printMsg($msg); |
||
177 | |||
178 | echo '<form action="' . SUBFOLDER . "/src/views/database.php\" method=\"post\">\n"; |
||
179 | echo '<p><input name="term" value="', htmlspecialchars($_REQUEST['term']), |
||
180 | "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n"; |
||
181 | // Output list of filters. This is complex due to all the 'has' and 'conf' feature possibilities |
||
182 | echo "<select name=\"filter\">\n"; |
||
183 | echo "\t<option value=\"\"", ($_REQUEST['filter'] == '') ? ' selected="selected"' : '', ">{$lang['strallobjects']}</option>\n"; |
||
184 | echo "\t<option value=\"SCHEMA\"", ($_REQUEST['filter'] == 'SCHEMA') ? ' selected="selected"' : '', ">{$lang['strschemas']}</option>\n"; |
||
185 | echo "\t<option value=\"TABLE\"", ($_REQUEST['filter'] == 'TABLE') ? ' selected="selected"' : '', ">{$lang['strtables']}</option>\n"; |
||
186 | echo "\t<option value=\"VIEW\"", ($_REQUEST['filter'] == 'VIEW') ? ' selected="selected"' : '', ">{$lang['strviews']}</option>\n"; |
||
187 | echo "\t<option value=\"SEQUENCE\"", ($_REQUEST['filter'] == 'SEQUENCE') ? ' selected="selected"' : '', ">{$lang['strsequences']}</option>\n"; |
||
188 | echo "\t<option value=\"COLUMN\"", ($_REQUEST['filter'] == 'COLUMN') ? ' selected="selected"' : '', ">{$lang['strcolumns']}</option>\n"; |
||
189 | echo "\t<option value=\"RULE\"", ($_REQUEST['filter'] == 'RULE') ? ' selected="selected"' : '', ">{$lang['strrules']}</option>\n"; |
||
190 | echo "\t<option value=\"INDEX\"", ($_REQUEST['filter'] == 'INDEX') ? ' selected="selected"' : '', ">{$lang['strindexes']}</option>\n"; |
||
191 | echo "\t<option value=\"TRIGGER\"", ($_REQUEST['filter'] == 'TRIGGER') ? ' selected="selected"' : '', ">{$lang['strtriggers']}</option>\n"; |
||
192 | echo "\t<option value=\"CONSTRAINT\"", ($_REQUEST['filter'] == 'CONSTRAINT') ? ' selected="selected"' : '', ">{$lang['strconstraints']}</option>\n"; |
||
193 | echo "\t<option value=\"FUNCTION\"", ($_REQUEST['filter'] == 'FUNCTION') ? ' selected="selected"' : '', ">{$lang['strfunctions']}</option>\n"; |
||
194 | echo "\t<option value=\"DOMAIN\"", ($_REQUEST['filter'] == 'DOMAIN') ? ' selected="selected"' : '', ">{$lang['strdomains']}</option>\n"; |
||
195 | if ($conf['show_advanced']) { |
||
196 | echo "\t<option value=\"AGGREGATE\"", ($_REQUEST['filter'] == 'AGGREGATE') ? ' selected="selected"' : '', ">{$lang['straggregates']}</option>\n"; |
||
197 | echo "\t<option value=\"TYPE\"", ($_REQUEST['filter'] == 'TYPE') ? ' selected="selected"' : '', ">{$lang['strtypes']}</option>\n"; |
||
198 | echo "\t<option value=\"OPERATOR\"", ($_REQUEST['filter'] == 'OPERATOR') ? ' selected="selected"' : '', ">{$lang['stroperators']}</option>\n"; |
||
199 | echo "\t<option value=\"OPCLASS\"", ($_REQUEST['filter'] == 'OPCLASS') ? ' selected="selected"' : '', ">{$lang['stropclasses']}</option>\n"; |
||
200 | echo "\t<option value=\"CONVERSION\"", ($_REQUEST['filter'] == 'CONVERSION') ? ' selected="selected"' : '', ">{$lang['strconversions']}</option>\n"; |
||
201 | echo "\t<option value=\"LANGUAGE\"", ($_REQUEST['filter'] == 'LANGUAGE') ? ' selected="selected"' : '', ">{$lang['strlanguages']}</option>\n"; |
||
202 | } |
||
203 | echo "</select>\n"; |
||
204 | echo "<input type=\"submit\" value=\"{$lang['strfind']}\" />\n"; |
||
205 | echo $misc->form; |
||
206 | echo "<input type=\"hidden\" name=\"action\" value=\"find\" /></p>\n"; |
||
207 | echo "</form>\n"; |
||
208 | |||
209 | // Default focus |
||
210 | $this->setFocus('forms[0].term'); |
||
211 | |||
212 | // If a search term has been specified, then perform the search |
||
213 | // and display the results, grouped by object type |
||
214 | if ($_REQUEST['term'] != '') { |
||
215 | $rs = $data->findObject($_REQUEST['term'], $_REQUEST['filter']); |
||
216 | if ($rs->recordCount() > 0) { |
||
217 | $curr = ''; |
||
218 | while (!$rs->EOF) { |
||
219 | // Output a new header if the current type has changed, but not if it's just changed the rule type |
||
220 | if ($rs->fields['type'] != $curr) { |
||
221 | // Short-circuit in the case of changing from table rules to view rules; table cols to view cols; |
||
222 | // table constraints to domain constraints |
||
223 | if ($rs->fields['type'] == 'RULEVIEW' && $curr == 'RULETABLE') { |
||
224 | $curr = $rs->fields['type']; |
||
225 | } elseif ($rs->fields['type'] == 'COLUMNVIEW' && $curr == 'COLUMNTABLE') { |
||
226 | $curr = $rs->fields['type']; |
||
227 | } elseif ($rs->fields['type'] == 'CONSTRAINTTABLE' && $curr == 'CONSTRAINTDOMAIN') { |
||
228 | $curr = $rs->fields['type']; |
||
229 | } else { |
||
230 | if ($curr != '') { |
||
231 | echo "</ul>\n"; |
||
232 | } |
||
233 | |||
234 | $curr = $rs->fields['type']; |
||
235 | echo '<h3>'; |
||
236 | switch ($curr) { |
||
237 | case 'SCHEMA': |
||
238 | echo $lang['strschemas']; |
||
239 | break; |
||
240 | case 'TABLE': |
||
241 | echo $lang['strtables']; |
||
242 | break; |
||
243 | case 'VIEW': |
||
244 | echo $lang['strviews']; |
||
245 | break; |
||
246 | case 'SEQUENCE': |
||
247 | echo $lang['strsequences']; |
||
248 | break; |
||
249 | case 'COLUMNTABLE': |
||
250 | case 'COLUMNVIEW': |
||
251 | echo $lang['strcolumns']; |
||
252 | break; |
||
253 | case 'INDEX': |
||
254 | echo $lang['strindexes']; |
||
255 | break; |
||
256 | case 'CONSTRAINTTABLE': |
||
257 | case 'CONSTRAINTDOMAIN': |
||
258 | echo $lang['strconstraints']; |
||
259 | break; |
||
260 | case 'TRIGGER': |
||
261 | echo $lang['strtriggers']; |
||
262 | break; |
||
263 | case 'RULETABLE': |
||
264 | case 'RULEVIEW': |
||
265 | echo $lang['strrules']; |
||
266 | break; |
||
267 | case 'FUNCTION': |
||
268 | echo $lang['strfunctions']; |
||
269 | break; |
||
270 | case 'TYPE': |
||
271 | echo $lang['strtypes']; |
||
272 | break; |
||
273 | case 'DOMAIN': |
||
274 | echo $lang['strdomains']; |
||
275 | break; |
||
276 | case 'OPERATOR': |
||
277 | echo $lang['stroperators']; |
||
278 | break; |
||
279 | case 'CONVERSION': |
||
280 | echo $lang['strconversions']; |
||
281 | break; |
||
282 | case 'LANGUAGE': |
||
283 | echo $lang['strlanguages']; |
||
284 | break; |
||
285 | case 'AGGREGATE': |
||
286 | echo $lang['straggregates']; |
||
287 | break; |
||
288 | case 'OPCLASS': |
||
289 | echo $lang['stropclasses']; |
||
290 | break; |
||
291 | } |
||
292 | echo '</h3>'; |
||
293 | echo "<ul>\n"; |
||
294 | } |
||
295 | } |
||
296 | |||
297 | switch ($curr) { |
||
298 | case 'SCHEMA': |
||
299 | 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"; |
||
300 | break; |
||
301 | case 'TABLE': |
||
302 | echo '<li>'; |
||
303 | echo "<a href=\"tables.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
304 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', |
||
305 | urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
306 | break; |
||
307 | case 'VIEW': |
||
308 | echo '<li>'; |
||
309 | echo "<a href=\"views.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
310 | echo '<a href="' . SUBFOLDER . "/redirect/view?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&view=', |
||
311 | urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
312 | break; |
||
313 | View Code Duplication | case 'SEQUENCE': |
|
314 | echo '<li>'; |
||
315 | echo "<a href=\"sequences.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
316 | echo "<a href=\"sequences.php?subject=sequence&action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), |
||
317 | '&sequence=', urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
318 | break; |
||
319 | View Code Duplication | case 'COLUMNTABLE': |
|
320 | echo '<li>'; |
||
321 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
322 | 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>.'; |
||
323 | echo "<a href=\"colproperties.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', |
||
324 | urlencode($rs->fields['relname']), '&column=', urlencode($rs->fields['name']), '">', |
||
325 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
326 | break; |
||
327 | View Code Duplication | case 'COLUMNVIEW': |
|
328 | echo '<li>'; |
||
329 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
330 | 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>.'; |
||
331 | echo "<a href=\"colproperties.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&view=', |
||
332 | urlencode($rs->fields['relname']), '&column=', urlencode($rs->fields['name']), '">', |
||
333 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
334 | break; |
||
335 | View Code Duplication | case 'INDEX': |
|
336 | echo '<li>'; |
||
337 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
338 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
339 | 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"; |
||
340 | break; |
||
341 | View Code Duplication | case 'CONSTRAINTTABLE': |
|
342 | echo '<li>'; |
||
343 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
344 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
345 | echo "<a href=\"constraints.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', |
||
346 | urlencode($rs->fields['relname']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
347 | break; |
||
348 | View Code Duplication | case 'CONSTRAINTDOMAIN': |
|
349 | echo '<li>'; |
||
350 | echo "<a href=\"domains.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
351 | echo "<a href=\"domains.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&domain=', urlencode($rs->fields['relname']), '">', |
||
352 | $misc->printVal($rs->fields['relname']), '.', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
353 | break; |
||
354 | View Code Duplication | case 'TRIGGER': |
|
355 | echo '<li>'; |
||
356 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
357 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
358 | echo "<a href=\"triggers.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', urlencode($rs->fields['relname']), '">', |
||
359 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
360 | break; |
||
361 | View Code Duplication | case 'RULETABLE': |
|
362 | echo '<li>'; |
||
363 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
364 | echo '<a href="' . SUBFOLDER . "/redirect/table?{$misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
365 | echo "<a href=\"rules.php?subject=table&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&reltype=table&table=', |
||
366 | urlencode($rs->fields['relname']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
367 | break; |
||
368 | View Code Duplication | case 'RULEVIEW': |
|
369 | echo '<li>'; |
||
370 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
371 | echo '<a href="' . SUBFOLDER . "/redirect/view?{$misc->href}&view=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['relname']), '</a>.'; |
||
372 | echo "<a href=\"rules.php?subject=view&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&reltype=view&view=', |
||
373 | urlencode($rs->fields['relname']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
374 | break; |
||
375 | View Code Duplication | case 'FUNCTION': |
|
376 | echo '<li>'; |
||
377 | echo "<a href=\"functions.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
378 | echo "<a href=\"functions.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&function=', |
||
379 | urlencode($rs->fields['name']), '&function_oid=', urlencode($rs->fields['oid']), '">', |
||
380 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
381 | break; |
||
382 | View Code Duplication | case 'TYPE': |
|
383 | echo '<li>'; |
||
384 | echo "<a href=\"types.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
385 | echo "<a href=\"types.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&type=', |
||
386 | urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
387 | break; |
||
388 | View Code Duplication | case 'DOMAIN': |
|
389 | echo '<li>'; |
||
390 | echo "<a href=\"domains.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
391 | echo "<a href=\"domains.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&domain=', |
||
392 | urlencode($rs->fields['name']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
393 | break; |
||
394 | View Code Duplication | case 'OPERATOR': |
|
395 | echo '<li>'; |
||
396 | echo "<a href=\"operators.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
397 | echo "<a href=\"operators.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '&operator=', |
||
398 | urlencode($rs->fields['name']), '&operator_oid=', urlencode($rs->fields['oid']), '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
399 | break; |
||
400 | View Code Duplication | case 'CONVERSION': |
|
401 | echo '<li>'; |
||
402 | echo "<a href=\"conversions.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
403 | echo "<a href=\"conversions.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), |
||
404 | '">', $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
405 | break; |
||
406 | case 'LANGUAGE': |
||
407 | echo "<li><a href=\"languages.php?{$misc->href}\">", $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
408 | break; |
||
409 | View Code Duplication | case 'AGGREGATE': |
|
410 | echo '<li>'; |
||
411 | echo "<a href=\"aggregates.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
412 | echo "<a href=\"aggregates.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', |
||
413 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
414 | break; |
||
415 | View Code Duplication | case 'OPCLASS': |
|
416 | echo '<li>'; |
||
417 | echo '<a href="' . SUBFOLDER . "/redirect/schema?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $misc->printVal($rs->fields['schemaname']), '</a>.'; |
||
418 | echo "<a href=\"opclasses.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', |
||
419 | $this->_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n"; |
||
420 | break; |
||
421 | } |
||
422 | $rs->moveNext(); |
||
423 | } |
||
424 | echo "</ul>\n"; |
||
425 | |||
426 | echo '<p>', $rs->recordCount(), ' ', $lang['strobjects'], "</p>\n"; |
||
427 | } else { |
||
428 | echo "<p>{$lang['strnoobjects']}</p>\n"; |
||
429 | } |
||
430 | } |
||
431 | } |
||
432 | |||
433 | /** |
||
434 | * Displays options for database download |
||
435 | */ |
||
436 | public function doExport($msg = '') |
||
437 | { |
||
438 | $conf = $this->conf; |
||
439 | $misc = $this->misc; |
||
440 | $lang = $this->lang; |
||
441 | $data = $misc->getDatabaseAccessor(); |
||
442 | |||
443 | $this->printTrail('database'); |
||
444 | $this->printTabs('database', 'export'); |
||
445 | $this->printMsg($msg); |
||
446 | |||
447 | echo '<form action="' . SUBFOLDER . "/src/views/dbexport.php\" method=\"post\">\n"; |
||
448 | echo "<table>\n"; |
||
449 | echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n"; |
||
450 | // Data only |
||
451 | echo '<tr><th class="data left" rowspan="2">'; |
||
452 | echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" checked=\"checked\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
||
453 | echo "<td>{$lang['strformat']}</td>\n"; |
||
454 | echo "<td><select name=\"d_format\">\n"; |
||
455 | echo "<option value=\"copy\">COPY</option>\n"; |
||
456 | echo "<option value=\"sql\">SQL</option>\n"; |
||
457 | echo "</select>\n</td>\n</tr>\n"; |
||
458 | 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"; |
||
459 | // Structure only |
||
460 | echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n"; |
||
461 | echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n"; |
||
462 | // Structure and data |
||
463 | echo '<tr><th class="data left" rowspan="3">'; |
||
464 | echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
||
465 | echo "<td>{$lang['strformat']}</td>\n"; |
||
466 | echo "<td><select name=\"sd_format\">\n"; |
||
467 | echo "<option value=\"copy\">COPY</option>\n"; |
||
468 | echo "<option value=\"sql\">SQL</option>\n"; |
||
469 | echo "</select>\n</td>\n</tr>\n"; |
||
470 | 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"; |
||
471 | 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"; |
||
472 | echo "</table>\n"; |
||
473 | |||
474 | echo "<h3>{$lang['stroptions']}</h3>\n"; |
||
475 | echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
||
476 | echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label>\n"; |
||
477 | // MSIE cannot download gzip in SSL mode - it's just broken |
||
478 | View Code Duplication | if (!(strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS']))) { |
|
479 | echo "<br /><input type=\"radio\" id=\"output3\" name=\"output\" value=\"gzipped\" /><label for=\"output3\">{$lang['strdownloadgzipped']}</label>\n"; |
||
480 | } |
||
481 | echo "</p>\n"; |
||
482 | echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
||
483 | echo "<input type=\"hidden\" name=\"subject\" value=\"database\" />\n"; |
||
484 | echo $misc->form; |
||
485 | echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
||
486 | echo "</form>\n"; |
||
487 | } |
||
488 | |||
489 | /** |
||
490 | * Show the current status of all database variables |
||
491 | */ |
||
492 | public function doVariables() |
||
518 | } |
||
519 | |||
520 | /** |
||
521 | * Show all current database connections and any queries they |
||
522 | * are running. |
||
523 | */ |
||
524 | public function doProcesses($msg = '') |
||
542 | } |
||
543 | |||
544 | public function currentProcesses($isAjax = false) |
||
545 | { |
||
546 | $conf = $this->conf; |
||
547 | $misc = $this->misc; |
||
548 | $lang = $this->lang; |
||
549 | $data = $misc->getDatabaseAccessor(); |
||
550 | |||
551 | // Display prepared transactions |
||
552 | if ($data->hasPreparedXacts()) { |
||
553 | echo "<h3>{$lang['strpreparedxacts']}</h3>\n"; |
||
554 | $prep_xacts = $data->getPreparedXacts($_REQUEST['database']); |
||
555 | |||
556 | $columns = [ |
||
557 | 'transaction' => [ |
||
558 | 'title' => $lang['strxactid'], |
||
559 | 'field' => Decorator::field('transaction'), |
||
560 | ], |
||
561 | 'gid' => [ |
||
562 | 'title' => $lang['strgid'], |
||
563 | 'field' => Decorator::field('gid'), |
||
564 | ], |
||
565 | 'prepared' => [ |
||
566 | 'title' => $lang['strstarttime'], |
||
567 | 'field' => Decorator::field('prepared'), |
||
568 | ], |
||
569 | 'owner' => [ |
||
570 | 'title' => $lang['strowner'], |
||
571 | 'field' => Decorator::field('owner'), |
||
572 | ], |
||
573 | ]; |
||
574 | |||
575 | $actions = []; |
||
576 | |||
577 | echo $this->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $lang['strnodata']); |
||
578 | } |
||
579 | |||
580 | // Fetch the processes from the database |
||
581 | echo "<h3>{$lang['strprocesses']}</h3>\n"; |
||
582 | $processes = $data->getProcesses($_REQUEST['database']); |
||
583 | |||
584 | $columns = [ |
||
585 | 'user' => [ |
||
586 | 'title' => $lang['strusername'], |
||
587 | 'field' => Decorator::field('usename'), |
||
588 | ], |
||
589 | 'process' => [ |
||
590 | 'title' => $lang['strprocess'], |
||
591 | 'field' => Decorator::field('pid'), |
||
592 | ], |
||
593 | 'application_name' => [ |
||
594 | 'title' => 'application', |
||
595 | 'field' => Decorator::field('application_name'), |
||
596 | ], |
||
597 | 'client_addr' => [ |
||
598 | 'title' => 'address', |
||
599 | 'field' => Decorator::field('client_addr'), |
||
600 | ], |
||
601 | 'blocked' => [ |
||
602 | 'title' => $lang['strblocked'], |
||
603 | 'field' => Decorator::field('waiting'), |
||
604 | ], |
||
605 | 'query' => [ |
||
606 | 'title' => $lang['strsql'], |
||
607 | 'field' => Decorator::field('query'), |
||
608 | ], |
||
609 | 'start_time' => [ |
||
610 | 'title' => $lang['strstarttime'], |
||
611 | 'field' => Decorator::field('query_start'), |
||
612 | ], |
||
613 | ]; |
||
614 | |||
615 | // Build possible actions for our process list |
||
616 | $columns['actions'] = ['title' => $lang['stractions']]; |
||
617 | |||
618 | $actions = []; |
||
619 | if ($data->hasUserSignals() || $data->isSuperUser()) { |
||
620 | $actions = [ |
||
621 | 'cancel' => [ |
||
622 | 'content' => $lang['strcancel'], |
||
623 | 'attr' => [ |
||
624 | 'href' => [ |
||
625 | 'url' => 'database.php', |
||
626 | 'urlvars' => [ |
||
627 | 'action' => 'signal', |
||
628 | 'signal' => 'CANCEL', |
||
629 | 'pid' => Decorator::field('pid'), |
||
630 | ], |
||
631 | ], |
||
632 | ], |
||
633 | ], |
||
634 | 'kill' => [ |
||
635 | 'content' => $lang['strkill'], |
||
636 | 'attr' => [ |
||
637 | 'href' => [ |
||
638 | 'url' => 'database.php', |
||
639 | 'urlvars' => [ |
||
640 | 'action' => 'signal', |
||
641 | 'signal' => 'KILL', |
||
642 | 'pid' => Decorator::field('pid'), |
||
643 | ], |
||
644 | ], |
||
645 | ], |
||
646 | ], |
||
647 | ]; |
||
648 | |||
649 | // Remove actions where not supported |
||
650 | if (!$data->hasQueryKill()) { |
||
651 | unset($actions['kill']); |
||
652 | } |
||
653 | |||
654 | if (!$data->hasQueryCancel()) { |
||
655 | unset($actions['cancel']); |
||
656 | } |
||
657 | } |
||
658 | |||
659 | if (count($actions) == 0) { |
||
660 | unset($columns['actions']); |
||
661 | } |
||
662 | |||
663 | echo $this->printTable($processes, $columns, $actions, 'database-processes', $lang['strnodata']); |
||
664 | |||
665 | if ($isAjax) { |
||
666 | exit; |
||
667 | } |
||
668 | } |
||
669 | |||
670 | public function currentLocks($isAjax = false) |
||
721 | } |
||
722 | } |
||
723 | |||
724 | /** |
||
725 | * Show the existing table locks in the current database |
||
726 | */ |
||
727 | public function doLocks() |
||
728 | { |
||
729 | $conf = $this->conf; |
||
730 | $misc = $this->misc; |
||
731 | $lang = $this->lang; |
||
732 | $data = $misc->getDatabaseAccessor(); |
||
733 | |||
734 | $this->printTrail('database'); |
||
735 | $this->printTabs('database', 'locks'); |
||
736 | |||
737 | echo '<br /><a id="control" href=""><img src="' . $misc->icon('Refresh') . "\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/> {$lang['strrefresh']}</a>"; |
||
738 | |||
739 | echo '<div id="data_block">'; |
||
740 | $this->currentLocks(); |
||
741 | echo '</div>'; |
||
742 | } |
||
743 | |||
744 | /** |
||
745 | * Allow execution of arbitrary SQL statements on a database |
||
746 | */ |
||
747 | public function doSQL() |
||
785 | } |
||
786 | } |
||
787 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: