-
Notifications
You must be signed in to change notification settings - Fork 1
/
InstallOrchestrator.php
167 lines (142 loc) · 6.04 KB
/
InstallOrchestrator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
use \LCI\Blend\Migrations;
class InstallOrchestrator extends Migrations
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Allow Custom .ENV
$custom_base_path = getenv('LCI_ORCHESTRATOR_BASE_PATH');
$custom_base_url = getenv('LCI_ORCHESTRATOR_BASE_URL');
$custom_vendor_path = getenv('LCI_ORCHESTRATOR_VENDOR_PATH');
// 1. MODX namespace
$orchestratorNamespace = $this->modx->getObject('modNamespace', 'orchestrator');
if (!$orchestratorNamespace) {
/** @var \modNamespace $orchestratorNamespace */
$orchestratorNamespace = $this->modx->newObject('modNamespace');
$orchestratorNamespace->set('name', 'orchestrator');
$orchestratorNamespace->set('path', '{core_path}vendor/');
$orchestratorNamespace->set('assets_path', '{assets_path}orchestrator/');
if ($orchestratorNamespace->save()) {
$this->blender->outSuccess('The modNamespace orchestrator has been created');
} else {
$this->blender->out('The modNamespace orchestrator was not created', true);
}
}
// 2. Media source
$orchestratorMediaSource = $this->blender->getBlendableLoader()->getBlendableMediaSource('orchestrator');
$saved = $orchestratorMediaSource
->setFieldDescription('Orchestrator packages')
->setPropertyBasePath(!$custom_base_path ? 'core/vendor/' : $custom_base_path)
->setPropertyBaseUrl(!$custom_base_url ? 'core/vendor/' : $custom_base_url)
->blend();
if ($saved) {
$this->blender->outSuccess('orchestrator MediaSource has been installed');
} else {
$this->blender->out('orchestrator MediaSource was not installed', true);
}
// 3. System setting
/** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */
$systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('orchestrator.vendor_path');
$saved = $systemSetting
->setSeedsDir($this->getSeedsDir())
->setFieldValue(!$custom_vendor_path ? MODX_CORE_PATH.'vendor/' : $custom_vendor_path)
->setFieldArea('Composer')
->setFieldNamespace('orchestrator')
->blend();
if ($saved) {
$this->blender->outSuccess('orchestrator.vendor_path System Setting has been created');
} else {
$this->blender->outError('orchestrator.vendor_path System Setting was not created');
}
// 4. plugin
$plugin = $this->blender->getBlendableLoader()->getBlendablePlugin('requireComposerAutoloader');
$saved = $plugin
->setFieldCategory('Orchestrator')
->setFieldDescription('Will load the composer autoloader.php file inside of MODX')
->setAsStatic('lci/orchestrator/src/elements/plugins/requireComposerAutoloader.php', 'orchestrator')
->attachOnEvent('OnInitCulture')
->blend();
if ($saved) {
$this->blender->outSuccess('requireComposerAutoloader Plugin has been installed');
} else {
$this->blender->outError('requireComposerAutoloader Plugin has been installed');
}
$this->modx->cacheManager->refresh();
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// remove DB Table:
$manager = $this->modx->getManager();
// 4. plugin
$plugin = $this->blender->getBlendableLoader()->getBlendablePlugin('requireComposerAutoloader');
if ($plugin->revertBlend()) {
$this->blender->outSuccess('requireComposerAutoloader Plugin has been reverted');
} else {
$this->blender->out('requireComposerAutoloader Plugin could not be reverted', true);
}
// 3. System setting
/** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */
$systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('orchestrator.vendor_path');
if ($systemSetting->revertBlend()) {
$this->blender->outSuccess('orchestrator.vendor_path System Setting has been reverted');
} else {
$this->blender->out('orchestrator.vendor_path System Setting could not be reverted', true);
}
// 2. Media source
$orchestratorMediaSource = $this->blender->getBlendableLoader()->getBlendableMediaSource('orchestrator');
if ($orchestratorMediaSource->revertBlend()) {
$this->blender->outSuccess('orchestrator MediaSource has been reverted');
} else {
$this->blender->out('orchestrator MediaSource could not be reverted', true);
}
// 1. MODX namespace
/** @var \modNamespace $orchestratorNamespace */
$orchestratorNamespace = $this->modx->getObject('modNamespace', 'orchestrator');
if ($orchestratorNamespace instanceof \modNamespace) {
if ($orchestratorNamespace->remove()) {
$this->blender->outSuccess('orchestrator modNamespace has been removed');
} else {
$this->blender->out('orchestrator modNamespace could not be removed', true);
}
}
$this->modx->cacheManager->refresh();
}
/**
* Method is called on construct, please fill me in
*/
protected function assignDescription()
{
$this->description = 'Install Orchestrator';
}
/**
* Method is called on construct, please fill me in
*/
protected function assignVersion()
{
$this->version = $this->blender->getVersion();
}
/**
* Method is called on construct, can change to only run this migration for those types
*/
protected function assignType()
{
$this->type = 'master';
}
/**
* Method is called on construct, Child class can override and implement this
*/
protected function assignSeedsDir()
{
$this->seeds_dir = '2018_09_03_020202';
}
}