1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sugarcrm\UpgradeSpec\Data; |
4
|
|
|
|
5
|
|
|
use Sugarcrm\UpgradeSpec\Context\Upgrade; |
6
|
|
|
use Sugarcrm\UpgradeSpec\Version\OrderedList; |
7
|
|
|
use Sugarcrm\UpgradeSpec\Version\Version; |
8
|
|
|
|
9
|
|
|
class Manager |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var ProviderChain |
13
|
|
|
*/ |
14
|
|
|
private $provider; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Manager constructor. |
18
|
|
|
* |
19
|
|
|
* @param ProviderChain $provider |
20
|
|
|
*/ |
21
|
|
|
public function __construct(ProviderChain $provider) |
22
|
|
|
{ |
23
|
|
|
$this->provider = $provider; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Gets all available SugarCRM versions (sorted ASC). |
28
|
|
|
* |
29
|
|
|
* @param string $flav |
30
|
|
|
* |
31
|
|
|
* @return OrderedList |
32
|
|
|
*/ |
33
|
|
|
public function getVersions($flav) |
34
|
|
|
{ |
35
|
|
|
$versions = $this->provider->getVersions($flav); |
36
|
|
|
if (!count($versions)) { |
37
|
|
|
throw new \RuntimeException(sprintf('No "%s" versions available', $flav)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $versions; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Gets the latest available SugarCRM version with given flav and base version. |
45
|
|
|
* |
46
|
|
|
* Examples: 7.6.1 -> 7.6.1.0, 7.7 -> 7.7.1, 7.8 -> 7.8.0.0 |
47
|
|
|
* |
48
|
|
|
* @param string $flav |
49
|
|
|
* @param Version|null $baseVersion |
50
|
|
|
* |
51
|
|
|
* @return Version |
52
|
|
|
*/ |
53
|
|
|
public function getLatestVersion($flav, Version $baseVersion = null) |
54
|
|
|
{ |
55
|
|
|
$versions = $this->getVersions($flav); |
56
|
|
|
|
57
|
|
|
// the latest available |
58
|
|
|
if (is_null($baseVersion)) { |
59
|
|
|
return $versions->last(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// is minor bugfix version |
63
|
|
|
if ($baseVersion->isFull()) { |
64
|
|
|
if (!$versions->contains($baseVersion)) { |
65
|
|
|
throw new \InvalidArgumentException(sprintf('Unknown version: %s', $baseVersion)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $baseVersion; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* all versions with $baseVersion base |
73
|
|
|
* for example: 7.6.1 -> [7.6.1, 7.6.1.0, 7.6.1.1], 7.6 -> [7.6.1.0, 7.6.1.1, 7.6.2]. |
74
|
|
|
*/ |
75
|
|
|
$minors = $versions->filter(function (Version $version) use ($baseVersion) { |
76
|
|
|
return $version->isChildOf($baseVersion) || $version->isEqualTo($baseVersion); |
77
|
|
|
}); |
78
|
|
|
|
79
|
|
|
if (!count($minors)) { |
80
|
|
|
throw new \InvalidArgumentException(sprintf('No minor versions available for version: %s', $baseVersion)); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $minors->last(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Gets release notes for all versions from given range. |
88
|
|
|
* |
89
|
|
|
* @param Upgrade $context |
90
|
|
|
* |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function getReleaseNotes(Upgrade $context) |
94
|
|
|
{ |
95
|
|
|
$versions = $this->getVersionRange($context); |
96
|
|
|
|
97
|
|
|
return $this->provider->getReleaseNotes($context->getBuildFlav(), $versions); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Gets all required information to perform health check. |
102
|
|
|
* |
103
|
|
|
* @param Version $version |
104
|
|
|
* |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
public function getHealthCheckInfo(Version $version) |
108
|
|
|
{ |
109
|
|
|
return $this->provider->getHealthCheckInfo($version); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Gets all required information to perform upgrade. |
114
|
|
|
* |
115
|
|
|
* @param Version $version |
116
|
|
|
* |
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
|
|
public function getUpgraderInfo(Version $version) |
120
|
|
|
{ |
121
|
|
|
return $this->provider->getUpgraderInfo($version); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Gets the list of potentially broken customizations (changed and deleted files) |
126
|
|
|
* |
127
|
|
|
* @param Upgrade $context |
128
|
|
|
* |
129
|
|
|
* @return mixed |
130
|
|
|
*/ |
131
|
|
|
public function getPotentiallyBrokenCustomizations(Upgrade $context) |
132
|
|
|
{ |
133
|
|
|
return $this->provider->getPotentiallyBrokenCustomizations($context); |
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Gets the lists of upgrade steps for the given source |
138
|
|
|
* |
139
|
|
|
* @param Upgrade $context |
140
|
|
|
* |
141
|
|
|
* @return mixed |
142
|
|
|
*/ |
143
|
|
|
public function getUpgradeSteps(Upgrade $context) |
144
|
|
|
{ |
145
|
|
|
return $this->provider->getUpgradeSteps($context); |
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Gets all available versions from given range ($from < version <= $to). |
150
|
|
|
* |
151
|
|
|
* @param Upgrade $context |
152
|
|
|
* |
153
|
|
|
* @return OrderedList |
154
|
|
|
*/ |
155
|
|
|
private function getVersionRange(Upgrade $context) |
156
|
|
|
{ |
157
|
|
|
$from = (string) $context->getBuildVersion()->getFull(); |
|
|
|
|
158
|
|
|
$to = (string) $context->getTargetVersion()->getFull(); |
|
|
|
|
159
|
|
|
|
160
|
|
|
return $this->getVersions($context->getBuildFlav())->filter(function (Version $version) use ($from, $to) { |
161
|
|
|
return version_compare((string) $version, $from, '>') |
162
|
|
|
&& version_compare((string) $version, $to, '<='); |
163
|
|
|
}); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: