1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sugarcrm\UpgradeSpec\Updater\Adapter; |
4
|
|
|
|
5
|
|
|
use Humbug\SelfUpdate\Strategy\GithubStrategy; |
6
|
|
|
use Humbug\SelfUpdate\Updater as HumbugUpdater; |
7
|
|
|
use Sugarcrm\UpgradeSpec\Updater\Updater; |
8
|
|
|
|
9
|
|
|
class HumbugAdapter implements AdapterInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var HumbugUpdater |
13
|
|
|
*/ |
14
|
|
|
private $updater; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* HumbugAdapter constructor. |
18
|
|
|
* |
19
|
|
|
* @param HumbugUpdater $updater |
20
|
|
|
*/ |
21
|
|
|
public function __construct(HumbugUpdater $updater) |
22
|
|
|
{ |
23
|
|
|
$this->updater = $updater; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
|
|
public function hasUpdate() |
30
|
|
|
{ |
31
|
|
|
return $this->updater->hasUpdate(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return mixed |
|
|
|
|
36
|
|
|
*/ |
37
|
|
|
public function getOldVersion() |
38
|
|
|
{ |
39
|
|
|
return $this->updater->getOldVersion(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return mixed |
|
|
|
|
44
|
|
|
*/ |
45
|
|
|
public function getNewVersion() |
46
|
|
|
{ |
47
|
|
|
return $this->updater->getNewVersion(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $stability |
52
|
|
|
* |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
public function update($stability = Updater::STABILITY_ANY) |
56
|
|
|
{ |
57
|
|
|
$strategy = $this->updater->getStrategy(); |
58
|
|
|
if ($strategy instanceof GithubStrategy) { |
59
|
|
|
$this->updater->getStrategy()->setStability($this->getGithubStability($stability)); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$result = $this->updater->update(); |
63
|
|
|
|
64
|
|
|
$this->performCleanup(); |
65
|
|
|
|
66
|
|
|
return $result; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
public function rollback() |
73
|
|
|
{ |
74
|
|
|
return $this->updater->rollback(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param $stability |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
private function getGithubStability($stability) |
83
|
|
|
{ |
84
|
|
|
if ($stability == Updater::STABILITY_STABLE) { |
85
|
|
|
return GithubStrategy::STABLE; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($stability == Updater::STABILITY_UNSTABLE) { |
89
|
|
|
return GithubStrategy::UNSTABLE; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return GithubStrategy::ANY; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Removes PHAR update leftovers. |
97
|
|
|
*/ |
98
|
|
|
private function performCleanup() |
99
|
|
|
{ |
100
|
|
|
$directory = $this->updater->getTempDirectory(); |
101
|
|
|
$fileBasename = $this->updater->getLocalPharFileBasename(); |
102
|
|
|
|
103
|
|
|
@unlink(sprintf('%s/%s.phar.temp.pubkey', $directory, $fileBasename)); |
|
|
|
|
104
|
|
|
@unlink(sprintf('%s/%s.temp.pubkey', $directory, $fileBasename)); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.