Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions apps/updatenotification/controller/admincontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,6 @@ public function __construct($appName,
$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
*/
Expand All @@ -121,6 +94,7 @@ public function displayPanel() {
'production',
];
$currentChannel = \OCP\Util::getChannel();

// Remove the currently used channel from the channels list
if(($key = array_search($currentChannel, $channels)) !== false) {
unset($channels[$key]);
Expand All @@ -132,7 +106,6 @@ public function displayPanel() {
'currentChannel' => $currentChannel,
'channels' => $channels,
'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'],
'updaterRequirementsFulfilled' => $this->isCompatibleWithUpdater(),
];

return new TemplateResponse($this->appName, 'admin', $params, '');
Expand Down
8 changes: 1 addition & 7 deletions apps/updatenotification/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@
$channels = $_['channels'];
/** @var string $currentChannel */
$currentChannel = $_['currentChannel'];
/** @var bool $updaterRequirementsFulfilled */
$updaterRequirementsFulfilled = $_['updaterRequirementsFulfilled'];
?>
<form id="oca_updatenotification_section" class="section">
<h2><?php p($l->t('Updater')); ?></h2>

<?php if($isNewVersionAvailable === true): ?>
<strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong>
<?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; ?>
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
<?php else: ?>
<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>
Expand Down
84 changes: 11 additions & 73 deletions apps/updatenotification/tests/controller/AdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,17 @@ public function setUp() {
->disableOriginalConstructor()->getMock();
$this->dateTimeFormatter = $this->getMock('\\OCP\\IDateTimeFormatter');

$this->adminController = $this->getMockBuilder('\OCA\UpdateNotification\Controller\AdminController')
->setConstructorArgs(
[
'updatenotification',
$this->request,
$this->jobList,
$this->secureRandom,
$this->config,
$this->timeFactory,
$this->l10n,
$this->updateChecker,
$this->dateTimeFormatter,
]
)
->setMethods(['isCompatibleWithUpdater'])
->getMock()
;
$this->adminController = new AdminController(
'updatenotification',
$this->request,
$this->jobList,
$this->secureRandom,
$this->config,
$this->timeFactory,
$this->l10n,
$this->updateChecker,
$this->dateTimeFormatter
);
}

public function testDisplayPanelWithUpdate() {
Expand Down Expand Up @@ -114,64 +108,13 @@ public function testDisplayPanelWithUpdate() {
->expects($this->once())
->method('getUpdateState')
->willReturn(['updateVersion' => '8.1.2']);
$this->adminController
->expects($this->once())
->method('isCompatibleWithUpdater')
->willReturn(true);

$params = [
'isNewVersionAvailable' => true,
'lastChecked' => 'LastCheckedReturnValue',
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'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, '');
Expand Down Expand Up @@ -206,18 +149,13 @@ public function testDisplayPanelWithoutUpdate() {
->expects($this->once())
->method('getUpdateState')
->willReturn([]);
$this->adminController
->expects($this->once())
->method('isCompatibleWithUpdater')
->willReturn(true);

$params = [
'isNewVersionAvailable' => false,
'lastChecked' => 'LastCheckedReturnValue',
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'newVersionString' => '',
'updaterRequirementsFulfilled' => true,
];

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