1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) 2013-2015 David Negrier |
4
|
|
|
* |
5
|
|
|
* See the file LICENSE.txt for copying permission. |
6
|
|
|
*/ |
7
|
|
|
namespace Mouf\Utils\Patcher; |
8
|
|
|
|
9
|
|
|
use Mouf\Actions\InstallUtils; |
10
|
|
|
use Mouf\Console\ConsoleUtils; |
11
|
|
|
use Mouf\Database\Patcher\PatchConnection; |
12
|
|
|
use Mouf\Installer\PackageInstallerInterface; |
13
|
|
|
use Mouf\MoufManager; |
14
|
|
|
use Mouf\Utils\Patcher\Commands\ApplyAllPatchesCommand; |
15
|
|
|
use Mouf\Utils\Patcher\Commands\ApplyPatchCommand; |
16
|
|
|
use Mouf\Utils\Patcher\Commands\ListPatchesCommand; |
17
|
|
|
use Mouf\Utils\Patcher\Commands\RevertPatchCommand; |
18
|
|
|
use Mouf\Utils\Patcher\Commands\SkipPatchCommand; |
19
|
|
|
|
20
|
|
|
class PatchInstaller2 implements PackageInstallerInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* (non-PHPdoc) |
24
|
|
|
* @see \Mouf\Installer\PackageInstallerInterface::install() |
25
|
|
|
* @param MoufManager $moufManager |
26
|
|
|
* @throws \Mouf\MoufException |
27
|
|
|
*/ |
28
|
|
|
public static function install(MoufManager $moufManager) |
29
|
|
|
{ |
30
|
|
|
// Let's create the instance. |
31
|
|
|
$patchDefaultType = InstallUtils::getOrCreateInstance('patch.default_type', PatchType::class, $moufManager); |
32
|
|
|
$patchDefaultType->getConstructorArgumentProperty('name')->setValue(''); |
33
|
|
|
$patchDefaultType->getConstructorArgumentProperty('description')->setValue('Patches that should be always applied should have this type. Typically, use this type for DDL changes or reference data insertion.'); |
34
|
|
|
|
35
|
|
|
$patchTestDataType = InstallUtils::getOrCreateInstance('patch.testdata_type', PatchType::class, $moufManager); |
36
|
|
|
$patchTestDataType->getConstructorArgumentProperty('name')->setValue('test_data'); |
37
|
|
|
$patchTestDataType->getConstructorArgumentProperty('description')->setValue('Use this type to mark patches that contain test data that should only be used in staging environment.'); |
38
|
|
|
|
39
|
|
|
$patchService = InstallUtils::getOrCreateInstance('patchService', PatchService::class, $moufManager); |
40
|
|
|
|
41
|
|
|
if (empty($patchService->getConstructorArgumentProperty('types')->getValue())) { |
42
|
|
|
$patchService->getConstructorArgumentProperty('types')->setValue([ $patchDefaultType, $patchTestDataType ]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$consoleUtils = new ConsoleUtils($moufManager); |
46
|
|
|
|
47
|
|
|
$listPatchesCommand = $moufManager->createInstance(ListPatchesCommand::class); |
48
|
|
|
$listPatchesCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
49
|
|
|
$consoleUtils->registerCommand($listPatchesCommand); |
50
|
|
|
|
51
|
|
|
$applyAllPatchesCommand = $moufManager->createInstance(ApplyAllPatchesCommand::class); |
52
|
|
|
$applyAllPatchesCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
53
|
|
|
$consoleUtils->registerCommand($applyAllPatchesCommand); |
54
|
|
|
|
55
|
|
|
$applyPatchCommand = $moufManager->createInstance(ApplyPatchCommand::class); |
56
|
|
|
$applyPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
57
|
|
|
$consoleUtils->registerCommand($applyPatchCommand); |
58
|
|
|
|
59
|
|
|
$skipPatchCommand = $moufManager->createInstance(SkipPatchCommand::class); |
60
|
|
|
$skipPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
61
|
|
|
$consoleUtils->registerCommand($skipPatchCommand); |
62
|
|
|
|
63
|
|
|
$revertPatchCommand = $moufManager->createInstance(RevertPatchCommand::class); |
64
|
|
|
$revertPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService); |
65
|
|
|
$consoleUtils->registerCommand($revertPatchCommand); |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
// Let's rewrite the MoufComponents.php file to save the component |
69
|
|
|
$moufManager->rewriteMouf(); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|