Skip to content

Commit 2d14612

Browse files
authored
Merge pull request #1501 from nextcloud/stable9-backport-1499
[stable9] Add repair step and revert "Open updater" button
2 parents f7d5351 + 91757e7 commit 2d14612

File tree

8 files changed

+127
-125
lines changed

8 files changed

+127
-125
lines changed

apps/updatenotification/controller/admincontroller.php

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,6 @@ public function __construct($appName,
8080
$this->dateTimeFormatter = $dateTimeFormatter;
8181
}
8282

83-
/**
84-
* Whether the instance is compatible with the updater
85-
*
86-
* @return bool
87-
*/
88-
protected function isCompatibleWithUpdater() {
89-
$updaterCompatible = true;
90-
if(!function_exists('proc_open') || !function_exists('shell_exec')) {
91-
$updaterCompatible = false;
92-
} else {
93-
$whichUnzip = shell_exec('command -v unzip');
94-
if(!class_exists('ZipArchive') && empty($whichUnzip)) {
95-
$updaterCompatible = false;
96-
}
97-
98-
$whichPhp = shell_exec('command -v php');
99-
if(empty($whichPhp)) {
100-
$updaterCompatible = false;
101-
}
102-
}
103-
if(!function_exists('curl_exec')) {
104-
$updaterCompatible = false;
105-
}
106-
107-
return $updaterCompatible;
108-
}
109-
11083
/**
11184
* @return TemplateResponse
11285
*/
@@ -122,6 +95,7 @@ public function displayPanel() {
12295
'production',
12396
];
12497
$currentChannel = \OCP\Util::getChannel();
98+
12599
// Remove the currently used channel from the channels list
126100
if(($key = array_search($currentChannel, $channels)) !== false) {
127101
unset($channels[$key]);
@@ -133,8 +107,6 @@ public function displayPanel() {
133107
'currentChannel' => $currentChannel,
134108
'channels' => $channels,
135109
'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'],
136-
'updaterRequirementsFulfilled' => $this->isCompatibleWithUpdater(),
137-
'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'],
138110
];
139111

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

