-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathPackageChecker.php
More file actions
127 lines (105 loc) · 3.19 KB
/
PackageChecker.php
File metadata and controls
127 lines (105 loc) · 3.19 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
<?php
namespace ProcessMaker;
class PackageChecker
{
private $name;
private $errors = [];
public function __construct($name)
{
$this->name = $name;
}
public function check($fn)
{
$message = $fn();
if ($message) {
$this->errors[] = $message;
}
}
public function getErrors()
{
return $this->errors;
}
public function hasEnvVars($vars)
{
foreach ($vars as $var) {
if (getenv($var) === false) {
$this->errors[] = "Environment variable missing $var";
}
}
}
public function hasDatabaseEntry($class, $name, $column = 'key')
{
if (!$class::where($column, $name)->exists()) {
$model = new $class;
$this->errors[] = "{$model->getTable()} table does not have $name in the $column column";
}
}
public function checkPublishedAssets()
{
foreach ($this->publishedFolders() as $local => $remote) {
if ($this->hashFolder($local) !== $this->hashFolder($remote)) {
$this->errors[] = 'Package assets not published';
}
}
}
public function checkRequiredPackages()
{
$installedCorePackages = $this->composerPackages();
foreach ($this->requiredPackages() as $package => $version) {
if (!isset($installedCorePackages[$package])) {
$this->errors[] = "Package missing: $package";
} elseif ($installedCorePackages[$package] !== '') {
// TODO: Check semver satisfies. See Composer\Semver package
}
}
}
public function artisanOutput($artisan)
{
if (count($this->errors) > 0) {
foreach ($this->errors as $error) {
$artisan->error($error);
}
} else {
$artisan->info('Package installed and configured correctly');
}
}
private function requiredPackages()
{
return (array) $this->packageComposer()->require;
}
private function composerPackages()
{
exec('composer show | awk \'{ print $1 "|" $2 }\'', $out);
$lines = collect($out);
return $lines->mapWithKeys(function ($line) {
$parts = explode('|', $line);
return [$parts[0] => $parts[1]];
});
}
private function publishedFolders()
{
$folders = [];
foreach ($this->packageProviders() as $provider) {
$folders = array_merge($folders, $provider::$publishes[$provider]);
}
return $folders;
}
public function packageProviders()
{
return $this->packageComposer()->extra->laravel->providers;
}
private function packageComposer()
{
$packageComposerPath = base_path("vendor/processmaker/{$this->name}/composer.json");
return json_decode(file_get_contents($packageComposerPath));
}
private function hashFolder($folder)
{
$cmd = "ls -alR --ignore='.*' $folder | awk '{ print $5 $9 }' | sha1sum";
exec($cmd, $out, $ret);
if ($ret !== 0) {
throw new \Exception(implode("\n", $out));
}
return $out[0];
}
}