[stable9] Don't show the updater if updater is incompatible

Prevents us from breaking instances.
This commit is contained in:
Lukas Reschke 2016-06-13 22:03:19 +02:00
parent 757ca9593a
commit 5e2bf16db1
No known key found for this signature in database
GPG Key ID: 9AB0ADB949B6898C
3 changed files with 108 additions and 13 deletions

View File

@ -79,6 +79,33 @@ class AdminController extends Controller {
$this->dateTimeFormatter = $dateTimeFormatter; $this->dateTimeFormatter = $dateTimeFormatter;
} }
/**
* Whether the instance is compatible with the updater
*
* @return bool
*/
protected function isCompatibleWithUpdater() {
$updaterCompatible = true;
if(!function_exists('proc_open') || !function_exists('shell_exec')) {
$updaterCompatible = false;
} else {
$whichUnzip = shell_exec('command -v unzip');
if(!class_exists('ZipArchive') && empty($whichUnzip)) {
$updaterCompatible = false;
}
$whichPhp = shell_exec('command -v php');
if(empty($whichPhp)) {
$updaterCompatible = false;
}
}
if(!function_exists('curl_exec')) {
$updaterCompatible = false;
}
return $updaterCompatible;
}
/** /**
* @return TemplateResponse * @return TemplateResponse
*/ */
@ -94,7 +121,6 @@ class AdminController extends Controller {
'production', 'production',
]; ];
$currentChannel = \OCP\Util::getChannel(); $currentChannel = \OCP\Util::getChannel();
// Remove the currently used channel from the channels list // Remove the currently used channel from the channels list
if(($key = array_search($currentChannel, $channels)) !== false) { if(($key = array_search($currentChannel, $channels)) !== false) {
unset($channels[$key]); unset($channels[$key]);
@ -106,6 +132,7 @@ class AdminController extends Controller {
'currentChannel' => $currentChannel, 'currentChannel' => $currentChannel,
'channels' => $channels, 'channels' => $channels,
'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'], 'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'],
'updaterRequirementsFulfilled' => $this->isCompatibleWithUpdater(),
]; ];
return new TemplateResponse($this->appName, 'admin', $params, ''); return new TemplateResponse($this->appName, 'admin', $params, '');

View File

@ -12,13 +12,19 @@
$channels = $_['channels']; $channels = $_['channels'];
/** @var string $currentChannel */ /** @var string $currentChannel */
$currentChannel = $_['currentChannel']; $currentChannel = $_['currentChannel'];
/** @var bool $updaterRequirementsFulfilled */
$updaterRequirementsFulfilled = $_['updaterRequirementsFulfilled'];
?> ?>
<form id="oca_updatenotification_section" class="section"> <form id="oca_updatenotification_section" class="section">
<h2><?php p($l->t('Updater')); ?></h2> <h2><?php p($l->t('Updater')); ?></h2>
<?php if($isNewVersionAvailable === true): ?> <?php if($isNewVersionAvailable === true): ?>
<strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong> <strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong>
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>"> <?php if($updaterRequirementsFulfilled === true): ?>
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
<?php else: ?>
<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.')); ?>
<?php endif; ?>
<?php else: ?> <?php else: ?>
<strong><?php print_unescaped($l->t('Your version is up to date.')); ?></strong> <strong><?php print_unescaped($l->t('Your version is up to date.')); ?></strong>
<span class="icon-info svg" title="<?php p($l->t('Checked on %s', [$lastCheckedDate])) ?>"></span> <span class="icon-info svg" title="<?php p($l->t('Checked on %s', [$lastCheckedDate])) ?>"></span>

View File

@ -67,17 +67,23 @@ class AdminControllerTest extends TestCase {
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->dateTimeFormatter = $this->getMock('\\OCP\\IDateTimeFormatter'); $this->dateTimeFormatter = $this->getMock('\\OCP\\IDateTimeFormatter');
$this->adminController = new AdminController( $this->adminController = $this->getMockBuilder('\OCA\UpdateNotification\Controller\AdminController')
'updatenotification', ->setConstructorArgs(
$this->request, [
$this->jobList, 'updatenotification',
$this->secureRandom, $this->request,
$this->config, $this->jobList,
$this->timeFactory, $this->secureRandom,
$this->l10n, $this->config,
$this->updateChecker, $this->timeFactory,
$this->dateTimeFormatter $this->l10n,
); $this->updateChecker,
$this->dateTimeFormatter,
]
)
->setMethods(['isCompatibleWithUpdater'])
->getMock()
;
} }
public function testDisplayPanelWithUpdate() { public function testDisplayPanelWithUpdate() {
@ -108,6 +114,10 @@ class AdminControllerTest extends TestCase {
->expects($this->once()) ->expects($this->once())
->method('getUpdateState') ->method('getUpdateState')
->willReturn(['updateVersion' => '8.1.2']); ->willReturn(['updateVersion' => '8.1.2']);
$this->adminController
->expects($this->once())
->method('isCompatibleWithUpdater')
->willReturn(true);
$params = [ $params = [
'isNewVersionAvailable' => true, 'isNewVersionAvailable' => true,
@ -115,6 +125,53 @@ class AdminControllerTest extends TestCase {
'currentChannel' => \OCP\Util::getChannel(), 'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels, 'channels' => $channels,
'newVersionString' => '8.1.2', 'newVersionString' => '8.1.2',
'updaterRequirementsFulfilled' => true,
];
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
$this->assertEquals($expected, $this->adminController->displayPanel());
}
public function testDisplayPanelWithUpdateAndIncompatibleUpdaterApp() {
$channels = [
'daily',
'beta',
'stable',
'production',
];
$currentChannel = \OCP\Util::getChannel();
// Remove the currently used channel from the channels list
if(($key = array_search($currentChannel, $channels)) !== false) {
unset($channels[$key]);
}
$this->config
->expects($this->once())
->method('getAppValue')
->with('core', 'lastupdatedat')
->willReturn('12345');
$this->dateTimeFormatter
->expects($this->once())
->method('formatDateTime')
->with('12345')
->willReturn('LastCheckedReturnValue');
$this->updateChecker
->expects($this->once())
->method('getUpdateState')
->willReturn(['updateVersion' => '8.1.2']);
$this->adminController
->expects($this->once())
->method('isCompatibleWithUpdater')
->willReturn(false);
$params = [
'isNewVersionAvailable' => true,
'lastChecked' => 'LastCheckedReturnValue',
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'newVersionString' => '8.1.2',
'updaterRequirementsFulfilled' => false,
]; ];
$expected = new TemplateResponse('updatenotification', 'admin', $params, ''); $expected = new TemplateResponse('updatenotification', 'admin', $params, '');
@ -149,6 +206,10 @@ class AdminControllerTest extends TestCase {
->expects($this->once()) ->expects($this->once())
->method('getUpdateState') ->method('getUpdateState')
->willReturn([]); ->willReturn([]);
$this->adminController
->expects($this->once())
->method('isCompatibleWithUpdater')
->willReturn(true);
$params = [ $params = [
'isNewVersionAvailable' => false, 'isNewVersionAvailable' => false,
@ -156,6 +217,7 @@ class AdminControllerTest extends TestCase {
'currentChannel' => \OCP\Util::getChannel(), 'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels, 'channels' => $channels,
'newVersionString' => '', 'newVersionString' => '',
'updaterRequirementsFulfilled' => true,
]; ];
$expected = new TemplateResponse('updatenotification', 'admin', $params, ''); $expected = new TemplateResponse('updatenotification', 'admin', $params, '');