Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| MigrationReport | |
0.00% |
0 / 42 |
|
0.00% |
0 / 4 |
182 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| add_page | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| get_report_page | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
110 | |||
| get_report_content | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace NewfoldLabs\WP\Module\Migration\Reports; |
| 3 | |
| 4 | use NewfoldLabs\WP\Module\Migration\Services\Tracker; |
| 5 | use NewfoldLabs\WP\Module\Migration\Helpers\Permissions; |
| 6 | /** |
| 7 | * Class to add a page report to see the tracking informations. |
| 8 | * |
| 9 | * @package wp-module-migration |
| 10 | */ |
| 11 | class MigrationReport { |
| 12 | /** |
| 13 | * Identifier for page and assets. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | public static $slug = 'nfd-migration'; |
| 18 | |
| 19 | /** |
| 20 | * The tracker instance. |
| 21 | * |
| 22 | * @var Tracker |
| 23 | */ |
| 24 | protected $tracker; |
| 25 | |
| 26 | /** |
| 27 | * UIReport constructor. |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | $this->tracker = new Tracker(); |
| 31 | add_action( 'admin_menu', array( $this, 'add_page' ) ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Add the report page to the admin menu. |
| 36 | * |
| 37 | * @return void |
| 38 | */ |
| 39 | public function add_page() { |
| 40 | $hook = add_submenu_page( |
| 41 | self::$slug, |
| 42 | __( 'Migration Report', 'wp-module-migration' ), |
| 43 | '', |
| 44 | Permissions::ADMIN, |
| 45 | self::$slug, |
| 46 | array( $this, 'get_report_page' ), |
| 47 | ); |
| 48 | |
| 49 | remove_menu_page( $hook ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the report page callback. |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | public function get_report_page() { |
| 58 | ?> |
| 59 | <div class="wrap"> |
| 60 | <h1><?php esc_html_e( 'Migration Report', 'wp-module-migration' ); ?></h1> |
| 61 | <div class="nfd-migration-report"> |
| 62 | <?php |
| 63 | $report_content = $this->get_report_content(); |
| 64 | if ( ! empty( $report_content ) ) { |
| 65 | echo '<ul>'; |
| 66 | foreach ( $report_content as $step => $values ) { |
| 67 | echo '<li>'; |
| 68 | echo '<h3>' . esc_html( $step ) . '</h3>'; |
| 69 | foreach ( $values as $key => $value ) { |
| 70 | if ( ! empty( $value ) && ! is_array( $value ) ) { |
| 71 | echo '<ul>'; |
| 72 | echo '<li><strong>' . esc_html( $key ) . '</strong>: ' . esc_html( $value ) . '</li>'; |
| 73 | echo '</ul>'; |
| 74 | } elseif ( is_array( $value ) && ! empty( $value ) ) { |
| 75 | echo '<ul>'; |
| 76 | echo '<li><strong>' . esc_html( $key ) . '</strong>: '; |
| 77 | echo '<ul>'; |
| 78 | foreach ( $value as $sub_key => $sub_value ) { |
| 79 | if ( is_array( $sub_value ) ) { |
| 80 | echo '<pre>' . print_r( $sub_value, true ) . '</pre>'; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r, WordPress.Security.EscapeOutput.OutputNotEscaped |
| 81 | } else { |
| 82 | echo '<li>' . esc_html( $sub_key ) . ': ' . esc_html( $sub_value ) . '</li>'; |
| 83 | } |
| 84 | } |
| 85 | echo '</ul>'; |
| 86 | echo '</li>'; |
| 87 | echo '</ul>'; |
| 88 | } |
| 89 | } |
| 90 | echo '</li>'; |
| 91 | } |
| 92 | echo '</ul>'; |
| 93 | } else { |
| 94 | echo '<p class="no-report">' . esc_html__( 'No report available.', 'wp-module-migration' ) . '</p>'; |
| 95 | } |
| 96 | ?> |
| 97 | </div> |
| 98 | </div> |
| 99 | <?php |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Get the report content. |
| 104 | * |
| 105 | * @return array |
| 106 | */ |
| 107 | private function get_report_content() { |
| 108 | return $this->tracker->get_track_content(); |
| 109 | } |
| 110 | } |