server/apps/updatenotification/lib/updatechecker.php
Lukas Reschke abc675d87e Move update notification code into app
Moves the update notification code in a single app. This is required since we want to use SSO for the new updater and for this have some code running in ownCloud as well (and we don't want that in core neccessarily). This app can provide that in the future, right now it's only the update notification itself. Will continue working on the SSO right away but wanted to keep the PR small.

Furthermore also makes some more code unit-testable...
2016-02-09 18:05:51 +01:00

67 lines
1.7 KiB
PHP

<?php
/**
* @author Lukas Reschke <lukas@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\UpdateNotification;
use OC\Updater;
class UpdateChecker {
/** @var Updater */
private $updater;
/**
* @param Updater $updater
*/
public function __construct(Updater $updater) {
$this->updater = $updater;
}
/**
* @return array
*/
public function getUpdateState() {
$data = $this->updater->check();
$result = [];
if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
$result['updateAvailable'] = true;
$result['updateVersion'] = $data['versionstring'];
if(substr($data['web'], 0, 8) === 'https://') {
$result['updateLink'] = $data['web'];
}
return $result;
}
return [];
}
/**
* @param array $data
*/
public function getJavaScript(array $data) {
$data['array']['oc_updateState'] = json_encode([
'updateAvailable' => true,
'updateVersion' => $this->getUpdateState()['updateVersion'],
'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '',
]);
}
}