Skip to content

Commit 5e2bf16

Browse files
committed
[stable9] Don't show the updater if updater is incompatible
Prevents us from breaking instances.
1 parent 757ca95 commit 5e2bf16

File tree

3 files changed

+108
-13
lines changed

3 files changed

+108
-13
lines changed

apps/updatenotification/controller/admincontroller.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ public function __construct($appName,
7979
$this->dateTimeFormatter = $dateTimeFormatter;
8080
}
8181

82+
/**
83+
* Whether the instance is compatible with the updater
84+
*
85+
* @return bool
86+
*/
87+
protected function isCompatibleWithUpdater() {
88+
$updaterCompatible = true;
89+
if(!function_exists('proc_open') || !function_exists('shell_exec')) {
90+
$updaterCompatible = false;
91+
} else {
92+
$whichUnzip = shell_exec('command -v unzip');
93+
if(!class_exists('ZipArchive') && empty($whichUnzip)) {
94+
$updaterCompatible = false;
95+
}
96+
97+
$whichPhp = shell_exec('command -v php');
98+
if(empty($whichPhp)) {
99+
$updaterCompatible = false;
100+
}
101+
}
102+
if(!function_exists('curl_exec')) {
103+
$updaterCompatible = false;
104+
}
105+
106+
return $updaterCompatible;
107+
}
108+
82109
/**
83110
* @return TemplateResponse
84111
*/
@@ -94,7 +121,6 @@ public function displayPanel() {
94121
'production',
95122
];
96123
$currentChannel = \OCP\Util::getChannel();
97-
98124
// Remove the currently used channel from the channels list
99125
if(($key = array_search($currentChannel, $channels)) !== false) {
100126
unset($channels[$key]);
@@ -106,6 +132,7 @@ public function displayPanel() {
106132
'currentChannel' => $currentChannel,
107133
'channels' => $channels,
108134
'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'],
135+
'updaterRequirementsFulfilled' => $this->isCompatibleWithUpdater(),
109136
];
110137

111138
return new TemplateResponse($this->appName, 'admin', $params, '');

apps/updatenotification/templates/admin.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
$channels = $_['channels'];
1313
/** @var string $currentChannel */
1414
$currentChannel = $_['currentChannel'];
15+
/** @var bool $updaterRequirementsFulfilled */
16+
$updaterRequirementsFulfilled = $_['updaterRequirementsFulfilled'];
1517
?>
1618
<form id="oca_updatenotification_section" class="section">
1719
<h2><?php p($l->t('Updater')); ?></h2>
1820

1921
<?php if($isNewVersionAvailable === true): ?>
2022
<strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong>
21-
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
23+
<?php if($updaterRequirementsFulfilled === true): ?>
24+
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
25+
<?php else: ?>
26+
<br/><?php p($l->t('At the moment only manual updates are supported on your environment. This is very likely the case because functions such as shell_exec are not available.')); ?>
27+
<?php endif; ?>
2228
<?php else: ?>
2329
<strong><?php print_unescaped($l->t('Your version is up to date.')); ?></strong>
2430
<span class="icon-info svg" title="<?php p($l->t('Checked on %s', [$lastCheckedDate])) ?>"></span>

apps/updatenotification/tests/controller/AdminControllerTest.php

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,23 @@ public function setUp() {
6767
->disableOriginalConstructor()->getMock();
6868
$this->dateTimeFormatter = $this->getMock('\\OCP\\IDateTimeFormatter');
6969

70-
$this->adminController = new AdminController(
71-
'updatenotification',
72-
$this->request,
73-
$this->jobList,
74-
$this->secureRandom,
75-
$this->config,
76-
$this->timeFactory,
77-
$this->l10n,
78-
$this->updateChecker,
79-
$this->dateTimeFormatter
80-
);
70+
$this->adminController = $this->getMockBuilder('\OCA\UpdateNotification\Controller\AdminController')
71+
->setConstructorArgs(
72+
[
73+
'updatenotification',
74+
$this->request,
75+
$this->jobList,
76+
$this->secureRandom,
77+
$this->config,
78+
$this->timeFactory,
79+
$this->l10n,
80+
$this->updateChecker,
81+
$this->dateTimeFormatter,
82+
]
83+
)
84+
->setMethods(['isCompatibleWithUpdater'])
85+
->getMock()
86+
;
8187
}
8288

8389
public function testDisplayPanelWithUpdate() {
@@ -108,13 +114,64 @@ public function testDisplayPanelWithUpdate() {
108114
->expects($this->once())
109115
->method('getUpdateState')
110116
->willReturn(['updateVersion' => '8.1.2']);
117+
$this->adminController
118+
->expects($this->once())
119+
->method('isCompatibleWithUpdater')
120+
->willReturn(true);
111121

112122
$params = [
113123
'isNewVersionAvailable' => true,
114124
'lastChecked' => 'LastCheckedReturnValue',
115125
'currentChannel' => \OCP\Util::getChannel(),
116126
'channels' => $channels,
117127
'newVersionString' => '8.1.2',
128+
'updaterRequirementsFulfilled' => true,
129+
];
130+
131+
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
132+
$this->assertEquals($expected, $this->adminController->displayPanel());
133+
}
134+
135+
public function testDisplayPanelWithUpdateAndIncompatibleUpdaterApp() {
136+
$channels = [
137+
'daily',
138+
'beta',
139+
'stable',
140+
'production',
141+
];
142+
$currentChannel = \OCP\Util::getChannel();
143+
144+
// Remove the currently used channel from the channels list
145+
if(($key = array_search($currentChannel, $channels)) !== false) {
146+
unset($channels[$key]);
147+
}
148+
149+
$this->config
150+
->expects($this->once())
151+
->method('getAppValue')
152+
->with('core', 'lastupdatedat')
153+
->willReturn('12345');
154+
$this->dateTimeFormatter
155+
->expects($this->once())
156+
->method('formatDateTime')
157+
->with('12345')
158+
->willReturn('LastCheckedReturnValue');
159+
$this->updateChecker
160+
->expects($this->once())
161+
->method('getUpdateState')
162+
->willReturn(['updateVersion' => '8.1.2']);
163+
$this->adminController
164+
->expects($this->once())
165+
->method('isCompatibleWithUpdater')
166+
->willReturn(false);
167+
168+
$params = [
169+
'isNewVersionAvailable' => true,
170+
'lastChecked' => 'LastCheckedReturnValue',
171+
'currentChannel' => \OCP\Util::getChannel(),
172+
'channels' => $channels,
173+
'newVersionString' => '8.1.2',
174+
'updaterRequirementsFulfilled' => false,
118175
];
119176

120177
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
@@ -149,13 +206,18 @@ public function testDisplayPanelWithoutUpdate() {
149206
->expects($this->once())
150207
->method('getUpdateState')
151208
->willReturn([]);
209+
$this->adminController
210+
->expects($this->once())
211+
->method('isCompatibleWithUpdater')
212+
->willReturn(true);
152213

153214
$params = [
154215
'isNewVersionAvailable' => false,
155216
'lastChecked' => 'LastCheckedReturnValue',
156217
'currentChannel' => \OCP\Util::getChannel(),
157218
'channels' => $channels,
158219
'newVersionString' => '',
220+
'updaterRequirementsFulfilled' => true,
159221
];
160222

161223
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');

0 commit comments

Comments
 (0)