Completed
Pull Request — 2.1 (#7)
by David
02:07
created

PatchInstaller3::install()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 46
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 46
rs 8.9411
cc 2
eloc 30
nc 2
nop 1
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\ResetPatchesCommand;
18
use Mouf\Utils\Patcher\Commands\RevertPatchCommand;
19
use Mouf\Utils\Patcher\Commands\SkipPatchCommand;
20
21
class PatchInstaller3 implements PackageInstallerInterface
22
{
23
    /**
24
     * (non-PHPdoc)
25
     * @see \Mouf\Installer\PackageInstallerInterface::install()
26
     * @param  MoufManager         $moufManager
27
     * @throws \Mouf\MoufException
28
     */
29
    public static function install(MoufManager $moufManager)
30
    {
31
        // Let's create the instance.
32
        $patchDefaultType = InstallUtils::getOrCreateInstance('patch.default_type', PatchType::class, $moufManager);
33
        $patchDefaultType->getConstructorArgumentProperty('name')->setValue('');
34
        $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.');
35
36
        $patchTestDataType = InstallUtils::getOrCreateInstance('patch.testdata_type', PatchType::class, $moufManager);
37
        $patchTestDataType->getConstructorArgumentProperty('name')->setValue('test_data');
38
        $patchTestDataType->getConstructorArgumentProperty('description')->setValue('Use this type to mark patches that contain test data that should only be used in staging environment.');
39
40
        $patchService = InstallUtils::getOrCreateInstance('patchService', PatchService::class, $moufManager);
41
42
        if (empty($patchService->getConstructorArgumentProperty('types')->getValue())) {
43
            $patchService->getConstructorArgumentProperty('types')->setValue([ $patchDefaultType, $patchTestDataType ]);
44
        }
45
46
        $consoleUtils = new ConsoleUtils($moufManager);
47
48
        $listPatchesCommand = $moufManager->createInstance(ListPatchesCommand::class);
49
        $listPatchesCommand->getConstructorArgumentProperty("patchService")->setValue($patchService);
50
        $consoleUtils->registerCommand($listPatchesCommand);
51
52
        $applyAllPatchesCommand = $moufManager->createInstance(ApplyAllPatchesCommand::class);
53
        $applyAllPatchesCommand->getConstructorArgumentProperty("patchService")->setValue($patchService);
54
        $consoleUtils->registerCommand($applyAllPatchesCommand);
55
56
        $applyPatchCommand = $moufManager->createInstance(ApplyPatchCommand::class);
57
        $applyPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService);
58
        $consoleUtils->registerCommand($applyPatchCommand);
59
60
        $skipPatchCommand = $moufManager->createInstance(SkipPatchCommand::class);
61
        $skipPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService);
62
        $consoleUtils->registerCommand($skipPatchCommand);
63
64
        $revertPatchCommand = $moufManager->createInstance(RevertPatchCommand::class);
65
        $revertPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService);
66
        $consoleUtils->registerCommand($revertPatchCommand);
67
68
        $resetPatchCommand = $moufManager->createInstance(ResetPatchesCommand::class);
69
        $resetPatchCommand->getConstructorArgumentProperty("patchService")->setValue($patchService);
70
        $consoleUtils->registerCommand($resetPatchCommand);
71
72
        // Let's rewrite the MoufComponents.php file to save the component
73
        $moufManager->rewriteMouf();
74
    }
75
}
76