-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Scaffold functionality to wp scaffold sub command
- Loading branch information
Iain
committed
May 4, 2023
1 parent
bbd40df
commit 33cf17e
Showing
4 changed files
with
56 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace DeliciousBrains\WPMigrations\CLI; | ||
|
||
class Scaffold extends \WP_CLI_Command { | ||
|
||
/** | ||
* Data migration command | ||
* | ||
* ## OPTIONS | ||
* | ||
* [<migration>] | ||
* : Class name for the migration | ||
* | ||
* [--rollback] | ||
* : If we are reverting a migration | ||
* | ||
* [--setup] | ||
* : Set up the migrations table | ||
* | ||
* [--scaffold] | ||
* : Scaffold a new migration class using the migration stub | ||
* | ||
* @param array $args | ||
* @param array $assoc_args | ||
* | ||
* @throws \WP_CLI\ExitException | ||
*/ | ||
public function __invoke( $args, $assoc_args ) { | ||
$migrator = \DeliciousBrains\WPMigrations\Database\Migrator::instance(); | ||
|
||
$migration = null; | ||
if ( ! empty( $args[0] ) ) { | ||
$migration = $args[0]; | ||
} | ||
|
||
|
||
if ( ! $migration ) { | ||
return \WP_CLI::error( 'Migration name must be specified when using --scaffold' ); | ||
} | ||
|
||
$filename = $migrator->scaffold( $migration ); | ||
|
||
if ( is_wp_error( $filename ) ) { | ||
return \WP_ClI::error( $filename->get_error_message() ); | ||
} | ||
|
||
return \WP_CLI::success( "Created {$filename}" ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters