value === $status; $failed = MigrationStatus::Failed->value === $status; $completed = MigrationStatus::Completed->value === $status; if ( $completed || $recovered ) { $state = $recovered ? ( $is_pull ? self::STATE_DATABASE_RESTORED : self::STATE_REMOTE_RESTORED ) : self::STATE_CLEAN; $rolled = $recovered; } elseif ( $failed ) { $state = self::STATE_PARTIAL; $rolled = false; } else { // Pending, running, paused, cancelling. Nothing to report yet. $state = self::STATE_CLEAN; $rolled = false; } return [ 'state' => $state, 'rolled_back' => $rolled, // Always false. Nothing in this plugin restores files. 'files_restored' => false, 'snapshot_available' => $snapshot_written, // The Backups page lists every restore point, so a written one is reachable. 'snapshot_reachable' => $snapshot_written, 'destination' => $is_pull ? 'this site' : 'the connected site', 'headline' => self::headline( $state, $is_pull ), 'detail' => self::detail( $state, $is_pull, $snapshot_written ), ]; } private static function headline( string $state, bool $is_pull ): string { switch ( $state ) { case self::STATE_DATABASE_RESTORED: return __( 'Migration failed. Your previous database was restored.', 'shiftora' ); case self::STATE_REMOTE_RESTORED: return __( 'Migration failed. The connected site was restored.', 'shiftora' ); case self::STATE_PARTIAL: return __( 'Migration failed. Review the details before retrying.', 'shiftora' ); case self::STATE_CLEAN: default: return __( 'The migration completed.', 'shiftora' ); } } private static function detail( string $state, bool $is_pull, bool $snapshot_written ): string { switch ( $state ) { case self::STATE_DATABASE_RESTORED: /* * A restore point is SQL. Uploads already copied stay copied, so the * message must not say the site was fully put back. */ return __( 'The database is the state it was before the run. Files that had already been copied were not restored.', 'shiftora' ); case self::STATE_REMOTE_RESTORED: return __( 'Nothing on this site changed as a result of the run.', 'shiftora' ); case self::STATE_PARTIAL: return $snapshot_written && $is_pull ? __( 'Your database may be partway through the migration. A restore point from before it started is available.', 'shiftora' ) : __( 'The destination may be partway through the migration.', 'shiftora' ); case self::STATE_CLEAN: default: return ''; } } }