Repository navigation
Expand file tree
/
Copy path2022_04_13_085018_clean_up_and_remove_package_advanced_forms.php
More file actions
150 lines (133 loc) · 4.2 KB
/
Copy path2022_04_13_085018_clean_up_and_remove_package_advanced_forms.php
File metadata and controls
150 lines (133 loc) · 4.2 KB
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
<?php
use ProcessMaker\Models\Screen;
use ProcessMaker\Models\ScreenVersion;
use ProcessMaker\Models\ScreenType;
use ProcessMaker\Upgrades\UpgradeMigration as Upgrade;
use Illuminate\Support\Facades\File;
class CleanUpAndRemovePackageAdvancedForms extends Upgrade
{
/**
* The version of ProcessMaker being upgraded *to*
*
* @var string example: 4.2.28
*/
public $to = '4.2.30-RC1';
/**
* Upgrade migration cannot be skipped if the pre-upgrade checks fail
*
* @var bool
*/
public $required = false;
/**
* Run any validations/pre-run checks to ensure the environment, settings,
* packages installed, etc. are right correct to run this upgrade.
*
* There is no need to check against the version(s) as the upgrade
* migrator will do this automatically and fail if the correct
* version(s) are not present.
*
* Throw a \RuntimeException if the conditions are *NOT* correct for this
* upgrade migration to run. If this is not a required upgrade, then it
* will be skipped. Otherwise the exception thrown will be caught, noted,
* and will prevent the remaining migrations from continuing to run.
*
* Returning void or null denotes the checks were successful.
*
* @return void
*
* @throws \RuntimeException
*/
public function preflightChecks()
{
if (!$this->packageAdvancedFormsInstalled()) {
throw new RuntimeException('This upgrade migration requires package-advancedforms to be installed.');
}
if ($this->advancedTypeScreensExist()) {
throw new RuntimeException('There are screens found with the type "ADVANCED". Please update or remove these screens and re-run this upgrade migration.');
}
}
/**
* Run the upgrade migrations.
*
* @return void
*/
public function up()
{
$this->composerRemovePackageAdvancedForms();
$this->removeAdvancedScreenType();
$this->removePublishedAssets();
}
/**
* Reverse the upgrade migrations.
*
* @return void
*/
public function down()
{
$this->installPackageAdvancedForms();
}
/**
* Install package-advancedforms with composer then run the package install command
*
* @return void
*
* @throws \RuntimeException
*/
protected function installPackageAdvancedForms(): void
{
if (!is_string(system($command = 'composer require processmaker/package-advancedforms --no-interaction > /dev/null 2>&1'))) {
throw new RuntimeException("Unknown error while running: {$command}");
}
if (!is_string(system($command = PHP_BINARY.' '. base_path('artisan') .' package-advancedforms:install > /dev/null 2>&1'))) {
throw new RuntimeException("Unknown error while running: {$command}");
}
}
/**
* Remove package-advancedforms using composer
*
* @return void
*/
protected function composerRemovePackageAdvancedForms(): void
{
system('composer remove processmaker/package-advancedforms --no-interaction');
}
/**
* Remove the ScreenType: "ADVANCED"
*
* @return void
*/
protected function removeAdvancedScreenType(): void
{
ScreenType::query()->where('name', 'ADVANCED')->delete();
}
/**
* Removes the published front-end assets for package-advancedforms
*
* @return void
*/
protected function removePublishedAssets(): void
{
if (File::exists($path = public_path('vendor/processmaker/packages/package-advancedforms'))) {
File::deleteDirectory($path);
}
}
/**
* Are there Screens with the type "ADVANCED"?
*
* @return bool
*/
protected function advancedTypeScreensExist(): bool
{
return ScreenVersion::query()->where('type', 'ADVANCED')->exists()
|| Screen::query()->where('type', 'ADVANCED')->exists();
}
/**
* Is package-advancedforms installed
*
* @return bool
*/
protected function packageAdvancedFormsInstalled(): bool
{
return File::exists(base_path('vendor/processmaker/package-advancedforms'));
}
}