154 lines
4.9 KiB
PHP
154 lines
4.9 KiB
PHP
<?php
|
|
/**
|
|
* Wizard Step 5 — Verification.
|
|
*
|
|
* Compares expected totals (from the Analysis step) with actual log counts
|
|
* and provides a downloadable CSV export of the full migration log.
|
|
*
|
|
* @package Robotstxt_Mlp2_Mlp5
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Class Robotstxt_Mlp2_Mlp5_Step_Verification
|
|
*/
|
|
class Robotstxt_Mlp2_Mlp5_Step_Verification {
|
|
|
|
/**
|
|
* Build the verification summary.
|
|
*
|
|
* @return array[] Rows keyed by context with expected/migrated/skipped/errors.
|
|
*/
|
|
public static function get_summary(): array {
|
|
$analysis = Robotstxt_Mlp2_Mlp5_Wizard_State::get_step_data( 2 );
|
|
|
|
$contexts = array(
|
|
'site_relation' => array(
|
|
'label' => __( 'Site Relations', 'robotstxt-mlp2-mlp5' ),
|
|
'expected' => (int) ( $analysis['site_relations_count'] ?? 0 ),
|
|
),
|
|
'post_relation' => array(
|
|
'label' => __( 'Post Relations', 'robotstxt-mlp2-mlp5' ),
|
|
'expected' => (int) ( $analysis['post_groups_count'] ?? 0 ),
|
|
),
|
|
'term_relation' => array(
|
|
'label' => __( 'Term Relations', 'robotstxt-mlp2-mlp5' ),
|
|
'expected' => (int) ( $analysis['term_groups_count'] ?? 0 ),
|
|
),
|
|
);
|
|
|
|
$summary = array();
|
|
foreach ( $contexts as $context => $meta ) {
|
|
$summary[ $context ] = array(
|
|
'label' => $meta['label'],
|
|
'expected' => $meta['expected'],
|
|
'migrated' => Robotstxt_Mlp2_Mlp5_Logger::count(
|
|
array(
|
|
'type' => 'success',
|
|
'context' => $context,
|
|
)
|
|
),
|
|
'skipped' => Robotstxt_Mlp2_Mlp5_Logger::count(
|
|
array(
|
|
'type' => 'skipped',
|
|
'context' => $context,
|
|
)
|
|
),
|
|
'errors' => Robotstxt_Mlp2_Mlp5_Logger::count(
|
|
array(
|
|
'type' => 'error',
|
|
'context' => $context,
|
|
)
|
|
),
|
|
);
|
|
}
|
|
|
|
return $summary;
|
|
}
|
|
|
|
/**
|
|
* Handle the CSV export request.
|
|
*
|
|
* Must be called on network_admin_init when the export GET param is present.
|
|
*/
|
|
public static function maybe_export_csv(): void {
|
|
check_admin_referer( 'mlp_migrator_export_log', 'mlp_export_nonce' );
|
|
|
|
if ( ! current_user_can( 'manage_network' ) ) {
|
|
wp_die( esc_html__( 'You do not have permission to export the log.', 'robotstxt-mlp2-mlp5' ) );
|
|
}
|
|
|
|
$csv = Robotstxt_Mlp2_Mlp5_Logger::export_csv();
|
|
|
|
header( 'Content-Type: text/csv; charset=UTF-8' );
|
|
header( 'Content-Disposition: attachment; filename="mlp-migration-log.csv"' );
|
|
header( 'Pragma: no-cache' );
|
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
echo $csv;
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Render the Step 5 UI.
|
|
*/
|
|
public static function render(): void {
|
|
$summary = self::get_summary();
|
|
$export_url = wp_nonce_url(
|
|
admin_url( 'admin-post.php?action=mlp_migrator_export_log' ),
|
|
'mlp_migrator_export_log',
|
|
'mlp_export_nonce'
|
|
);
|
|
?>
|
|
<h2><?php esc_html_e( 'Step 5 — Verification', 'robotstxt-mlp2-mlp5' ); ?></h2>
|
|
<p><?php esc_html_e( 'Compare expected totals (from the Analysis step) with actual migration results. Download the full log before proceeding to cleanup.', 'robotstxt-mlp2-mlp5' ); ?></p>
|
|
|
|
<table class="widefat striped" style="border:0;margin-bottom:1.5em;">
|
|
<thead>
|
|
<tr>
|
|
<th><?php esc_html_e( 'Category', 'robotstxt-mlp2-mlp5' ); ?></th>
|
|
<th><?php esc_html_e( 'Expected', 'robotstxt-mlp2-mlp5' ); ?></th>
|
|
<th><?php esc_html_e( 'Migrated', 'robotstxt-mlp2-mlp5' ); ?></th>
|
|
<th><?php esc_html_e( 'Skipped', 'robotstxt-mlp2-mlp5' ); ?></th>
|
|
<th><?php esc_html_e( 'Errors', 'robotstxt-mlp2-mlp5' ); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ( $summary as $row ) : ?>
|
|
<?php
|
|
$color = '#46b450'; // Green.
|
|
if ( (int) $row['errors'] > 0 ) {
|
|
$color = '#dba617'; // Amber.
|
|
}
|
|
if ( 0 === (int) $row['migrated'] && (int) $row['expected'] > 0 ) {
|
|
$color = '#d63638'; // Red.
|
|
}
|
|
?>
|
|
<tr style="border-left:4px solid <?php echo esc_attr( $color ); ?>;">
|
|
<td><?php echo esc_html( $row['label'] ); ?></td>
|
|
<td><?php echo esc_html( number_format_i18n( (int) $row['expected'] ) ); ?></td>
|
|
<td><?php echo esc_html( number_format_i18n( (int) $row['migrated'] ) ); ?></td>
|
|
<td><?php echo esc_html( number_format_i18n( (int) $row['skipped'] ) ); ?></td>
|
|
<td><?php echo esc_html( number_format_i18n( (int) $row['errors'] ) ); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<p>
|
|
<a href="<?php echo esc_url( $export_url ); ?>" class="button button-secondary">
|
|
<?php esc_html_e( 'Download log (CSV)', 'robotstxt-mlp2-mlp5' ); ?>
|
|
</a>
|
|
</p>
|
|
|
|
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
|
|
<?php wp_nonce_field( 'mlp_migrator_step_5', 'mlp_migrator_nonce' ); ?>
|
|
<input type="hidden" name="action" value="mlp_migrator_step" />
|
|
<input type="hidden" name="mlp_migrator_step_action" value="5" />
|
|
<p><button type="submit" class="button button-primary"><?php esc_html_e( 'Next: Cleanup', 'robotstxt-mlp2-mlp5' ); ?></button></p>
|
|
</form>
|
|
<?php
|
|
}
|
|
}
|