|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @copyright Copyright (c) 2018, Joas Schilling <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @author Joas Schilling <[email protected]> |
|
9
|
|
|
* @author Lukas Reschke <[email protected]> |
|
10
|
|
|
* @author Morris Jobke <[email protected]> |
|
11
|
|
|
* |
|
12
|
|
|
* @license GNU AGPL version 3 or any later version |
|
13
|
|
|
* |
|
14
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
15
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
16
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
17
|
|
|
* License, or (at your option) any later version. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU Affero General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
namespace OCA\UpdateNotification\AppInfo; |
|
30
|
|
|
|
|
31
|
|
|
use OCA\UpdateNotification\Notification\Notifier; |
|
32
|
|
|
use OCA\UpdateNotification\UpdateChecker; |
|
33
|
|
|
use OCP\AppFramework\App; |
|
34
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext; |
|
35
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap; |
|
36
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext; |
|
37
|
|
|
use OCP\AppFramework\QueryException; |
|
38
|
|
|
use OCP\IUser; |
|
39
|
|
|
use OCP\Util; |
|
40
|
|
|
|
|
41
|
|
|
class Application extends App implements IBootstrap { |
|
42
|
|
|
public function __construct() { |
|
43
|
|
|
parent::__construct('updatenotification', []); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function register(IRegistrationContext $context): void { |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function boot(IBootContext $context): void { |
|
50
|
|
|
$server = $context->getServerContainer(); |
|
51
|
|
|
|
|
52
|
|
|
if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) { |
|
53
|
|
|
// Updater check is disabled |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// Always register the notifier, so background jobs (without a user) can send push notifications |
|
58
|
|
|
$notificationsManager = $server->getNotificationManager(); |
|
59
|
|
|
$notificationsManager->registerNotifierService(Notifier::class); |
|
60
|
|
|
|
|
61
|
|
|
$user = $server->getUserSession()->getUser(); |
|
62
|
|
|
if (!$user instanceof IUser) { |
|
63
|
|
|
// Nothing to do for guests |
|
64
|
|
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (!$server->getAppManager()->isEnabledForUser('notifications') && |
|
68
|
|
|
$server->getGroupManager()->isAdmin($user->getUID())) { |
|
69
|
|
|
try { |
|
70
|
|
|
$updateChecker = $server->query(UpdateChecker::class); |
|
71
|
|
|
} catch (QueryException $e) { |
|
72
|
|
|
$server->getLogger()->logException($e); |
|
73
|
|
|
return; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if ($updateChecker->getUpdateState() !== []) { |
|
77
|
|
|
Util::addScript('updatenotification', 'legacy-notification'); |
|
78
|
|
|
\OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|