2016-02-09 12:06:48 +00:00
|
|
|
<?php
|
2018-01-17 12:42:02 +00:00
|
|
|
declare(strict_types=1);
|
2016-02-09 12:06:48 +00:00
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2016-02-09 12:06:48 +00:00
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
|
2018-06-26 15:25:37 +00:00
|
|
|
use OC\Updater\ChangesCheck;
|
2016-04-11 11:19:22 +00:00
|
|
|
use OC\Updater\VersionCheck;
|
2016-02-09 12:06:48 +00:00
|
|
|
|
|
|
|
class UpdateChecker {
|
2016-04-11 11:19:22 +00:00
|
|
|
/** @var VersionCheck */
|
2016-02-09 12:06:48 +00:00
|
|
|
private $updater;
|
2018-06-26 15:25:37 +00:00
|
|
|
/** @var ChangesCheck */
|
|
|
|
private $changesCheck;
|
2016-02-09 12:06:48 +00:00
|
|
|
|
|
|
|
/**
|
2016-04-11 11:19:22 +00:00
|
|
|
* @param VersionCheck $updater
|
2016-02-09 12:06:48 +00:00
|
|
|
*/
|
2018-06-26 15:25:37 +00:00
|
|
|
public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
|
2016-02-09 12:06:48 +00:00
|
|
|
$this->updater = $updater;
|
2018-06-26 15:25:37 +00:00
|
|
|
$this->changesCheck = $changesCheck;
|
2016-02-09 12:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-01-17 12:42:02 +00:00
|
|
|
public function getUpdateState(): array {
|
2016-02-09 12:06:48 +00:00
|
|
|
$data = $this->updater->check();
|
|
|
|
$result = [];
|
|
|
|
|
2018-01-17 12:42:02 +00:00
|
|
|
if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
|
2016-02-09 12:06:48 +00:00
|
|
|
$result['updateAvailable'] = true;
|
2018-11-08 13:50:12 +00:00
|
|
|
$result['updateVersion'] = $data['version'];
|
|
|
|
$result['updateVersionString'] = $data['versionstring'];
|
2016-09-27 12:47:59 +00:00
|
|
|
$result['updaterEnabled'] = $data['autoupdater'] === '1';
|
2018-03-14 13:21:49 +00:00
|
|
|
$result['versionIsEol'] = $data['eol'] === '1';
|
2018-01-17 12:42:02 +00:00
|
|
|
if (strpos($data['web'], 'https://') === 0) {
|
2016-02-09 12:06:48 +00:00
|
|
|
$result['updateLink'] = $data['web'];
|
|
|
|
}
|
2018-01-17 12:42:02 +00:00
|
|
|
if (strpos($data['url'], 'https://') === 0) {
|
2016-09-27 12:47:59 +00:00
|
|
|
$result['downloadLink'] = $data['url'];
|
|
|
|
}
|
2018-06-26 15:25:37 +00:00
|
|
|
if (strpos($data['changes'], 'https://') === 0) {
|
|
|
|
try {
|
|
|
|
$result['changes'] = $this->changesCheck->check($data['changes'], $data['version']);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
// no info, not a problem
|
|
|
|
}
|
2018-05-30 13:53:08 +00:00
|
|
|
}
|
2016-02-09 12:06:48 +00:00
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
2018-01-11 10:58:43 +00:00
|
|
|
public function populateJavaScriptVariables(array $data) {
|
2016-02-09 12:06:48 +00:00
|
|
|
$data['array']['oc_updateState'] = json_encode([
|
|
|
|
'updateAvailable' => true,
|
2018-11-08 13:50:12 +00:00
|
|
|
'updateVersion' => $this->getUpdateState()['updateVersionString'],
|
2018-01-17 12:42:02 +00:00
|
|
|
'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
|
2016-02-09 12:06:48 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|