v1.0.0
This commit is contained in:
parent
8caa140991
commit
5cdf7f48e5
29 changed files with 6526 additions and 0 deletions
113
includes/class-robotstxt-mlp2-mlp5-step-site-relations.php
Normal file
113
includes/class-robotstxt-mlp2-mlp5-step-site-relations.php
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/**
|
||||
* Wizard Step 3 — Site Relations Migration.
|
||||
*
|
||||
* Reads all MLP2 backup site relations and writes them to MLP5,
|
||||
* skipping orphaned or already-migrated pairs and logging all results.
|
||||
*
|
||||
* @package Robotstxt_Mlp2_Mlp5
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Robotstxt_Mlp2_Mlp5_Step_Site_Relations
|
||||
*/
|
||||
class Robotstxt_Mlp2_Mlp5_Step_Site_Relations {
|
||||
|
||||
/**
|
||||
* Run the site relations migration.
|
||||
*
|
||||
* @return array {
|
||||
* @type int $migrated Number of relations successfully written.
|
||||
* @type int $skipped Number of relations skipped.
|
||||
* @type int $errors Number of relations that failed.
|
||||
* }
|
||||
*/
|
||||
public static function run(): array {
|
||||
$rows = Robotstxt_Mlp2_Mlp5_Reader_Site_Relations::get_all();
|
||||
$orphaned_site_ids = array_map( 'intval', (array) ( Robotstxt_Mlp2_Mlp5_Wizard_State::get_step_data( 2 )['orphaned_site_ids'] ?? array() ) );
|
||||
|
||||
$migrated = 0;
|
||||
$skipped = 0;
|
||||
$errors = 0;
|
||||
|
||||
foreach ( $rows as $row ) {
|
||||
$site_1 = $row['site_1'];
|
||||
$site_2 = $row['site_2'];
|
||||
|
||||
// Skip orphaned sites.
|
||||
if ( in_array( $site_1, $orphaned_site_ids, true ) || in_array( $site_2, $orphaned_site_ids, true ) ) {
|
||||
Robotstxt_Mlp2_Mlp5_Logger::log( 'skipped', 'site_relation', $site_1, $site_2, __( 'One or both sites no longer exist in the network.', 'robotstxt-mlp2-mlp5' ) );
|
||||
++$skipped;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip if already exists in MLP5.
|
||||
if ( Robotstxt_Mlp2_Mlp5_Writer_Site_Relations::relation_exists( $site_1, $site_2 ) ) {
|
||||
Robotstxt_Mlp2_Mlp5_Logger::log( 'skipped', 'site_relation', $site_1, $site_2, __( 'Relation already exists in MLP5 (idempotent skip).', 'robotstxt-mlp2-mlp5' ) );
|
||||
++$skipped;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Write.
|
||||
if ( Robotstxt_Mlp2_Mlp5_Writer_Site_Relations::write_relation( $site_1, $site_2 ) ) {
|
||||
Robotstxt_Mlp2_Mlp5_Logger::log( 'success', 'site_relation', $site_1, $site_2, __( 'Site relation migrated successfully.', 'robotstxt-mlp2-mlp5' ) );
|
||||
++$migrated;
|
||||
} else {
|
||||
Robotstxt_Mlp2_Mlp5_Logger::log( 'error', 'site_relation', $site_1, $site_2, __( 'Failed to write site relation to MLP5.', 'robotstxt-mlp2-mlp5' ) );
|
||||
++$errors;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'migrated' => $migrated,
|
||||
'skipped' => $skipped,
|
||||
'errors' => $errors,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Step 3 UI.
|
||||
*/
|
||||
public static function render(): void {
|
||||
$data = Robotstxt_Mlp2_Mlp5_Wizard_State::get_step_data( 3 );
|
||||
$ran = ! empty( $data );
|
||||
?>
|
||||
<h2><?php esc_html_e( 'Step 3 — Site Relations', 'robotstxt-mlp2-mlp5' ); ?></h2>
|
||||
<p><?php esc_html_e( 'This step migrates site connections and language assignments from MLP2 to MLP5. It usually completes in seconds.', 'robotstxt-mlp2-mlp5' ); ?></p>
|
||||
|
||||
<?php if ( $ran ) : ?>
|
||||
<table class="widefat striped" style="border:0;max-width:400px;margin-bottom:1.5em;">
|
||||
<tbody>
|
||||
<tr><td><?php esc_html_e( 'Migrated', 'robotstxt-mlp2-mlp5' ); ?></td><td style="color:#46b450;font-weight:600;"><?php echo esc_html( number_format_i18n( (int) ( $data['migrated'] ?? 0 ) ) ); ?></td></tr>
|
||||
<tr><td><?php esc_html_e( 'Skipped', 'robotstxt-mlp2-mlp5' ); ?></td><td><?php echo esc_html( number_format_i18n( (int) ( $data['skipped'] ?? 0 ) ) ); ?></td></tr>
|
||||
<tr><td><?php esc_html_e( 'Errors', 'robotstxt-mlp2-mlp5' ); ?></td><td style="<?php echo (int) ( $data['errors'] ?? 0 ) > 0 ? 'color:#d63638;font-weight:600;' : ''; ?>"><?php echo esc_html( number_format_i18n( (int) ( $data['errors'] ?? 0 ) ) ); ?></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
|
||||
<p>
|
||||
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" style="display:inline;">
|
||||
<?php wp_nonce_field( 'mlp_migrator_site_relations', 'mlp_migrator_nonce' ); ?>
|
||||
<input type="hidden" name="action" value="mlp_migrator_step" />
|
||||
<input type="hidden" name="mlp_migrator_step_action" value="3_run" />
|
||||
<button type="submit" class="button button-<?php echo $ran ? 'secondary' : 'primary'; ?>">
|
||||
<?php echo $ran ? esc_html__( 'Re-run Site Relations', 'robotstxt-mlp2-mlp5' ) : esc_html__( 'Start Site Relations Migration', 'robotstxt-mlp2-mlp5' ); ?>
|
||||
</button>
|
||||
</form>
|
||||
<?php if ( $ran ) : ?>
|
||||
|
||||
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" style="display:inline;">
|
||||
<?php wp_nonce_field( 'mlp_migrator_step_3', 'mlp_migrator_nonce' ); ?>
|
||||
<input type="hidden" name="action" value="mlp_migrator_step" />
|
||||
<input type="hidden" name="mlp_migrator_step_action" value="3" />
|
||||
<button type="submit" class="button button-primary"><?php esc_html_e( 'Next: Content Relations', 'robotstxt-mlp2-mlp5' ); ?></button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue