Conditions | 50 |
Paths | > 20000 |
Total Lines | 328 |
Code Lines | 233 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
396 | protected function displayTableList() |
||
397 | { |
||
398 | // filtering |
||
399 | $this->response->addHTML( |
||
400 | $this->template->render('filter', ['filter_value' => '']) |
||
401 | ); |
||
402 | // table form |
||
403 | $this->response->addHTML( |
||
404 | $this->template->render('database/structure/table_header', [ |
||
405 | 'db' => $this->db, |
||
406 | 'db_is_system_schema' => $this->_db_is_system_schema, |
||
407 | 'replication' => $GLOBALS['replication_info']['slave']['status'], |
||
408 | 'properties_num_columns' => $GLOBALS['cfg']['PropertiesNumColumns'], |
||
409 | 'is_show_stats' => $GLOBALS['is_show_stats'], |
||
410 | 'show_charset' => $GLOBALS['cfg']['ShowDbStructureCharset'], |
||
411 | 'show_comment' => $GLOBALS['cfg']['ShowDbStructureComment'], |
||
412 | 'show_creation' => $GLOBALS['cfg']['ShowDbStructureCreation'], |
||
413 | 'show_last_update' => $GLOBALS['cfg']['ShowDbStructureLastUpdate'], |
||
414 | 'show_last_check' => $GLOBALS['cfg']['ShowDbStructureLastCheck'], |
||
415 | 'num_favorite_tables' => $GLOBALS['cfg']['NumFavoriteTables'], |
||
416 | ]) |
||
417 | ); |
||
418 | |||
419 | $i = $sum_entries = 0; |
||
420 | $overhead_check = false; |
||
421 | $create_time_all = ''; |
||
422 | $update_time_all = ''; |
||
423 | $check_time_all = ''; |
||
424 | $num_columns = $GLOBALS['cfg']['PropertiesNumColumns'] > 1 |
||
425 | ? ceil($this->_num_tables / $GLOBALS['cfg']['PropertiesNumColumns']) + 1 |
||
426 | : 0; |
||
427 | $row_count = 0; |
||
428 | $sum_size = 0; |
||
429 | $overhead_size = 0; |
||
430 | |||
431 | $hidden_fields = []; |
||
432 | $overall_approx_rows = false; |
||
433 | foreach ($this->_tables as $keyname => $current_table) { |
||
434 | // Get valid statistics whatever is the table type |
||
435 | |||
436 | $drop_query = ''; |
||
437 | $drop_message = ''; |
||
438 | $overhead = ''; |
||
439 | $input_class = ['checkall']; |
||
440 | |||
441 | $table_is_view = false; |
||
|
|||
442 | // Sets parameters for links |
||
443 | $tbl_url_query = Url::getCommon( |
||
444 | [ |
||
445 | 'db' => $this->db, |
||
446 | 'table' => $current_table['TABLE_NAME'], |
||
447 | ] |
||
448 | ); |
||
449 | // do not list the previous table's size info for a view |
||
450 | |||
451 | list($current_table, $formatted_size, $unit, $formatted_overhead, |
||
452 | $overhead_unit, $overhead_size, $table_is_view, $sum_size) |
||
453 | = $this->getStuffForEngineTypeTable( |
||
454 | $current_table, |
||
455 | $sum_size, |
||
456 | $overhead_size |
||
457 | ); |
||
458 | |||
459 | $curTable = $this->dbi |
||
460 | ->getTable($this->db, $current_table['TABLE_NAME']); |
||
461 | if (! $curTable->isMerge()) { |
||
462 | $sum_entries += $current_table['TABLE_ROWS']; |
||
463 | } |
||
464 | |||
465 | if (isset($current_table['Collation'])) { |
||
466 | $collation = '<dfn title="' |
||
467 | . Charsets::getCollationDescr($current_table['Collation']) . '">' |
||
468 | . $current_table['Collation'] . '</dfn>'; |
||
469 | } else { |
||
470 | $collation = '---'; |
||
471 | } |
||
472 | |||
473 | if ($this->_is_show_stats) { |
||
474 | if ($formatted_overhead != '') { |
||
475 | $overhead = '<a href="tbl_structure.php' |
||
476 | . $tbl_url_query . '#showusage">' |
||
477 | . '<span>' . $formatted_overhead . '</span> ' |
||
478 | . '<span class="unit">' . $overhead_unit . '</span>' |
||
479 | . '</a>' . "\n"; |
||
480 | $overhead_check = true; |
||
481 | $input_class[] = 'tbl-overhead'; |
||
482 | } else { |
||
483 | $overhead = '-'; |
||
484 | } |
||
485 | } // end if |
||
486 | |||
487 | if ($GLOBALS['cfg']['ShowDbStructureCharset']) { |
||
488 | if (isset($current_table['Collation'])) { |
||
489 | $charset = mb_substr($collation, 0, mb_strpos($collation, "_")); |
||
490 | } else { |
||
491 | $charset = ''; |
||
492 | } |
||
493 | } |
||
494 | |||
495 | if ($GLOBALS['cfg']['ShowDbStructureCreation']) { |
||
496 | $create_time = isset($current_table['Create_time']) |
||
497 | ? $current_table['Create_time'] : ''; |
||
498 | if ($create_time |
||
499 | && (! $create_time_all |
||
500 | || $create_time < $create_time_all) |
||
501 | ) { |
||
502 | $create_time_all = $create_time; |
||
503 | } |
||
504 | } |
||
505 | |||
506 | if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) { |
||
507 | $update_time = isset($current_table['Update_time']) |
||
508 | ? $current_table['Update_time'] : ''; |
||
509 | if ($update_time |
||
510 | && (! $update_time_all |
||
511 | || $update_time < $update_time_all) |
||
512 | ) { |
||
513 | $update_time_all = $update_time; |
||
514 | } |
||
515 | } |
||
516 | |||
517 | if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) { |
||
518 | $check_time = isset($current_table['Check_time']) |
||
519 | ? $current_table['Check_time'] : ''; |
||
520 | if ($check_time |
||
521 | && (! $check_time_all |
||
522 | || $check_time < $check_time_all) |
||
523 | ) { |
||
524 | $check_time_all = $check_time; |
||
525 | } |
||
526 | } |
||
527 | |||
528 | $truename = ! empty($tooltip_truename) |
||
529 | && isset($tooltip_truename[$current_table['TABLE_NAME']]) |
||
530 | ? $tooltip_truename[$current_table['TABLE_NAME']] |
||
531 | : $current_table['TABLE_NAME']; |
||
532 | |||
533 | $i++; |
||
534 | |||
535 | $row_count++; |
||
536 | if ($table_is_view) { |
||
537 | $hidden_fields[] = '<input type="hidden" name="views[]" value="' |
||
538 | . htmlspecialchars($current_table['TABLE_NAME']) . '">'; |
||
539 | } |
||
540 | |||
541 | /* |
||
542 | * Always activate links for Browse, Search and Empty, even if |
||
543 | * the icons are greyed, because |
||
544 | * 1. for views, we don't know the number of rows at this point |
||
545 | * 2. for tables, another source could have populated them since the |
||
546 | * page was generated |
||
547 | * |
||
548 | * I could have used the PHP ternary conditional operator but I find |
||
549 | * the code easier to read without this operator. |
||
550 | */ |
||
551 | $may_have_rows = $current_table['TABLE_ROWS'] > 0 || $table_is_view; |
||
552 | $titles = Util::buildActionTitles(); |
||
553 | |||
554 | if (! $this->_db_is_system_schema) { |
||
555 | $drop_query = sprintf( |
||
556 | 'DROP %s %s', |
||
557 | $table_is_view || $current_table['ENGINE'] == null ? 'VIEW' |
||
558 | : 'TABLE', |
||
559 | Util::backquote( |
||
560 | $current_table['TABLE_NAME'] |
||
561 | ) |
||
562 | ); |
||
563 | $drop_message = sprintf( |
||
564 | ($table_is_view || $current_table['ENGINE'] == null |
||
565 | ? __('View %s has been dropped.') |
||
566 | : __('Table %s has been dropped.')), |
||
567 | str_replace( |
||
568 | ' ', |
||
569 | ' ', |
||
570 | htmlspecialchars($current_table['TABLE_NAME']) |
||
571 | ) |
||
572 | ); |
||
573 | } |
||
574 | |||
575 | if ($num_columns > 0 |
||
576 | && $this->_num_tables > $num_columns |
||
577 | && ($row_count % $num_columns) == 0 |
||
578 | ) { |
||
579 | $row_count = 1; |
||
580 | |||
581 | $this->response->addHTML( |
||
582 | '</tr></tbody></table></div></form>' |
||
583 | ); |
||
584 | |||
585 | $this->response->addHTML( |
||
586 | $this->template->render('database/structure/table_header', [ |
||
587 | 'db' => $this->db, |
||
588 | 'db_is_system_schema' => $this->_db_is_system_schema, |
||
589 | 'replication' => $GLOBALS['replication_info']['slave']['status'], |
||
590 | 'properties_num_columns' => $GLOBALS['cfg']['PropertiesNumColumns'], |
||
591 | 'is_show_stats' => $GLOBALS['is_show_stats'], |
||
592 | 'show_charset' => $GLOBALS['cfg']['ShowDbStructureCharset'], |
||
593 | 'show_comment' => $GLOBALS['cfg']['ShowDbStructureComment'], |
||
594 | 'show_creation' => $GLOBALS['cfg']['ShowDbStructureCreation'], |
||
595 | 'show_last_update' => $GLOBALS['cfg']['ShowDbStructureLastUpdate'], |
||
596 | 'show_last_check' => $GLOBALS['cfg']['ShowDbStructureLastCheck'], |
||
597 | 'num_favorite_tables' => $GLOBALS['cfg']['NumFavoriteTables'], |
||
598 | ]) |
||
599 | ); |
||
600 | } |
||
601 | |||
602 | list($approx_rows, $show_superscript) = $this->isRowCountApproximated( |
||
603 | $current_table, |
||
604 | $table_is_view |
||
605 | ); |
||
606 | |||
607 | list($do, $ignored) = $this->getReplicationStatus($truename); |
||
608 | |||
609 | $this->response->addHTML( |
||
610 | $this->template->render('database/structure/structure_table_row', [ |
||
611 | 'table_name_hash' => md5($current_table['TABLE_NAME']), |
||
612 | 'db_table_name_hash' => md5($this->db . '.' . $current_table['TABLE_NAME']), |
||
613 | 'db' => $this->db, |
||
614 | 'curr' => $i, |
||
615 | 'input_class' => implode(' ', $input_class), |
||
616 | 'table_is_view' => $table_is_view, |
||
617 | 'current_table' => $current_table, |
||
618 | 'browse_table_title' => $may_have_rows ? $titles['Browse'] : $titles['NoBrowse'], |
||
619 | 'search_table_title' => $may_have_rows ? $titles['Search'] : $titles['NoSearch'], |
||
620 | 'browse_table_label_title' => htmlspecialchars($current_table['TABLE_COMMENT']), |
||
621 | 'browse_table_label_truename' => $truename, |
||
622 | 'empty_table_sql_query' => urlencode( |
||
623 | 'TRUNCATE ' . Util::backquote( |
||
624 | $current_table['TABLE_NAME'] |
||
625 | ) |
||
626 | ), |
||
627 | 'empty_table_message_to_show' => urlencode( |
||
628 | sprintf( |
||
629 | __('Table %s has been emptied.'), |
||
630 | htmlspecialchars( |
||
631 | $current_table['TABLE_NAME'] |
||
632 | ) |
||
633 | ) |
||
634 | ), |
||
635 | 'empty_table_title' => $may_have_rows ? $titles['Empty'] : $titles['NoEmpty'], |
||
636 | 'tracking_icon' => $this->getTrackingIcon($truename), |
||
637 | 'server_slave_status' => $GLOBALS['replication_info']['slave']['status'], |
||
638 | 'tbl_url_query' => $tbl_url_query, |
||
639 | 'db_is_system_schema' => $this->_db_is_system_schema, |
||
640 | 'titles' => $titles, |
||
641 | 'drop_query' => $drop_query, |
||
642 | 'drop_message' => $drop_message, |
||
643 | 'collation' => $collation, |
||
644 | 'formatted_size' => $formatted_size, |
||
645 | 'unit' => $unit, |
||
646 | 'overhead' => $overhead, |
||
647 | 'create_time' => isset($create_time) && $create_time |
||
648 | ? Util::localisedDate(strtotime($create_time)) : '-', |
||
649 | 'update_time' => isset($update_time) && $update_time |
||
650 | ? Util::localisedDate(strtotime($update_time)) : '-', |
||
651 | 'check_time' => isset($check_time) && $check_time |
||
652 | ? Util::localisedDate(strtotime($check_time)) : '-', |
||
653 | 'charset' => isset($charset) |
||
654 | ? $charset : '', |
||
655 | 'is_show_stats' => $this->_is_show_stats, |
||
656 | 'ignored' => $ignored, |
||
657 | 'do' => $do, |
||
658 | 'approx_rows' => $approx_rows, |
||
659 | 'show_superscript' => $show_superscript, |
||
660 | 'already_favorite' => $this->checkFavoriteTable( |
||
661 | $current_table['TABLE_NAME'] |
||
662 | ), |
||
663 | 'num_favorite_tables' => $GLOBALS['cfg']['NumFavoriteTables'], |
||
664 | 'properties_num_columns' => $GLOBALS['cfg']['PropertiesNumColumns'], |
||
665 | 'limit_chars' => $GLOBALS['cfg']['LimitChars'], |
||
666 | 'show_charset' => $GLOBALS['cfg']['ShowDbStructureCharset'], |
||
667 | 'show_comment' => $GLOBALS['cfg']['ShowDbStructureComment'], |
||
668 | 'show_creation' => $GLOBALS['cfg']['ShowDbStructureCreation'], |
||
669 | 'show_last_update' => $GLOBALS['cfg']['ShowDbStructureLastUpdate'], |
||
670 | 'show_last_check' => $GLOBALS['cfg']['ShowDbStructureLastCheck'], |
||
671 | ]) |
||
672 | ); |
||
673 | |||
674 | $overall_approx_rows = $overall_approx_rows || $approx_rows; |
||
675 | } // end foreach |
||
676 | |||
677 | $this->response->addHTML('</tbody>'); |
||
678 | |||
679 | $db_collation = $this->dbi->getDbCollation($this->db); |
||
680 | $db_charset = mb_substr($db_collation, 0, mb_strpos($db_collation, "_")); |
||
681 | |||
682 | // Show Summary |
||
683 | $this->response->addHTML( |
||
684 | $this->template->render('database/structure/body_for_table_summary', [ |
||
685 | 'num_tables' => $this->_num_tables, |
||
686 | 'server_slave_status' => $GLOBALS['replication_info']['slave']['status'], |
||
687 | 'db_is_system_schema' => $this->_db_is_system_schema, |
||
688 | 'sum_entries' => $sum_entries, |
||
689 | 'db_collation' => $db_collation, |
||
690 | 'is_show_stats' => $this->_is_show_stats, |
||
691 | 'db_charset' => $db_charset, |
||
692 | 'sum_size' => $sum_size, |
||
693 | 'overhead_size' => $overhead_size, |
||
694 | 'create_time_all' => $create_time_all ? Util::localisedDate(strtotime($create_time_all)) : '-', |
||
695 | 'update_time_all' => $update_time_all ? Util::localisedDate(strtotime($update_time_all)) : '-', |
||
696 | 'check_time_all' => $check_time_all ? Util::localisedDate(strtotime($check_time_all)) : '-', |
||
697 | 'approx_rows' => $overall_approx_rows, |
||
698 | 'num_favorite_tables' => $GLOBALS['cfg']['NumFavoriteTables'], |
||
699 | 'db' => $GLOBALS['db'], |
||
700 | 'properties_num_columns' => $GLOBALS['cfg']['PropertiesNumColumns'], |
||
701 | 'dbi' => $this->dbi, |
||
702 | 'show_charset' => $GLOBALS['cfg']['ShowDbStructureCharset'], |
||
703 | 'show_comment' => $GLOBALS['cfg']['ShowDbStructureComment'], |
||
704 | 'show_creation' => $GLOBALS['cfg']['ShowDbStructureCreation'], |
||
705 | 'show_last_update' => $GLOBALS['cfg']['ShowDbStructureLastUpdate'], |
||
706 | 'show_last_check' => $GLOBALS['cfg']['ShowDbStructureLastCheck'], |
||
707 | ]) |
||
708 | ); |
||
709 | $this->response->addHTML('</table>'); |
||
710 | |||
711 | //check all |
||
712 | $this->response->addHTML( |
||
713 | $this->template->render('database/structure/check_all_tables', [ |
||
714 | 'pma_theme_image' => $GLOBALS['pmaThemeImage'], |
||
715 | 'text_dir' => $GLOBALS['text_dir'], |
||
716 | 'overhead_check' => $overhead_check, |
||
717 | 'db_is_system_schema' => $this->_db_is_system_schema, |
||
718 | 'hidden_fields' => $hidden_fields, |
||
719 | 'disable_multi_table' => $GLOBALS['cfg']['DisableMultiTableMaintenance'], |
||
720 | 'central_columns_work' => $GLOBALS['cfgRelation']['centralcolumnswork'], |
||
721 | ]) |
||
722 | ); |
||
723 | $this->response->addHTML('</form>'); //end of form |
||
724 | } |
||
1147 |