|
22 | 22 |
|
23 | 23 | use Doctrine\DBAL\Connection;
|
24 | 24 | use Mouf\ClassProxy;
|
| 25 | +use Mouf\Installer\PackageInstallerInterface; |
25 | 26 | use Mouf\InstanceProxy;
|
26 | 27 | use Mouf\MoufManager;
|
27 | 28 | use Mouf\UniqueIdService;
|
|
33 | 34 | *
|
34 | 35 | * @author David Negrier <[email protected]>
|
35 | 36 | */
|
36 |
| -class DatabasePatchInstaller |
| 37 | +class DatabasePatchInstaller implements PackageInstallerInterface |
37 | 38 | {
|
| 39 | + /** |
| 40 | + * (non-PHPdoc) |
| 41 | + * @see \Mouf\Installer\PackageInstallerInterface::install() |
| 42 | + * @param MoufManager $moufManager |
| 43 | + * @throws \Mouf\MoufException |
| 44 | + */ |
| 45 | + public static function install(MoufManager $moufManager) { |
| 46 | + // Let's create the table. |
| 47 | + $dbConnection = $moufManager->get('dbalConnection'); |
| 48 | + /* @var $dbConnection Connection */ |
| 49 | + |
| 50 | + $existingPatches = $moufManager->findInstances("Mouf\\Database\\Patcher\\DatabasePatch"); |
| 51 | + $dbConnectionDescriptor = $moufManager->getInstanceDescriptor('dbalConnection'); |
| 52 | + foreach($existingPatches as $existingPatche){ |
| 53 | + $patchIntance = $moufManager->getInstanceDescriptor($existingPatche); |
| 54 | + $patchIntance->getProperty('dbalConnection')->setValue($dbConnectionDescriptor); |
| 55 | + } |
| 56 | + |
| 57 | + // Finally, let's change the dbalConnection configuration to add an ignore rule on the "patches" table. |
| 58 | + $configArgument = $dbConnectionDescriptor->getConstructorArgumentProperty('config'); |
| 59 | + $config = $configArgument->getValue(); |
| 60 | + if ($config === null) { |
| 61 | + $config = $moufManager->createInstance("Doctrine\\DBAL\\Configuration"); |
| 62 | + $config->setName('doctrineDbalConfiguration'); |
| 63 | + |
| 64 | + $configArgument->setValue($config); |
| 65 | + } |
| 66 | + |
| 67 | + if ($config->getProperty('filterSchemaAssetsExpression')->getValue() === null) { |
| 68 | + $config->getProperty('filterSchemaAssetsExpression')->setValue('/^(?!patches$).*/'); |
| 69 | + } |
| 70 | + |
| 71 | + $moufManager->rewriteMouf(); |
| 72 | + //Create patches table |
| 73 | + self::createPatchTable($dbConnection); |
| 74 | + } |
| 75 | + |
38 | 76 | /**
|
39 | 77 | * Registers a database patch in the patch system.
|
40 | 78 | * Note: the patch will not be executed, only registered in "Awaiting" state.
|
|
0 commit comments