Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

[Kaliop Migrations Bundle] exec commands

Bonjour.

I’ve developed a command that I want to launch via Kaliop Migrations Bundle.

So I generated a PHP migration file

class FormFix implements MigrationInterface
{
    public static function execute(ContainerInterface $container)
    {
        $cmdList = [
            'my:fix --text',
            'my:fix --address',
        ];

        $kernelRootDir = $container->getParameter('kernel.root_dir'); 
        foreach ($cmdList as $cmd) {
            $processString = sprintf('php -d memory_limit=-1 %s/../bin/console %s ',
                $kernelRootDir,
                $cmd
            );
            $process = new Symfony\Component\Process\Process($processString);
            $process->setWorkingDirectory(getcwd() . "../");
            $process->start();

            if (!$process->isSuccessful()) {
                throw new \Symfony\Component\Process\Exception\ProcessFailedException($process);
            }
        }
    }
}

Exec :

php bin/console k:m:u -n
# OR
ez sfrun "k:m:u -n"

But, when executing the migration, I’m getting this error:

Migration failed! Reason: Error in execution of step 1: The command “php -d memory_limit=-1 /var/www/html/project/ezplatform/app/…/bin/console my:fix --text” failed.

However, if I execute the command directly, it works.

php -d memory_limit=-1 /var/www/html/project/ezplatform/app/../bin/console novaformbuilder:migrate --export

Is this the right technique for executing commands from a migration?

Merci :slight_smile:

$command = $container->get( MyFixCommand::class );
$command->run(
    new ArrayInput(
        array(
            '--text' =>true,
        )
    ),
    new ConsoleOutput()
);