jur*_*ieb 5 cakephp cakephp-3.0
我知道我可以运行bin / cake Migrations migration --plugin MyPlugin
但是我在项目中使用了50多个插件,并且id喜欢用一个命令在所有插件中运行所有迁移,这可能吗?
据我所知,没有直接的命令来运行所有插件的迁移。不过,您可以编写一个简单的 Shell 脚本来完成此操作。
您可以使用以下方法检索应用程序所有已加载插件的列表:-
$plugins = Plugin::loaded();
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用每个插件运行迁移dispatchShell,这允许您从另一个 Shell 运行命令:-
$this->dispatchShell(
'migrations',
'migrate',
'-p',
$plugin
);
Run Code Online (Sandbox Code Playgroud)
迁移的每个参数都作为参数传递给dispatchShell.
因此,将所有这些组合到一个 Shell 脚本中:-
<?php
// src/Shell/InstallShell.php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Core\Plugin;
class InstallShell extends Shell
{
public function plugins()
{
$plugins = Plugin::loaded();
foreach ($plugins as $plugin) {
$this->dispatchShell(
'migrations',
'migrate',
'-p',
$plugin
);
}
}
}
Run Code Online (Sandbox Code Playgroud)
该脚本将被称为类似$ bin/cake install plugins.
| 归档时间: |
|
| 查看次数: |
900 次 |
| 最近记录: |