Skip to content

Commit

Permalink
Merge pull request #456 from cakephp/4.x-bake-exclude
Browse files Browse the repository at this point in the history
[4.x] exclude bake commands
  • Loading branch information
dereuromark authored Apr 24, 2020
2 parents a3da821 + 88671b5 commit f986bc6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"require-dev": {
"phpunit/phpunit": "~8.5.0",
"cakephp/cakephp": "^4.0.5",
"cakephp/bake": "^2.0.9",
"cakephp/bake": "^2.1.0",
"cakephp/cakephp-codesniffer": "~4.1.0"
},
"autoload": {
Expand Down
43 changes: 43 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
namespace Migrations;

use Cake\Console\CommandCollection;
use Cake\Core\BasePlugin;

/**
Expand All @@ -33,4 +34,46 @@ class Plugin extends BasePlugin
* @var bool
*/
protected $routesEnabled = false;

protected $migrationCommandsList = [
Command\MigrationsCommand::class,
Command\MigrationsCreateCommand::class,
Command\MigrationsDumpCommand::class,
Command\MigrationsMarkMigratedCommand::class,
Command\MigrationsMigrateCommand::class,
Command\MigrationsCacheBuildCommand::class,
Command\MigrationsCacheClearCommand::class,
Command\MigrationsRollbackCommand::class,
Command\MigrationsSeedCommand::class,
Command\MigrationsStatusCommand::class,
];

/**
* Add migrations commands.
*
* @param \Cake\Console\CommandCollection $collection The command collection to update
* @return \Cake\Console\CommandCollection
*/
public function console(CommandCollection $collection): CommandCollection
{
if (class_exists('Bake\Command\SimpleBakeCommand')) {
$commands = $collection->discoverPlugin($this->getName());

return $collection->addMany($commands);
}
$commands = [];
foreach ($this->migrationCommandsList as $class) {
$name = $class::defaultName();
// If the short name has been used, use the full name.
// This allows app commands to have name preference.
// and app commands to overwrite migration commands.
if (!$collection->has($name)) {
$commands[$name] = $class;
}
// full name
$commands['migrations.' . $name] = $class;
}

return $collection->addMany($commands);
}
}
6 changes: 3 additions & 3 deletions templates/bake/config/snapshot.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class {{ name }} extends AbstractMigration
*/
public function up()
{
{% element 'Migrations.create-tables' {
{{~ element('Migrations.create-tables', {
tables: tables,
autoId: autoId,
useSchema: false
} %}
}
})
}} }
/**
* Down Method.
Expand Down
11 changes: 6 additions & 5 deletions templates/bake/element/create-tables.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@
)
{% endfor %}
->create();
{% endfor %}
{% endfor -%}
{% if createData.constraints %}
{% for table, tableConstraints in createData.constraints %}
{% element 'Migrations.add-foreign-keys' {
{{- element('Migrations.add-foreign-keys', {
constraints: tableConstraints,
table: table
} %}
{% endfor %}
{% endif %}
})
-}}
{% endfor -%}
{% endif -%}
2 changes: 1 addition & 1 deletion tests/TestCase/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function setUp(): void
parent::setUp();

Router::reload();
$this->loadPlugins(['WyriHaximus/TwigView']);
$this->loadPlugins(['Cake/TwigView']);
}

public function tearDown(): void
Expand Down
Empty file.

0 comments on commit f986bc6

Please sign in to comment.