Skip to content

Commit 5395a47

Browse files
committed
Changing installer so that patches table is automatically in the DBAL ignore list
1 parent ebf199e commit 5395a47

File tree

4 files changed

+52
-49
lines changed

4 files changed

+52
-49
lines changed

composer.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
}
2424
},
2525
"extra": {
26-
"mouf": {
27-
"install": [
28-
{
29-
"type": "file",
30-
"file": "src/install.php",
31-
"description": "Create the 'patches' table in your database to track patches applied."
32-
}
33-
],
34-
"require-admin": [
35-
"src/DBPatchAdmin.php"
36-
],
37-
"logo": "icon.png"
26+
"mouf": {
27+
"install": [
28+
{
29+
"type": "class",
30+
"class": "Mouf\\Database\\Patcher\\DatabasePatchInstaller",
31+
"description": "Create the 'patches' table in your database to track patches applied."
32+
}
33+
],
34+
"require-admin": [
35+
"src/DBPatchAdmin.php"
36+
],
37+
"logo": "icon.png"
3838
}
3939
}
4040
}

src/Mouf/Database/Patcher/Controllers/DatabasePatchController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function defaultAction($name, $patchInstanceName = null, $selfedit = 'fal
100100
}
101101
$this->status = 'skipped';
102102

103-
$this->content->addFile(dirname(__FILE__).'/../../../../views/editPatch.php', $this);
103+
$this->content->addFile(__DIR__'/../../../../views/editPatch.php', $this);
104104
$this->template->toHtml();
105105
}
106106

src/Mouf/Database/Patcher/DatabasePatchInstaller.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use Doctrine\DBAL\Connection;
2424
use Mouf\ClassProxy;
25+
use Mouf\Installer\PackageInstallerInterface;
2526
use Mouf\InstanceProxy;
2627
use Mouf\MoufManager;
2728
use Mouf\UniqueIdService;
@@ -33,8 +34,45 @@
3334
*
3435
* @author David Negrier <[email protected]>
3536
*/
36-
class DatabasePatchInstaller
37+
class DatabasePatchInstaller implements PackageInstallerInterface
3738
{
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+
3876
/**
3977
* Registers a database patch in the patch system.
4078
* Note: the patch will not be executed, only registered in "Awaiting" state.

src/install.php

-35
This file was deleted.

0 commit comments

Comments
 (0)