This commit is contained in:
Javier Casares 2026-03-02 11:22:59 +00:00
commit 5cdf7f48e5
29 changed files with 6526 additions and 0 deletions

View file

@ -0,0 +1,142 @@
<?php
/**
* Wizard Step 1 — Preflight checks.
*
* Verifies that the system is ready to run the migration:
* - MLP2 backup tables exist (preparation step was done)
* - MultilingualPress 5 is network-active
*
* @package Robotstxt_Mlp2_Mlp5
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Robotstxt_Mlp2_Mlp5_Step_Preflight
*/
class Robotstxt_Mlp2_Mlp5_Step_Preflight {
/**
* Run all preflight checks and return a structured result.
*
* @return array {
* @type bool $mlp2_tables_renamed Backup tables exist (rename step was done).
* @type bool $mlp2_original_present Original MLP2 tables still exist (rename not done).
* @type string[] $mlp2_backup_tables List of backup table names found.
* @type bool $mlp2_active MLP2 plugin is network-active (informational).
* @type string $mlp2_version MLP2 plugin version string, or empty.
* @type bool $mlp5_active MLP5 plugin is network-active.
* @type string $mlp5_version MLP5 plugin version string, or empty.
* @type bool $can_proceed True when migration may start.
* @type string[] $blocking_issues Human-readable blocking problem descriptions.
* }
*/
public static function run(): array {
$mlp2 = new Robotstxt_Mlp2_Mlp5_Detector_Mlp2();
$mlp5 = new Robotstxt_Mlp2_Mlp5_Detector_Mlp5();
$backup_tables = Robotstxt_Mlp2_Mlp5_Table_Preparer::get_backup_tables();
$issues = array();
$tables_renamed = count( $backup_tables ) > 0;
$original_present = Robotstxt_Mlp2_Mlp5_Table_Preparer::has_original_tables();
$mlp5_active = $mlp5->is_active();
if ( ! $tables_renamed ) {
if ( $original_present ) {
$issues[] = __( 'MLP2 tables have not been renamed yet. Go back to the plugin status page and click "Rename MLP2 tables".', 'robotstxt-mlp2-mlp5' );
} else {
$issues[] = __( 'No MLP2 tables found (neither original nor backup). Restore your database from a backup before proceeding.', 'robotstxt-mlp2-mlp5' );
}
}
if ( ! $mlp5_active ) {
$issues[] = __( 'MultilingualPress 5 is not network-active. Activate it before running the migration.', 'robotstxt-mlp2-mlp5' );
}
return array(
'mlp2_tables_renamed' => $tables_renamed,
'mlp2_original_present' => $original_present,
'mlp2_backup_tables' => $backup_tables,
'mlp2_active' => $mlp2->is_active(),
'mlp2_version' => $mlp2->get_version(),
'mlp5_active' => $mlp5_active,
'mlp5_version' => $mlp5->get_version(),
'can_proceed' => $tables_renamed && $mlp5_active,
'blocking_issues' => $issues,
);
}
/**
* Render the Step 1 UI.
*/
public static function render(): void {
$checks = self::run();
$can_proceed = $checks['can_proceed'];
?>
<h2><?php esc_html_e( 'Step 1 — Preflight Checks', 'robotstxt-mlp2-mlp5' ); ?></h2>
<table class="widefat striped" style="border:0;margin-bottom:1.5em;">
<tbody>
<tr>
<td style="width:60%"><?php esc_html_e( 'MLP2 backup tables (preparation done)', 'robotstxt-mlp2-mlp5' ); ?></td>
<td>
<?php if ( $checks['mlp2_tables_renamed'] ) : ?>
<span style="color:#46b450;">&#10003; <?php echo esc_html( sprintf( /* translators: %d: table count */ _n( '%d table ready', '%d tables ready', count( $checks['mlp2_backup_tables'] ), 'robotstxt-mlp2-mlp5' ), count( $checks['mlp2_backup_tables'] ) ) ); ?></span>
<?php elseif ( $checks['mlp2_original_present'] ) : ?>
<span style="color:#d63638;">&#10007; <?php esc_html_e( 'Original tables still present — rename step not done', 'robotstxt-mlp2-mlp5' ); ?></span>
<?php else : ?>
<span style="color:#d63638;">&#10007; <?php esc_html_e( 'No MLP2 tables found', 'robotstxt-mlp2-mlp5' ); ?></span>
<?php endif; ?>
</td>
</tr>
<tr>
<td><?php esc_html_e( 'MLP2 plugin (active — informational only)', 'robotstxt-mlp2-mlp5' ); ?></td>
<td>
<?php if ( $checks['mlp2_active'] ) : ?>
<span style="color:#dba617;">&#9888; <?php esc_html_e( 'Active — consider deactivating before proceeding', 'robotstxt-mlp2-mlp5' ); ?></span>
<?php else : ?>
<span style="color:#46b450;">&#10003; <?php esc_html_e( 'Inactive (expected)', 'robotstxt-mlp2-mlp5' ); ?></span>
<?php endif; ?>
</td>
</tr>
<tr>
<td><?php esc_html_e( 'MultilingualPress 5 (network-active)', 'robotstxt-mlp2-mlp5' ); ?></td>
<td>
<?php if ( $checks['mlp5_active'] ) : ?>
<span style="color:#46b450;">&#10003; <?php echo esc_html( sprintf( /* translators: %s: version */ __( 'Active (v%s)', 'robotstxt-mlp2-mlp5' ), $checks['mlp5_version'] ) ); ?></span>
<?php else : ?>
<span style="color:#d63638;">&#10007; <?php esc_html_e( 'Not active', 'robotstxt-mlp2-mlp5' ); ?></span>
<?php endif; ?>
</td>
</tr>
</tbody>
</table>
<?php if ( ! empty( $checks['blocking_issues'] ) ) : ?>
<div class="notice notice-error inline" style="margin:0 0 1em;">
<ul style="margin:.5em 0 .5em 1em;list-style:disc;">
<?php foreach ( $checks['blocking_issues'] as $issue ) : ?>
<li><?php echo esc_html( $issue ); ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
<?php wp_nonce_field( 'mlp_migrator_step_1', 'mlp_migrator_nonce' ); ?>
<input type="hidden" name="action" value="mlp_migrator_step" />
<input type="hidden" name="mlp_migrator_step_action" value="1" />
<p>
<button type="submit" class="button button-primary"<?php echo $can_proceed ? '' : ' disabled'; ?>>
<?php esc_html_e( 'Next: Run Analysis', 'robotstxt-mlp2-mlp5' ); ?>
</button>
<?php if ( ! $can_proceed ) : ?>
<span style="margin-left:.75em;color:#d63638;"><?php esc_html_e( 'Resolve the issues above before continuing.', 'robotstxt-mlp2-mlp5' ); ?></span>
<?php endif; ?>
</p>
</form>
<?php
}
}