-
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.
Merge pull request #15 from deliciousbrains/bporcelli-scaffold-command
Add support for generating new migration classes with wp migrate <name> --scaffold
- Loading branch information
Showing
5 changed files
with
139 additions
and
9 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
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,19 @@ | ||
<?php | ||
|
||
use DeliciousBrains\WPMigrations\Database\AbstractMigration; | ||
|
||
class {{ class }} extends AbstractMigration { | ||
|
||
/** | ||
* Run the migration. | ||
*/ | ||
public function run() { | ||
} | ||
|
||
/** | ||
* Optional: Roll back the migration. | ||
*/ | ||
public function rollback() { | ||
} | ||
|
||
} |