|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* @author Lukas Reschke <[email protected]> |
|
7
|
|
|
* @author Thomas Müller <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license AGPL-3.0 |
|
10
|
|
|
* |
|
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
13
|
|
|
* as published by the Free Software Foundation. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace OCA\UpdateNotification; |
|
26
|
|
|
|
|
27
|
|
|
use OC\Updater\VersionCheck; |
|
28
|
|
|
|
|
29
|
|
|
class UpdateChecker { |
|
30
|
|
|
/** @var VersionCheck */ |
|
31
|
|
|
private $updater; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param VersionCheck $updater |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(VersionCheck $updater) { |
|
37
|
|
|
$this->updater = $updater; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getUpdateState() { |
|
44
|
|
|
$data = $this->updater->check(); |
|
45
|
|
|
$result = []; |
|
46
|
|
|
|
|
47
|
|
|
if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
48
|
|
|
$result['updateAvailable'] = true; |
|
49
|
|
|
$result['updateVersion'] = $data['versionstring']; |
|
50
|
|
|
$result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
51
|
|
|
if(substr($data['web'], 0, 8) === 'https://') { |
|
52
|
|
|
$result['updateLink'] = $data['web']; |
|
53
|
|
|
} |
|
54
|
|
|
if(substr($data['url'], 0, 8) === 'https://') { |
|
55
|
|
|
$result['downloadLink'] = $data['url']; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $result; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return []; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param array $data |
|
66
|
|
|
*/ |
|
67
|
|
|
public function populateJavaScriptVariables(array $data) { |
|
68
|
|
|
$data['array']['oc_updateState'] = json_encode([ |
|
69
|
|
|
'updateAvailable' => true, |
|
70
|
|
|
'updateVersion' => $this->getUpdateState()['updateVersion'], |
|
71
|
|
|
'updateLink' => isset($this->getUpdateState()['updateLink']) ? $this->getUpdateState()['updateLink'] : '', |
|
72
|
|
|
]); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|