| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Cli\Commands; |
| 5 |
|
| 6 |
use Jet_Form_Builder\Db_Queries\Execution_Builder; |
| 7 |
use Jet_Form_Builder\Migrations\Migration_Exception; |
| 8 |
use Jet_Form_Builder\Migrations\Migration_Incomplete_Exception; |
| 9 |
use Jet_Form_Builder\Migrations\Migrator; |
| 10 |
use Jet_Form_Builder\Migrations\Profilers\Cli_Migration_Profiler; |
| 11 |
|
| 12 |
// If this file is called directly, abort. |
| 13 |
if ( ! defined( 'WPINC' ) ) { |
| 14 |
die; |
| 15 |
} |
| 16 |
|
| 17 |
class Upgrade_Database implements Base_Command_It { |
| 18 |
|
| 19 |
public function rep_item_id() { |
| 20 |
return 'db-upgrade'; |
| 21 |
} |
| 22 |
|
| 23 |
public function condition(): bool { |
| 24 |
return true; |
| 25 |
} |
| 26 |
|
| 27 |
public function do_command( $args, $assoc_args ) { |
| 28 |
try { |
| 29 |
Execution_Builder::instance()->transaction_start(); |
| 30 |
Migrator::instance()->install( new Cli_Migration_Profiler() ); |
| 31 |
Execution_Builder::instance()->transaction_commit(); |
| 32 |
|
| 33 |
\WP_CLI::line(); |
| 34 |
\WP_CLI::success( 'Migrated successfully' ); |
| 35 |
|
| 36 |
} catch ( Migration_Incomplete_Exception $exception ) { |
| 37 |
// Not a data-loss failure: a time-boxed migration (e.g. the SSR registry |
| 38 |
// import) already committed its own partial progress and a resume cursor |
| 39 |
// before throwing this — see its own docblock. There is nothing left to roll |
| 40 |
// back here; running the command again resumes from that cursor. It is, |
| 41 |
// however, not "done" either — `WP_CLI::success()` here would exit 0, which |
| 42 |
// automation polling this command's exit code would read as "migration |
| 43 |
// complete" and never retry, silently leaving the site on partially-migrated |
| 44 |
// data (review finding, issues-tracker #20361 follow-up). `WP_CLI::error()` |
| 45 |
// gives it the same non-zero exit code as a genuine failure so such automation |
| 46 |
// reliably re-invokes the command instead. |
| 47 |
\WP_CLI::line(); |
| 48 |
\WP_CLI::error( 'Migration is still in progress. Run this command again to continue.' ); |
| 49 |
|
| 50 |
} catch ( Migration_Exception $exception ) { |
| 51 |
Execution_Builder::instance()->transaction_rollback(); |
| 52 |
\WP_CLI::error( $exception->getMessage() ); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|