2016-02-09 15:06:48 +03:00
|
|
|
<?php
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
declare(strict_types=1);
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2016-02-09 15:06:48 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-12-16 16:54:15 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2016-02-09 15:06:48 +03: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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-02-09 15:06:48 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\UpdateNotification;
|
|
|
|
|
2018-06-26 18:25:37 +03:00
|
|
|
use OC\Updater\ChangesCheck;
|
2016-04-11 14:19:22 +03:00
|
|
|
use OC\Updater\VersionCheck;
|
2016-02-09 15:06:48 +03:00
|
|
|
|
|
|
|
class UpdateChecker {
|
2016-04-11 14:19:22 +03:00
|
|
|
/** @var VersionCheck */
|
2016-02-09 15:06:48 +03:00
|
|
|
private $updater;
|
2018-06-26 18:25:37 +03:00
|
|
|
/** @var ChangesCheck */
|
|
|
|
private $changesCheck;
|
2016-02-09 15:06:48 +03:00
|
|
|
|
|
|
|
/**
|
2016-04-11 14:19:22 +03:00
|
|
|
* @param VersionCheck $updater
|
2016-02-09 15:06:48 +03:00
|
|
|
*/
|
2018-06-26 18:25:37 +03:00
|
|
|
public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) {
|
2016-02-09 15:06:48 +03:00
|
|
|
$this->updater = $updater;
|
2018-06-26 18:25:37 +03:00
|
|
|
$this->changesCheck = $changesCheck;
|
2016-02-09 15:06:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
public function getUpdateState(): array {
|
2016-02-09 15:06:48 +03:00
|
|
|
$data = $this->updater->check();
|
|
|
|
$result = [];
|
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) {
|
2016-02-09 15:06:48 +03:00
|
|
|
$result['updateAvailable'] = true;
|
2018-11-08 16:50:12 +03:00
|
|
|
$result['updateVersion'] = $data['version'];
|
|
|
|
$result['updateVersionString'] = $data['versionstring'];
|
2016-09-27 15:47:59 +03:00
|
|
|
$result['updaterEnabled'] = $data['autoupdater'] === '1';
|
2018-03-14 16:21:49 +03:00
|
|
|
$result['versionIsEol'] = $data['eol'] === '1';
|
2018-01-17 15:42:02 +03:00
|
|
|
if (strpos($data['web'], 'https://') === 0) {
|
2016-02-09 15:06:48 +03:00
|
|
|
$result['updateLink'] = $data['web'];
|
|
|
|
}
|
2018-01-17 15:42:02 +03:00
|
|
|
if (strpos($data['url'], 'https://') === 0) {
|
2016-09-27 15:47:59 +03:00
|
|
|
$result['downloadLink'] = $data['url'];
|
|
|
|
}
|
2018-06-26 18:25:37 +03: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 16:53:08 +03:00
|
|
|
}
|
2016-02-09 15:06:48 +03:00
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
2018-01-11 13:58:43 +03:00
|
|
|
public function populateJavaScriptVariables(array $data) {
|
2020-10-05 16:12:57 +03:00
|
|
|
$data['array']['oc_updateState'] = json_encode([
|
2016-02-09 15:06:48 +03:00
|
|
|
'updateAvailable' => true,
|
2018-11-08 16:50:12 +03:00
|
|
|
'updateVersion' => $this->getUpdateState()['updateVersionString'],
|
2018-01-17 15:42:02 +03:00
|
|
|
'updateLink' => $this->getUpdateState()['updateLink'] ?? '',
|
2016-02-09 15:06:48 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|