1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sugarcrm\UpgradeSpec\Data\Provider; |
4
|
|
|
|
5
|
|
|
use Sugarcrm\UpgradeSpec\Data\Provider\Doc\DocProviderInterface; |
6
|
|
|
use Sugarcrm\UpgradeSpec\Data\Provider\SourceCode\SourceCodeProviderInterface; |
7
|
|
|
use Sugarcrm\UpgradeSpec\Context\Upgrade; |
8
|
|
|
use Sugarcrm\UpgradeSpec\Version\OrderedList; |
9
|
|
|
use Sugarcrm\UpgradeSpec\Version\Version; |
10
|
|
|
|
11
|
|
|
class Memory implements DocProviderInterface, SourceCodeProviderInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
private $data; |
17
|
|
|
|
18
|
|
|
public function __construct(array $data = []) |
19
|
|
|
{ |
20
|
|
|
$this->data = $data; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get all available SugarCRM versions (sorted ASC). |
25
|
|
|
* |
26
|
|
|
* @param string $flav |
27
|
|
|
* |
28
|
|
|
* @return OrderedList |
29
|
|
|
*/ |
30
|
|
|
public function getVersions($flav) |
31
|
|
|
{ |
32
|
|
|
return new OrderedList($this->get($flav . '_versions', [])); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get release notes for all available versions from given range. |
37
|
|
|
* |
38
|
|
|
* @param $flav |
39
|
|
|
* @param OrderedList $versions |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getReleaseNotes($flav, OrderedList $versions) |
44
|
|
|
{ |
45
|
|
|
$releaseNotes = []; |
46
|
|
|
foreach ($versions as $version) { |
47
|
|
|
$releaseNotes[(string) $version] = $this->get(sprintf('%s_%s_release_notes', $flav, $version), ''); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $releaseNotes; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Gets all required information to perform health check. |
55
|
|
|
* |
56
|
|
|
* @param Version $version |
57
|
|
|
* |
58
|
|
|
* @return mixed |
59
|
|
|
*/ |
60
|
|
|
public function getHealthCheckInfo(Version $version) |
61
|
|
|
{ |
62
|
|
|
return $this->get($version . '_health_check', ''); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Gets all required information to perform upgrade. |
67
|
|
|
* |
68
|
|
|
* @param Version $version |
69
|
|
|
* |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
public function getUpgraderInfo(Version $version) |
73
|
|
|
{ |
74
|
|
|
return $this->get($version . '_upgrader', ''); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Gets the list of potentially broken customizations (changed and deleted files) |
79
|
|
|
* |
80
|
|
|
* @param Upgrade $context |
81
|
|
|
* |
82
|
|
|
* @return mixed |
83
|
|
|
*/ |
84
|
|
|
public function getPotentiallyBrokenCustomizations(Upgrade $context) |
85
|
|
|
{ |
86
|
|
|
return $this->get($context . '_customizations', [[], []]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Gets the lists of upgrade steps for the given source |
91
|
|
|
* |
92
|
|
|
* @param Upgrade $context |
93
|
|
|
* |
94
|
|
|
* @return mixed |
95
|
|
|
*/ |
96
|
|
|
public function getUpgradeSteps(Upgrade $context) |
97
|
|
|
{ |
98
|
|
|
return $this->get($context . '_upgrade_steps', []); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Gets data from memory by key. |
103
|
|
|
* |
104
|
|
|
* @param $key |
105
|
|
|
* @param null $default |
106
|
|
|
* |
107
|
|
|
* @return mixed|null |
108
|
|
|
*/ |
109
|
|
|
private function get($key, $default = null) |
110
|
|
|
{ |
111
|
|
|
$key = mb_strtolower($key); |
112
|
|
|
|
113
|
|
|
return isset($this->data[$key]) ? $this->data[$key] : $default; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|