apps/updatenotification/js/admin.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,32 @@
1313
/**
1414
* Creates a new authentication token and loads the updater URL
1515
*/
16+
var loginToken = '';
1617
$(document).ready(function(){
18+
$('#oca_updatenotification_button').click(function() {
19+
// Load the new token
20+
$.ajax({
21+
url: OC.generateUrl('/apps/updatenotification/credentials')
22+
}).success(function(data) {
23+
loginToken = data;
24+
$.ajax({
25+
url: OC.webroot+'/updater/',
26+
headers: {
27+
'X-Updater-Auth': loginToken
28+
},
29+
method: 'POST',
30+
success: function(data){
31+
if(data !== 'false') {
32+
var body = $('body');
33+
$('head').remove();
34+
body.html(data);
35+
body.removeAttr('id');
36+
body.attr('id', 'body-settings');
37+
}
38+
}
39+
});
40+
});
41+
});
1742
$('#release-channel').change(function() {
1843
var newChannel = $('#release-channel').find(":selected").val();
1944
$.post(

apps/updatenotification/lib/updatechecker.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public function getUpdateState() {
4848
if(substr($data['web'], 0, 8) === 'https://') {
4949
$result['updateLink'] = $data['web'];
5050
}
51-
if(substr($data['url'], 0, 8) === 'https://') {
52-
$result['downloadLink'] = $data['url'];
53-
}
5451

5552
return $result;
5653
}

apps/updatenotification/templates/admin.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212
$channels = $_['channels'];
1313
/** @var string $currentChannel */
1414
$currentChannel = $_['currentChannel'];
15-
/** @var bool $updaterRequirementsFulfilled */
16-
$updaterRequirementsFulfilled = $_['updaterRequirementsFulfilled'];
1715
?>
1816
<form id="oca_updatenotification_section" class="section">
1917
<h2><?php p($l->t('Updater')); ?></h2>
2018

2119
<?php if($isNewVersionAvailable === true): ?>
2220
<strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong>
23-
<?php if ($_['downloadLink']): ?>
24-
<a href="<?php p($_['downloadLink']); ?>" class="button"><?php p($l->t('Download now')) ?></a>
25-
<?php endif; ?>
21+
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
2622
<?php else: ?>
2723
<strong><?php print_unescaped($l->t('Your version is up to date.')); ?></strong>
2824
<span class="icon-info svg" title="<?php p($l->t('Checked on %s', [$lastCheckedDate])) ?>"></span>

apps/updatenotification/tests/UpdateCheckerTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ public function testGetUpdateStateWithUpdateAndInvalidLink() {
4646
->method('check')
4747
->willReturn([
4848
'version' => 123,
49-
'versionstring' => 'Nextcloud 123',
49+
'versionstring' => 'ownCloud 123',
5050
'web'=> 'javascript:alert(1)',
51-
'url'=> 'javascript:alert(2)',
5251
]);
5352

5453
$expected = [
5554
'updateAvailable' => true,
56-
'updateVersion' => 'Nextcloud 123',
55+
'updateVersion' => 'ownCloud 123',
5756
];
5857
$this->assertSame($expected, $this->updateChecker->getUpdateState());
5958
}
@@ -64,16 +63,14 @@ public function testGetUpdateStateWithUpdateAndValidLink() {
6463
->method('check')
6564
->willReturn([
6665
'version' => 123,
67-
'versionstring' => 'Nextcloud 123',
68-
'web'=> 'https://docs.nextcloud.com/myUrl',
69-
'url'=> 'https://downloads.nextcloud.org/server',
66+
'versionstring' => 'ownCloud 123',
67+
'web'=> 'https://owncloud.org/myUrl',
7068
]);
7169

7270
$expected = [
7371
'updateAvailable' => true,
74-
'updateVersion' => 'Nextcloud 123',
75-
'updateLink' => 'https://docs.nextcloud.com/myUrl',
76-
'downloadLink' => 'https://downloads.nextcloud.org/server',
72+
'updateVersion' => 'ownCloud 123',
73+
'updateLink' => 'https://owncloud.org/myUrl',
7774
];
7875
$this->assertSame($expected, $this->updateChecker->getUpdateState());
7976
}

apps/updatenotification/tests/controller/AdminControllerTest.php

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

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

9084
public function testDisplayPanelWithUpdate() {
@@ -115,69 +109,13 @@ public function testDisplayPanelWithUpdate() {
115109
->expects($this->once())
116110
->method('getUpdateState')
117111
->willReturn(['updateVersion' => '8.1.2']);
118-
$this->adminController
119-
->expects($this->once())
120-
->method('isCompatibleWithUpdater')
121-
->willReturn(true);
122-
123-
$params = [
124-
'isNewVersionAvailable' => true,
125-
'lastChecked' => 'LastCheckedReturnValue',
126-
'currentChannel' => \OCP\Util::getChannel(),
127-
'channels' => $channels,
128-
'newVersionString' => '8.1.2',
129-
'updaterRequirementsFulfilled' => true,
130-
'downloadLink' => '',
131-
];
132-
133-
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
134-
$this->assertEquals($expected, $this->adminController->displayPanel());
135-
}
136-
137-
public function testDisplayPanelWithUpdateAndIncompatibleUpdaterApp() {
138-
$channels = [
139-
'daily',
140-
'beta',
141-
'stable',
142-
'production',
143-
];
144-
$currentChannel = \OCP\Util::getChannel();
145-
146-
// Remove the currently used channel from the channels list
147-
if(($key = array_search($currentChannel, $channels)) !== false) {
148-
unset($channels[$key]);
149-
}
150-
151-
$this->config
152-
->expects($this->once())
153-
->method('getAppValue')
154-
->with('core', 'lastupdatedat')
155-
->willReturn('12345');
156-
$this->dateTimeFormatter
157-
->expects($this->once())
158-
->method('formatDateTime')
159-
->with('12345')
160-
->willReturn('LastCheckedReturnValue');
161-
$this->updateChecker
162-
->expects($this->once())
163-
->method('getUpdateState')
164-
->willReturn([
165-
'updateVersion' => '8.1.2',
166-
'downloadLink' => 'https://downloads.nextcloud.org/server',
167-
]);
168-
$this->adminController
169-
->expects($this->once())
170-
->method('isCompatibleWithUpdater')
171-
->willReturn(false);
172112

173113
$params = [
174114
'isNewVersionAvailable' => true,
175115
'lastChecked' => 'LastCheckedReturnValue',
176116
'currentChannel' => \OCP\Util::getChannel(),
177117
'channels' => $channels,
178118
'newVersionString' => '8.1.2',
179-
'updaterRequirementsFulfilled' => false,
180-
'downloadLink' => 'https://downloads.nextcloud.org/server',
181119
];
182120

183121
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
@@ -212,19 +150,13 @@ public function testDisplayPanelWithoutUpdate() {
212150
->expects($this->once())
213151
->method('getUpdateState')
214152
->willReturn([]);
215-
$this->adminController
216-
->expects($this->once())
217-
->method('isCompatibleWithUpdater')
218-
->willReturn(true);
219153

220154
$params = [
221155
'isNewVersionAvailable' => false,
222156
'lastChecked' => 'LastCheckedReturnValue',
223157
'currentChannel' => \OCP\Util::getChannel(),
224158
'channels' => $channels,
225159
'newVersionString' => '',
226-
'updaterRequirementsFulfilled' => true,
227-
'downloadLink' => '',
228160
];
229161

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

lib/private/repair.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use OC\Repair\DropOldJobs;
4242
use OC\Repair\EncryptionCompatibility;
4343
use OC\Repair\MoveChannelToSystemConfig;
44+
use OC\Repair\MoveUpdaterStepFile;
4445
use OC\Repair\OldGroupMembershipShares;
4546
use OC\Repair\RemoveGetETagEntries;
4647
use OC\Repair\SqliteAutoincrement;
@@ -123,6 +124,7 @@ public static function getRepairSteps() {
123124
new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
124125
new AvatarPermissions(\OC::$server->getDatabaseConnection()),
125126
new MoveChannelToSystemConfig(\OC::$server->getConfig()),
127+
new MoveUpdaterStepFile(\OC::$server->getConfig()),
126128
];
127129
}
128130

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016 Morris Jobke <hey@morrisjobke.de>
4+
*
5+
* @author Morris Jobke <hey@morrisjobke.de>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OC\Repair;
25+
26+
use OC\Hooks\BasicEmitter;
27+
use OCP\Migration\IOutput;
28+
use OCP\Migration\IRepairStep;
29+
30+
class MoveUpdaterStepFile extends BasicEmitter implements \OC\RepairStep {
31+
32+
/** @var \OCP\IConfig */
33+
protected $config;
34+
35+
/**
36+
* @param \OCP\IConfig $config
37+
*/
38+
public function __construct($config) {
39+
$this->config = $config;
40+
}
41+
42+
public function getName() {
43+
return 'Move .step file of updater to backup location';
44+
}
45+
46+
public function run() {
47+
48+
$dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT);
49+
$instanceId = $this->config->getSystemValue('instanceid', null);
50+
51+
if(!is_string($instanceId) || empty($instanceId)) {
52+
return;
53+
}
54+
55+
$updaterFolderPath = $dataDir . '/updater-' . $instanceId;
56+
$stepFile = $updaterFolderPath . '/.step';
57+
if(file_exists($stepFile)) {
58+
$this->emit('\OC\Repair', 'info', array('.step file exists'));
59+
60+
$previousStepFile = $updaterFolderPath . '/.step-previous-update';
61+
62+
// cleanup
63+
if(file_exists($previousStepFile)) {
64+
if(\OC_Helper::rmdirr($previousStepFile)) {
65+
$this->emit('\OC\Repair', 'info', array('.step-previous-update removed'));
66+
} else {
67+
$this->emit('\OC\Repair', 'info', array('.step-previous-update can\'t be removed - abort move of .step file'));
68+
return;
69+
}
70+
}
71+
72+
// move step file
73+
if(rename($stepFile, $previousStepFile)) {
74+
$this->emit('\OC\Repair', 'info', array('.step file moved to .step-previous-update'));
75+
} else {
76+
$this->emit('\OC\Repair', 'warning', array('.step file can\'t be moved'));
77+
}
78+
}
79+
}
80+
}
81+

0 commit comments

Comments
 (0)