Skip to content

Instantly share code, notes, and snippets.

@mbabker
Last active November 10, 2020 07:59
Show Gist options
  • Save mbabker/ef79d1cbd9a3b238eba1c7306be72562 to your computer and use it in GitHub Desktop.
Save mbabker/ef79d1cbd9a3b238eba1c7306be72562 to your computer and use it in GitHub Desktop.
Compiler pass which removes migration paths added by SyliusCoreBundle and SyliusAdminApiBundle (or other third party packages), useful if you are manually managing all migrations within your Sylius application
<?php declare(strict_types=1);
namespace App\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
final class RemoveSyliusMigrationsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if ($container->hasDefinition('doctrine.migrations.configuration')) {
$definition = $container->getDefinition('doctrine.migrations.configuration');
$calls = $definition->getMethodCalls();
$sanitizedCalls = [];
/*
* Key 0 is the method name, key 1 is the arguments, and if defined key 2 is a flag indicating whether a clone should be returned
* Inside the arguments array for `addMigrationsDirectory` calls, key 0 is the namespace and key 1 is the path
*/
foreach ($calls as $call) {
if ($call[0] !== 'addMigrationsDirectory') {
$sanitizedCalls[] = $call;
continue;
}
if ($call[1][0] === 'DoctrineMigrations') {
$sanitizedCalls[] = $call;
}
}
$definition->setMethodCalls($sanitizedCalls);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment