PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, March 13, 2022

[FIXED] How can i run all migrations for all plugins in cakephp 3?

 March 13, 2022     cakephp, cakephp-3.0     No comments   

Issue

I know I can run bin/cake Migrations migrate --plugin MyPlugin

but I use 50+ plugins in my project and id liked to run all migrations in all plugins with one command is this possible?


Solution

As far as I am aware there is no straight forward command for running migrations for all plugins. However, you could put together a simple Shell script to do this.

You can retrieve a list of all the loaded plugins for an app using:-

$plugins = Plugin::loaded();

You can then run the migrations for each plugin using dispatchShell which allows you to run a command from another Shell:-

$this->dispatchShell(
    'migrations',
    'migrate',
    '-p',
    $plugin
);

Each argument for the migration is passed as an argument to dispatchShell.

So, putting all that together into a Shell script:-

<?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
            );
        }
    }
}

This script would be called like $ bin/cake install plugins.



Answered By - drmonkeyninja
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing