$row['id'], 'state' => AIEO_Site_Migration::ABSENT === $row['state'] ? 'not present' : $row['state'], 'verified' => AIEO_Site_Migration::COPIED === $row['state'] || AIEO_Site_Migration::SWITCHED === $row['state'] ? ( $row['verified'] ? 'yes' : 'no' ) : '', 'copied' => $row['copied_at'], 'switched' => $row['switched_at'], 'what' => $row['title'], ); } if ( 'json' === (string) ( $assoc['format'] ?? '' ) ) { WP_CLI::line( (string) wp_json_encode( $rows, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); return; } WP_CLI\Utils\format_items( 'table', $rows, array( 'source', 'state', 'verified', 'copied', 'switched', 'what' ) ); } public function audit( array $args, array $assoc ) { $result = AIEO_Site_Migration_Audit::run( (string) ( $assoc['out'] ?? '' ) ); if ( is_wp_error( $result ) ) { WP_CLI::error( $result->get_error_message() ); } foreach ( $result['failed'] as $subject => $error ) { WP_CLI::warning( sprintf( '%s could not be read: %s', $subject, $error ) ); } WP_CLI::success( sprintf( '%d file(s) written to %s. Nothing on the shop was changed.', count( $result['files'] ), (string) $assoc['out'] ) ); } public function source( $id, array $args, array $assoc ) { $source = AIEO_Site_Migration::source( $id ); if ( ! $source ) { WP_CLI::error( sprintf( '%s is not a source.', $id ) ); } $steps = array_values( array_filter( self::STEPS, static fn ( $step ) => ! empty( $assoc[ $step ] ) ) ); if ( 1 !== count( $steps ) ) { WP_CLI::line( $source->title() ); WP_CLI::line( 'One step at a time: --plan, --copy, --verify, --switch or --undo.' ); foreach ( $source->options() as $name => $what ) { WP_CLI::line( sprintf( ' --%s %s', $name, $what ) ); } WP_CLI::halt( $steps ? 1 : 0 ); } $opts = array_diff_key( $assoc, array_flip( self::STEPS ), array( 'format' => 1 ) ); $report = AIEO_Site_Migration::run( $id, $steps[0], $opts ); if ( 'json' === (string) ( $assoc['format'] ?? '' ) ) { WP_CLI::line( (string) wp_json_encode( array( 'source' => $id, 'step' => $steps[0], 'state' => AIEO_Site_Migration::state( $id ) ) + $report->to_array(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); WP_CLI::halt( $report->ok() ? 0 : 1 ); } foreach ( $report->lines as $line ) { WP_CLI::line( $line ); } foreach ( $report->counts as $label => $n ) { WP_CLI::line( sprintf( '%s: %s', $label, is_scalar( $n ) ? (string) $n : (string) wp_json_encode( $n ) ) ); } foreach ( $report->warnings as $warning ) { WP_CLI::warning( $warning ); } foreach ( $report->deactivate as $file ) { WP_CLI::line( 'DEACTIVATE ' . $file ); } $state = AIEO_Site_Migration::state( $id ); if ( ! $report->ok() ) { foreach ( array_slice( $report->errors, 0, -1 ) as $error ) { WP_CLI::warning( $error ); } WP_CLI::error( (string) end( $report->errors ) ); } WP_CLI::success( sprintf( '%s %s: %s. The source is %s.', $id, $steps[0], 'plan' === $steps[0] ? 'nothing changed' : 'passed', AIEO_Site_Migration::ABSENT === $state ? 'not present' : $state ) ); } private static function neutral( array $assoc ) { return array_values( array_filter( array_map( 'sanitize_key', explode( ',', (string) ( $assoc['neutral-roles'] ?? '' ) ) ), 'strlen' ) ); } public function golden_capture( array $args, array $assoc ) { $sets = array_values( array_filter( array_map( 'trim', explode( ',', (string) ( $assoc['set'] ?? '' ) ) ) ) ); $dir = (string) ( $assoc['out'] ?? '' ); if ( ! $sets || array_diff( $sets, AIEO_Site_Migration_Golden::SETS ) || '' === $dir ) { WP_CLI::error( sprintf( 'Name the set (--set=%s) and the folder (--out=