scheduler() ); $result = array( 'success' => false, 'message' => __( 'Unknown action.', 'marginbeacon' ), ); if ( 'refresh_summary' === $action ) { $service->summarize(); $result = array( 'success' => true, 'message' => __( 'Migration summary refreshed.', 'marginbeacon' ), ); } elseif ( 'switch_only' === $action ) { $result = $service->switch_without_copy(); } elseif ( 'copy_and_switch' === $action ) { $result = $service->start_copy_and_switch(); } elseif ( 'switch_back' === $action ) { $result = $service->switch_back_to_marginbeacon(); } add_settings_error( 'aksmb_cogs_migration', 'migration', isset( $result['message'] ) ? (string) $result['message'] : '', ! empty( $result['success'] ) ? 'updated' : 'error' ); set_transient( 'aksmb_cogs_migration_errors_' . get_current_user_id(), get_settings_errors( 'aksmb_cogs_migration' ), 30 ); wp_safe_redirect( Tabs::url( Tabs::COST_SETUP, array( 'view' => 'migration' ) ) ); exit; } /** * Whether the migration view should render. * * @return bool */ public static function is_migration_view() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $view = isset( $_GET['view'] ) ? sanitize_key( wp_unslash( $_GET['view'] ) ) : ''; return 'migration' === $view; } /** * @return void */ public function render() { if ( ! Capabilities::current_user_can_manage() ) { wp_die( esc_html__( 'You do not have permission to access MarginBeacon.', 'marginbeacon' ) ); } $stored = get_transient( 'aksmb_cogs_migration_errors_' . get_current_user_id() ); if ( is_array( $stored ) ) { foreach ( $stored as $error ) { add_settings_error( $error['setting'], $error['code'], $error['message'], $error['type'] ); } delete_transient( 'aksmb_cogs_migration_errors_' . get_current_user_id() ); } settings_errors( 'aksmb_cogs_migration' ); $canonical = new CanonicalCostSource(); $canonical->ensure_bootstrapped( false ); $env = ( new CogsEnvironment() )->detect(); $service = new CogsMigrationService(); $state = $canonical->migration_state(); $summary = isset( $state['last_summary'] ) && is_array( $state['last_summary'] ) ? $state['last_summary'] : $service->summarize(); $last = isset( $state['last_result'] ) && is_array( $state['last_result'] ) ? $state['last_result'] : null; $job = isset( $state['job'] ) && is_array( $state['job'] ) ? $state['job'] : array(); ?>