@@ -1,25 +1,25 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | declare(strict_types=1); |
| 3 | - script('updatenotification', 'admin'); |
|
| 4 | - style('updatenotification', 'admin'); |
|
| 3 | + script('updatenotification', 'admin'); |
|
| 4 | + style('updatenotification', 'admin'); |
|
| 5 | 5 | |
| 6 | - /** @var array $_ */ |
|
| 7 | - /** @var bool $isNewVersionAvailable */ |
|
| 8 | - $isNewVersionAvailable = $_['isNewVersionAvailable']; |
|
| 9 | - /** @var string $newVersionString */ |
|
| 10 | - $newVersionString = $_['newVersionString']; |
|
| 11 | - /** @var bool $isUpdateChecked */ |
|
| 12 | - $isUpdateChecked = $_['isUpdateChecked']; |
|
| 13 | - /** @var string $lastCheckedDate */ |
|
| 14 | - $lastCheckedDate = $_['lastChecked']; |
|
| 15 | - /** @var array $channels */ |
|
| 16 | - $channels = $_['channels']; |
|
| 17 | - /** @var string $currentChannel */ |
|
| 18 | - $currentChannel = $_['currentChannel']; |
|
| 19 | - /** @var string $updateServerURL */ |
|
| 20 | - $updateServerURL = $_['updateServerURL']; |
|
| 21 | - /** @var bool $isDefaultUpdateServerURL */ |
|
| 22 | - $isDefaultUpdateServerURL = $_['isDefaultUpdateServerURL']; |
|
| 6 | + /** @var array $_ */ |
|
| 7 | + /** @var bool $isNewVersionAvailable */ |
|
| 8 | + $isNewVersionAvailable = $_['isNewVersionAvailable']; |
|
| 9 | + /** @var string $newVersionString */ |
|
| 10 | + $newVersionString = $_['newVersionString']; |
|
| 11 | + /** @var bool $isUpdateChecked */ |
|
| 12 | + $isUpdateChecked = $_['isUpdateChecked']; |
|
| 13 | + /** @var string $lastCheckedDate */ |
|
| 14 | + $lastCheckedDate = $_['lastChecked']; |
|
| 15 | + /** @var array $channels */ |
|
| 16 | + $channels = $_['channels']; |
|
| 17 | + /** @var string $currentChannel */ |
|
| 18 | + $currentChannel = $_['currentChannel']; |
|
| 19 | + /** @var string $updateServerURL */ |
|
| 20 | + $updateServerURL = $_['updateServerURL']; |
|
| 21 | + /** @var bool $isDefaultUpdateServerURL */ |
|
| 22 | + $isDefaultUpdateServerURL = $_['isDefaultUpdateServerURL']; |
|
| 23 | 23 | ?> |
| 24 | 24 | <form id="oca_updatenotification_section" class="followupsection"> |
| 25 | 25 | <p> |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | script('updatenotification', 'admin'); |
| 4 | 4 | style('updatenotification', 'admin'); |
| 5 | 5 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | <label for="release-channel"><?php p($l->t('Update channel:')) ?></label> |
| 52 | 52 | <select id="release-channel"> |
| 53 | 53 | <option value="<?php p($currentChannel); ?>"><?php p($currentChannel); ?></option> |
| 54 | - <?php foreach ($channels as $channel => $channelTitle){ ?> |
|
| 54 | + <?php foreach ($channels as $channel => $channelTitle) { ?> |
|
| 55 | 55 | <option value="<?php p($channelTitle) ?>"> |
| 56 | 56 | <?php p($channelTitle) ?> |
| 57 | 57 | </option> |
@@ -37,241 +37,241 @@ |
||
| 37 | 37 | |
| 38 | 38 | class BackgroundJob extends TimedJob { |
| 39 | 39 | |
| 40 | - protected $connectionNotifications = [3, 7, 14, 30]; |
|
| 41 | - |
|
| 42 | - /** @var IConfig */ |
|
| 43 | - protected $config; |
|
| 44 | - |
|
| 45 | - /** @var IManager */ |
|
| 46 | - protected $notificationManager; |
|
| 47 | - |
|
| 48 | - /** @var IGroupManager */ |
|
| 49 | - protected $groupManager; |
|
| 50 | - |
|
| 51 | - /** @var IAppManager */ |
|
| 52 | - protected $appManager; |
|
| 53 | - |
|
| 54 | - /** @var IClientService */ |
|
| 55 | - protected $client; |
|
| 56 | - |
|
| 57 | - /** @var Installer */ |
|
| 58 | - protected $installer; |
|
| 59 | - |
|
| 60 | - /** @var string[] */ |
|
| 61 | - protected $users; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * NotificationBackgroundJob constructor. |
|
| 65 | - * |
|
| 66 | - * @param IConfig $config |
|
| 67 | - * @param IManager $notificationManager |
|
| 68 | - * @param IGroupManager $groupManager |
|
| 69 | - * @param IAppManager $appManager |
|
| 70 | - * @param IClientService $client |
|
| 71 | - * @param Installer $installer |
|
| 72 | - */ |
|
| 73 | - public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) { |
|
| 74 | - // Run once a day |
|
| 75 | - $this->setInterval(60 * 60 * 24); |
|
| 76 | - |
|
| 77 | - $this->config = $config; |
|
| 78 | - $this->notificationManager = $notificationManager; |
|
| 79 | - $this->groupManager = $groupManager; |
|
| 80 | - $this->appManager = $appManager; |
|
| 81 | - $this->client = $client; |
|
| 82 | - $this->installer = $installer; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - protected function run($argument) { |
|
| 86 | - $this->checkCoreUpdate(); |
|
| 87 | - $this->checkAppUpdates(); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Check for ownCloud update |
|
| 92 | - */ |
|
| 93 | - protected function checkCoreUpdate() { |
|
| 94 | - if (\in_array($this->getChannel(), ['daily', 'git'], true)) { |
|
| 95 | - // "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $updater = $this->createVersionCheck(); |
|
| 100 | - |
|
| 101 | - $status = $updater->check(); |
|
| 102 | - if ($status === false) { |
|
| 103 | - $errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
| 104 | - $this->config->setAppValue('updatenotification', 'update_check_errors', $errors); |
|
| 105 | - |
|
| 106 | - if (\in_array($errors, $this->connectionNotifications, true)) { |
|
| 107 | - $this->sendErrorNotifications($errors); |
|
| 108 | - } |
|
| 109 | - } else if (\is_array($status)) { |
|
| 110 | - $this->config->setAppValue('updatenotification', 'update_check_errors', 0); |
|
| 111 | - $this->clearErrorNotifications(); |
|
| 112 | - |
|
| 113 | - if (isset($status['version'])) { |
|
| 114 | - $this->createNotifications('core', $status['version'], $status['versionstring']); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Send a message to the admin when the update server could not be reached |
|
| 121 | - * @param int $numDays |
|
| 122 | - */ |
|
| 123 | - protected function sendErrorNotifications($numDays) { |
|
| 124 | - $this->clearErrorNotifications(); |
|
| 125 | - |
|
| 126 | - $notification = $this->notificationManager->createNotification(); |
|
| 127 | - try { |
|
| 128 | - $notification->setApp('updatenotification') |
|
| 129 | - ->setDateTime(new \DateTime()) |
|
| 130 | - ->setObject('updatenotification', 'error') |
|
| 131 | - ->setSubject('connection_error', ['days' => $numDays]); |
|
| 132 | - |
|
| 133 | - foreach ($this->getUsersToNotify() as $uid) { |
|
| 134 | - $notification->setUser($uid); |
|
| 135 | - $this->notificationManager->notify($notification); |
|
| 136 | - } |
|
| 137 | - } catch (\InvalidArgumentException $e) { |
|
| 138 | - return; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Remove error notifications again |
|
| 144 | - */ |
|
| 145 | - protected function clearErrorNotifications() { |
|
| 146 | - $notification = $this->notificationManager->createNotification(); |
|
| 147 | - try { |
|
| 148 | - $notification->setApp('updatenotification') |
|
| 149 | - ->setSubject('connection_error') |
|
| 150 | - ->setObject('updatenotification', 'error'); |
|
| 151 | - } catch (\InvalidArgumentException $e) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - $this->notificationManager->markProcessed($notification); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Check all installed apps for updates |
|
| 159 | - */ |
|
| 160 | - protected function checkAppUpdates() { |
|
| 161 | - $apps = $this->appManager->getInstalledApps(); |
|
| 162 | - foreach ($apps as $app) { |
|
| 163 | - $update = $this->isUpdateAvailable($app); |
|
| 164 | - if ($update !== false) { |
|
| 165 | - $this->createNotifications($app, $update); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Create notifications for this app version |
|
| 172 | - * |
|
| 173 | - * @param string $app |
|
| 174 | - * @param string $version |
|
| 175 | - * @param string $visibleVersion |
|
| 176 | - */ |
|
| 177 | - protected function createNotifications($app, $version, $visibleVersion = '') { |
|
| 178 | - $lastNotification = $this->config->getAppValue('updatenotification', $app, false); |
|
| 179 | - if ($lastNotification === $version) { |
|
| 180 | - // We already notified about this update |
|
| 181 | - return; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($lastNotification !== false) { |
|
| 185 | - // Delete old updates |
|
| 186 | - $this->deleteOutdatedNotifications($app, $lastNotification); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $notification = $this->notificationManager->createNotification(); |
|
| 190 | - try { |
|
| 191 | - $notification->setApp('updatenotification') |
|
| 192 | - ->setDateTime(new \DateTime()) |
|
| 193 | - ->setObject($app, $version); |
|
| 194 | - |
|
| 195 | - if ($visibleVersion !== '') { |
|
| 196 | - $notification->setSubject('update_available', ['version' => $visibleVersion]); |
|
| 197 | - } else { |
|
| 198 | - $notification->setSubject('update_available'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - foreach ($this->getUsersToNotify() as $uid) { |
|
| 202 | - $notification->setUser($uid); |
|
| 203 | - $this->notificationManager->notify($notification); |
|
| 204 | - } |
|
| 205 | - } catch (\InvalidArgumentException $e) { |
|
| 206 | - return; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $this->config->setAppValue('updatenotification', $app, $version); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @return string[] |
|
| 214 | - */ |
|
| 215 | - protected function getUsersToNotify(): array { |
|
| 216 | - if ($this->users !== null) { |
|
| 217 | - return $this->users; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $notifyGroups = (array) json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
| 221 | - $this->users = []; |
|
| 222 | - foreach ($notifyGroups as $group) { |
|
| 223 | - $groupToNotify = $this->groupManager->get($group); |
|
| 224 | - if ($groupToNotify instanceof IGroup) { |
|
| 225 | - foreach ($groupToNotify->getUsers() as $user) { |
|
| 226 | - $this->users[$user->getUID()] = true; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $this->users = array_keys($this->users); |
|
| 232 | - |
|
| 233 | - return $this->users; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Delete notifications for old updates |
|
| 238 | - * |
|
| 239 | - * @param string $app |
|
| 240 | - * @param string $version |
|
| 241 | - */ |
|
| 242 | - protected function deleteOutdatedNotifications($app, $version) { |
|
| 243 | - $notification = $this->notificationManager->createNotification(); |
|
| 244 | - try { |
|
| 245 | - $notification->setApp('updatenotification') |
|
| 246 | - ->setObject($app, $version); |
|
| 247 | - } catch (\InvalidArgumentException $e) { |
|
| 248 | - return; |
|
| 249 | - } |
|
| 250 | - $this->notificationManager->markProcessed($notification); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @return VersionCheck |
|
| 255 | - */ |
|
| 256 | - protected function createVersionCheck(): VersionCheck { |
|
| 257 | - return new VersionCheck( |
|
| 258 | - $this->client, |
|
| 259 | - $this->config |
|
| 260 | - ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @return string |
|
| 265 | - */ |
|
| 266 | - protected function getChannel(): string { |
|
| 267 | - return \OC_Util::getChannel(); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @param string $app |
|
| 272 | - * @return string|false |
|
| 273 | - */ |
|
| 274 | - protected function isUpdateAvailable($app) { |
|
| 275 | - return $this->installer->isUpdateAvailable($app); |
|
| 276 | - } |
|
| 40 | + protected $connectionNotifications = [3, 7, 14, 30]; |
|
| 41 | + |
|
| 42 | + /** @var IConfig */ |
|
| 43 | + protected $config; |
|
| 44 | + |
|
| 45 | + /** @var IManager */ |
|
| 46 | + protected $notificationManager; |
|
| 47 | + |
|
| 48 | + /** @var IGroupManager */ |
|
| 49 | + protected $groupManager; |
|
| 50 | + |
|
| 51 | + /** @var IAppManager */ |
|
| 52 | + protected $appManager; |
|
| 53 | + |
|
| 54 | + /** @var IClientService */ |
|
| 55 | + protected $client; |
|
| 56 | + |
|
| 57 | + /** @var Installer */ |
|
| 58 | + protected $installer; |
|
| 59 | + |
|
| 60 | + /** @var string[] */ |
|
| 61 | + protected $users; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * NotificationBackgroundJob constructor. |
|
| 65 | + * |
|
| 66 | + * @param IConfig $config |
|
| 67 | + * @param IManager $notificationManager |
|
| 68 | + * @param IGroupManager $groupManager |
|
| 69 | + * @param IAppManager $appManager |
|
| 70 | + * @param IClientService $client |
|
| 71 | + * @param Installer $installer |
|
| 72 | + */ |
|
| 73 | + public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) { |
|
| 74 | + // Run once a day |
|
| 75 | + $this->setInterval(60 * 60 * 24); |
|
| 76 | + |
|
| 77 | + $this->config = $config; |
|
| 78 | + $this->notificationManager = $notificationManager; |
|
| 79 | + $this->groupManager = $groupManager; |
|
| 80 | + $this->appManager = $appManager; |
|
| 81 | + $this->client = $client; |
|
| 82 | + $this->installer = $installer; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + protected function run($argument) { |
|
| 86 | + $this->checkCoreUpdate(); |
|
| 87 | + $this->checkAppUpdates(); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Check for ownCloud update |
|
| 92 | + */ |
|
| 93 | + protected function checkCoreUpdate() { |
|
| 94 | + if (\in_array($this->getChannel(), ['daily', 'git'], true)) { |
|
| 95 | + // "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $updater = $this->createVersionCheck(); |
|
| 100 | + |
|
| 101 | + $status = $updater->check(); |
|
| 102 | + if ($status === false) { |
|
| 103 | + $errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
| 104 | + $this->config->setAppValue('updatenotification', 'update_check_errors', $errors); |
|
| 105 | + |
|
| 106 | + if (\in_array($errors, $this->connectionNotifications, true)) { |
|
| 107 | + $this->sendErrorNotifications($errors); |
|
| 108 | + } |
|
| 109 | + } else if (\is_array($status)) { |
|
| 110 | + $this->config->setAppValue('updatenotification', 'update_check_errors', 0); |
|
| 111 | + $this->clearErrorNotifications(); |
|
| 112 | + |
|
| 113 | + if (isset($status['version'])) { |
|
| 114 | + $this->createNotifications('core', $status['version'], $status['versionstring']); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Send a message to the admin when the update server could not be reached |
|
| 121 | + * @param int $numDays |
|
| 122 | + */ |
|
| 123 | + protected function sendErrorNotifications($numDays) { |
|
| 124 | + $this->clearErrorNotifications(); |
|
| 125 | + |
|
| 126 | + $notification = $this->notificationManager->createNotification(); |
|
| 127 | + try { |
|
| 128 | + $notification->setApp('updatenotification') |
|
| 129 | + ->setDateTime(new \DateTime()) |
|
| 130 | + ->setObject('updatenotification', 'error') |
|
| 131 | + ->setSubject('connection_error', ['days' => $numDays]); |
|
| 132 | + |
|
| 133 | + foreach ($this->getUsersToNotify() as $uid) { |
|
| 134 | + $notification->setUser($uid); |
|
| 135 | + $this->notificationManager->notify($notification); |
|
| 136 | + } |
|
| 137 | + } catch (\InvalidArgumentException $e) { |
|
| 138 | + return; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Remove error notifications again |
|
| 144 | + */ |
|
| 145 | + protected function clearErrorNotifications() { |
|
| 146 | + $notification = $this->notificationManager->createNotification(); |
|
| 147 | + try { |
|
| 148 | + $notification->setApp('updatenotification') |
|
| 149 | + ->setSubject('connection_error') |
|
| 150 | + ->setObject('updatenotification', 'error'); |
|
| 151 | + } catch (\InvalidArgumentException $e) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + $this->notificationManager->markProcessed($notification); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Check all installed apps for updates |
|
| 159 | + */ |
|
| 160 | + protected function checkAppUpdates() { |
|
| 161 | + $apps = $this->appManager->getInstalledApps(); |
|
| 162 | + foreach ($apps as $app) { |
|
| 163 | + $update = $this->isUpdateAvailable($app); |
|
| 164 | + if ($update !== false) { |
|
| 165 | + $this->createNotifications($app, $update); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Create notifications for this app version |
|
| 172 | + * |
|
| 173 | + * @param string $app |
|
| 174 | + * @param string $version |
|
| 175 | + * @param string $visibleVersion |
|
| 176 | + */ |
|
| 177 | + protected function createNotifications($app, $version, $visibleVersion = '') { |
|
| 178 | + $lastNotification = $this->config->getAppValue('updatenotification', $app, false); |
|
| 179 | + if ($lastNotification === $version) { |
|
| 180 | + // We already notified about this update |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($lastNotification !== false) { |
|
| 185 | + // Delete old updates |
|
| 186 | + $this->deleteOutdatedNotifications($app, $lastNotification); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $notification = $this->notificationManager->createNotification(); |
|
| 190 | + try { |
|
| 191 | + $notification->setApp('updatenotification') |
|
| 192 | + ->setDateTime(new \DateTime()) |
|
| 193 | + ->setObject($app, $version); |
|
| 194 | + |
|
| 195 | + if ($visibleVersion !== '') { |
|
| 196 | + $notification->setSubject('update_available', ['version' => $visibleVersion]); |
|
| 197 | + } else { |
|
| 198 | + $notification->setSubject('update_available'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + foreach ($this->getUsersToNotify() as $uid) { |
|
| 202 | + $notification->setUser($uid); |
|
| 203 | + $this->notificationManager->notify($notification); |
|
| 204 | + } |
|
| 205 | + } catch (\InvalidArgumentException $e) { |
|
| 206 | + return; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $this->config->setAppValue('updatenotification', $app, $version); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @return string[] |
|
| 214 | + */ |
|
| 215 | + protected function getUsersToNotify(): array { |
|
| 216 | + if ($this->users !== null) { |
|
| 217 | + return $this->users; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $notifyGroups = (array) json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
| 221 | + $this->users = []; |
|
| 222 | + foreach ($notifyGroups as $group) { |
|
| 223 | + $groupToNotify = $this->groupManager->get($group); |
|
| 224 | + if ($groupToNotify instanceof IGroup) { |
|
| 225 | + foreach ($groupToNotify->getUsers() as $user) { |
|
| 226 | + $this->users[$user->getUID()] = true; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $this->users = array_keys($this->users); |
|
| 232 | + |
|
| 233 | + return $this->users; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Delete notifications for old updates |
|
| 238 | + * |
|
| 239 | + * @param string $app |
|
| 240 | + * @param string $version |
|
| 241 | + */ |
|
| 242 | + protected function deleteOutdatedNotifications($app, $version) { |
|
| 243 | + $notification = $this->notificationManager->createNotification(); |
|
| 244 | + try { |
|
| 245 | + $notification->setApp('updatenotification') |
|
| 246 | + ->setObject($app, $version); |
|
| 247 | + } catch (\InvalidArgumentException $e) { |
|
| 248 | + return; |
|
| 249 | + } |
|
| 250 | + $this->notificationManager->markProcessed($notification); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @return VersionCheck |
|
| 255 | + */ |
|
| 256 | + protected function createVersionCheck(): VersionCheck { |
|
| 257 | + return new VersionCheck( |
|
| 258 | + $this->client, |
|
| 259 | + $this->config |
|
| 260 | + ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * @return string |
|
| 265 | + */ |
|
| 266 | + protected function getChannel(): string { |
|
| 267 | + return \OC_Util::getChannel(); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @param string $app |
|
| 272 | + * @return string|false |
|
| 273 | + */ |
|
| 274 | + protected function isUpdateAvailable($app) { |
|
| 275 | + return $this->installer->isUpdateAvailable($app); |
|
| 276 | + } |
|
| 277 | 277 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -38,141 +38,141 @@ |
||
| 38 | 38 | |
| 39 | 39 | class Notifier implements INotifier { |
| 40 | 40 | |
| 41 | - /** @var IURLGenerator */ |
|
| 42 | - protected $url; |
|
| 43 | - |
|
| 44 | - /** @var IConfig */ |
|
| 45 | - protected $config; |
|
| 46 | - |
|
| 47 | - /** @var IManager */ |
|
| 48 | - protected $notificationManager; |
|
| 49 | - |
|
| 50 | - /** @var IFactory */ |
|
| 51 | - protected $l10NFactory; |
|
| 52 | - |
|
| 53 | - /** @var IUserSession */ |
|
| 54 | - protected $userSession; |
|
| 55 | - |
|
| 56 | - /** @var IGroupManager */ |
|
| 57 | - protected $groupManager; |
|
| 58 | - |
|
| 59 | - /** @var string[] */ |
|
| 60 | - protected $appVersions; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Notifier constructor. |
|
| 64 | - * |
|
| 65 | - * @param IURLGenerator $url |
|
| 66 | - * @param IConfig $config |
|
| 67 | - * @param IManager $notificationManager |
|
| 68 | - * @param IFactory $l10NFactory |
|
| 69 | - * @param IUserSession $userSession |
|
| 70 | - * @param IGroupManager $groupManager |
|
| 71 | - */ |
|
| 72 | - public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { |
|
| 73 | - $this->url = $url; |
|
| 74 | - $this->notificationManager = $notificationManager; |
|
| 75 | - $this->config = $config; |
|
| 76 | - $this->l10NFactory = $l10NFactory; |
|
| 77 | - $this->userSession = $userSession; |
|
| 78 | - $this->groupManager = $groupManager; |
|
| 79 | - $this->appVersions = $this->getAppVersions(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param INotification $notification |
|
| 84 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 85 | - * @return INotification |
|
| 86 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
| 87 | - * @since 9.0.0 |
|
| 88 | - */ |
|
| 89 | - public function prepare(INotification $notification, $languageCode): INotification { |
|
| 90 | - if ($notification->getApp() !== 'updatenotification') { |
|
| 91 | - throw new \InvalidArgumentException('Unknown app id'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $l = $this->l10NFactory->get('updatenotification', $languageCode); |
|
| 95 | - if ($notification->getSubject() === 'connection_error') { |
|
| 96 | - $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
| 97 | - if ($errors === 0) { |
|
| 98 | - $this->notificationManager->markProcessed($notification); |
|
| 99 | - throw new \InvalidArgumentException('Update checked worked again'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |
|
| 103 | - ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.')); |
|
| 104 | - } elseif ($notification->getObjectType() === 'core') { |
|
| 105 | - $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); |
|
| 106 | - |
|
| 107 | - $parameters = $notification->getSubjectParameters(); |
|
| 108 | - $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
|
| 109 | - |
|
| 110 | - if ($this->isAdmin()) { |
|
| 111 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index') . '#updater'); |
|
| 112 | - } |
|
| 113 | - } else { |
|
| 114 | - $appInfo = $this->getAppInfo($notification->getObjectType()); |
|
| 115 | - $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; |
|
| 116 | - |
|
| 117 | - if (isset($this->appVersions[$notification->getObjectType()])) { |
|
| 118 | - $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) |
|
| 122 | - ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [ |
|
| 123 | - 'app' => [ |
|
| 124 | - 'type' => 'app', |
|
| 125 | - 'id' => $notification->getObjectType(), |
|
| 126 | - 'name' => $appName, |
|
| 127 | - ] |
|
| 128 | - ]); |
|
| 129 | - |
|
| 130 | - if ($this->isAdmin()) { |
|
| 131 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); |
|
| 136 | - |
|
| 137 | - return $notification; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Remove the notification and prevent rendering, when the update is installed |
|
| 142 | - * |
|
| 143 | - * @param INotification $notification |
|
| 144 | - * @param string $installedVersion |
|
| 145 | - * @throws \InvalidArgumentException When the update is already installed |
|
| 146 | - */ |
|
| 147 | - protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { |
|
| 148 | - if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { |
|
| 149 | - $this->notificationManager->markProcessed($notification); |
|
| 150 | - throw new \InvalidArgumentException('Update already installed'); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - protected function isAdmin(): bool { |
|
| 158 | - $user = $this->userSession->getUser(); |
|
| 159 | - |
|
| 160 | - if ($user instanceof IUser) { |
|
| 161 | - return $this->groupManager->isAdmin($user->getUID()); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return false; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - protected function getCoreVersions(): string { |
|
| 168 | - return implode('.', Util::getVersion()); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - protected function getAppVersions(): array { |
|
| 172 | - return \OC_App::getAppVersions(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - protected function getAppInfo($appId) { |
|
| 176 | - return \OC_App::getAppInfo($appId); |
|
| 177 | - } |
|
| 41 | + /** @var IURLGenerator */ |
|
| 42 | + protected $url; |
|
| 43 | + |
|
| 44 | + /** @var IConfig */ |
|
| 45 | + protected $config; |
|
| 46 | + |
|
| 47 | + /** @var IManager */ |
|
| 48 | + protected $notificationManager; |
|
| 49 | + |
|
| 50 | + /** @var IFactory */ |
|
| 51 | + protected $l10NFactory; |
|
| 52 | + |
|
| 53 | + /** @var IUserSession */ |
|
| 54 | + protected $userSession; |
|
| 55 | + |
|
| 56 | + /** @var IGroupManager */ |
|
| 57 | + protected $groupManager; |
|
| 58 | + |
|
| 59 | + /** @var string[] */ |
|
| 60 | + protected $appVersions; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Notifier constructor. |
|
| 64 | + * |
|
| 65 | + * @param IURLGenerator $url |
|
| 66 | + * @param IConfig $config |
|
| 67 | + * @param IManager $notificationManager |
|
| 68 | + * @param IFactory $l10NFactory |
|
| 69 | + * @param IUserSession $userSession |
|
| 70 | + * @param IGroupManager $groupManager |
|
| 71 | + */ |
|
| 72 | + public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { |
|
| 73 | + $this->url = $url; |
|
| 74 | + $this->notificationManager = $notificationManager; |
|
| 75 | + $this->config = $config; |
|
| 76 | + $this->l10NFactory = $l10NFactory; |
|
| 77 | + $this->userSession = $userSession; |
|
| 78 | + $this->groupManager = $groupManager; |
|
| 79 | + $this->appVersions = $this->getAppVersions(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param INotification $notification |
|
| 84 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 85 | + * @return INotification |
|
| 86 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
| 87 | + * @since 9.0.0 |
|
| 88 | + */ |
|
| 89 | + public function prepare(INotification $notification, $languageCode): INotification { |
|
| 90 | + if ($notification->getApp() !== 'updatenotification') { |
|
| 91 | + throw new \InvalidArgumentException('Unknown app id'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $l = $this->l10NFactory->get('updatenotification', $languageCode); |
|
| 95 | + if ($notification->getSubject() === 'connection_error') { |
|
| 96 | + $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
| 97 | + if ($errors === 0) { |
|
| 98 | + $this->notificationManager->markProcessed($notification); |
|
| 99 | + throw new \InvalidArgumentException('Update checked worked again'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |
|
| 103 | + ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.')); |
|
| 104 | + } elseif ($notification->getObjectType() === 'core') { |
|
| 105 | + $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); |
|
| 106 | + |
|
| 107 | + $parameters = $notification->getSubjectParameters(); |
|
| 108 | + $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
|
| 109 | + |
|
| 110 | + if ($this->isAdmin()) { |
|
| 111 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index') . '#updater'); |
|
| 112 | + } |
|
| 113 | + } else { |
|
| 114 | + $appInfo = $this->getAppInfo($notification->getObjectType()); |
|
| 115 | + $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; |
|
| 116 | + |
|
| 117 | + if (isset($this->appVersions[$notification->getObjectType()])) { |
|
| 118 | + $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) |
|
| 122 | + ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [ |
|
| 123 | + 'app' => [ |
|
| 124 | + 'type' => 'app', |
|
| 125 | + 'id' => $notification->getObjectType(), |
|
| 126 | + 'name' => $appName, |
|
| 127 | + ] |
|
| 128 | + ]); |
|
| 129 | + |
|
| 130 | + if ($this->isAdmin()) { |
|
| 131 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); |
|
| 136 | + |
|
| 137 | + return $notification; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Remove the notification and prevent rendering, when the update is installed |
|
| 142 | + * |
|
| 143 | + * @param INotification $notification |
|
| 144 | + * @param string $installedVersion |
|
| 145 | + * @throws \InvalidArgumentException When the update is already installed |
|
| 146 | + */ |
|
| 147 | + protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { |
|
| 148 | + if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { |
|
| 149 | + $this->notificationManager->markProcessed($notification); |
|
| 150 | + throw new \InvalidArgumentException('Update already installed'); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + protected function isAdmin(): bool { |
|
| 158 | + $user = $this->userSession->getUser(); |
|
| 159 | + |
|
| 160 | + if ($user instanceof IUser) { |
|
| 161 | + return $this->groupManager->isAdmin($user->getUID()); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + protected function getCoreVersions(): string { |
|
| 168 | + return implode('.', Util::getVersion()); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + protected function getAppVersions(): array { |
|
| 172 | + return \OC_App::getAppVersions(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + protected function getAppInfo($appId) { |
|
| 176 | + return \OC_App::getAppInfo($appId); |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
| 109 | 109 | |
| 110 | 110 | if ($this->isAdmin()) { |
| 111 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index') . '#updater'); |
|
| 111 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index').'#updater'); |
|
| 112 | 112 | } |
| 113 | 113 | } else { |
| 114 | 114 | $appInfo = $this->getAppInfo($notification->getObjectType()); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | ]); |
| 129 | 129 | |
| 130 | 130 | if ($this->isAdmin()) { |
| 131 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
| 131 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']).'#app-'.$notification->getObjectType()); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2018, Joas Schilling <[email protected]> |
| 5 | 5 | * |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | protected function run($argument) { |
| 58 | 58 | // Delete old tokens after 2 days |
| 59 | - if($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) { |
|
| 59 | + if ($this->timeFactory->getTime() - $this->config->getAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()) >= 172800) { |
|
| 60 | 60 | $this->config->deleteSystemValue('updater.secret'); |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -38,63 +38,63 @@ |
||
| 38 | 38 | use OCP\Util; |
| 39 | 39 | |
| 40 | 40 | class AdminController extends Controller { |
| 41 | - /** @var IJobList */ |
|
| 42 | - private $jobList; |
|
| 43 | - /** @var ISecureRandom */ |
|
| 44 | - private $secureRandom; |
|
| 45 | - /** @var IConfig */ |
|
| 46 | - private $config; |
|
| 47 | - /** @var ITimeFactory */ |
|
| 48 | - private $timeFactory; |
|
| 49 | - /** @var IL10N */ |
|
| 50 | - private $l10n; |
|
| 41 | + /** @var IJobList */ |
|
| 42 | + private $jobList; |
|
| 43 | + /** @var ISecureRandom */ |
|
| 44 | + private $secureRandom; |
|
| 45 | + /** @var IConfig */ |
|
| 46 | + private $config; |
|
| 47 | + /** @var ITimeFactory */ |
|
| 48 | + private $timeFactory; |
|
| 49 | + /** @var IL10N */ |
|
| 50 | + private $l10n; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param string $appName |
|
| 54 | - * @param IRequest $request |
|
| 55 | - * @param IJobList $jobList |
|
| 56 | - * @param ISecureRandom $secureRandom |
|
| 57 | - * @param IConfig $config |
|
| 58 | - * @param ITimeFactory $timeFactory |
|
| 59 | - * @param IL10N $l10n |
|
| 60 | - */ |
|
| 61 | - public function __construct($appName, |
|
| 62 | - IRequest $request, |
|
| 63 | - IJobList $jobList, |
|
| 64 | - ISecureRandom $secureRandom, |
|
| 65 | - IConfig $config, |
|
| 66 | - ITimeFactory $timeFactory, |
|
| 67 | - IL10N $l10n) { |
|
| 68 | - parent::__construct($appName, $request); |
|
| 69 | - $this->jobList = $jobList; |
|
| 70 | - $this->secureRandom = $secureRandom; |
|
| 71 | - $this->config = $config; |
|
| 72 | - $this->timeFactory = $timeFactory; |
|
| 73 | - $this->l10n = $l10n; |
|
| 74 | - } |
|
| 52 | + /** |
|
| 53 | + * @param string $appName |
|
| 54 | + * @param IRequest $request |
|
| 55 | + * @param IJobList $jobList |
|
| 56 | + * @param ISecureRandom $secureRandom |
|
| 57 | + * @param IConfig $config |
|
| 58 | + * @param ITimeFactory $timeFactory |
|
| 59 | + * @param IL10N $l10n |
|
| 60 | + */ |
|
| 61 | + public function __construct($appName, |
|
| 62 | + IRequest $request, |
|
| 63 | + IJobList $jobList, |
|
| 64 | + ISecureRandom $secureRandom, |
|
| 65 | + IConfig $config, |
|
| 66 | + ITimeFactory $timeFactory, |
|
| 67 | + IL10N $l10n) { |
|
| 68 | + parent::__construct($appName, $request); |
|
| 69 | + $this->jobList = $jobList; |
|
| 70 | + $this->secureRandom = $secureRandom; |
|
| 71 | + $this->config = $config; |
|
| 72 | + $this->timeFactory = $timeFactory; |
|
| 73 | + $this->l10n = $l10n; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @param string $channel |
|
| 78 | - * @return DataResponse |
|
| 79 | - */ |
|
| 80 | - public function setChannel(string $channel): DataResponse { |
|
| 81 | - Util::setChannel($channel); |
|
| 82 | - $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 83 | - return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
| 84 | - } |
|
| 76 | + /** |
|
| 77 | + * @param string $channel |
|
| 78 | + * @return DataResponse |
|
| 79 | + */ |
|
| 80 | + public function setChannel(string $channel): DataResponse { |
|
| 81 | + Util::setChannel($channel); |
|
| 82 | + $this->config->setAppValue('core', 'lastupdatedat', 0); |
|
| 83 | + return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @return DataResponse |
|
| 88 | - */ |
|
| 89 | - public function createCredentials(): DataResponse { |
|
| 90 | - // Create a new job and store the creation date |
|
| 91 | - $this->jobList->add(ResetTokenBackgroundJob::class); |
|
| 92 | - $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
| 86 | + /** |
|
| 87 | + * @return DataResponse |
|
| 88 | + */ |
|
| 89 | + public function createCredentials(): DataResponse { |
|
| 90 | + // Create a new job and store the creation date |
|
| 91 | + $this->jobList->add(ResetTokenBackgroundJob::class); |
|
| 92 | + $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); |
|
| 93 | 93 | |
| 94 | - // Create a new token |
|
| 95 | - $newToken = $this->secureRandom->generate(64); |
|
| 96 | - $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
| 94 | + // Create a new token |
|
| 95 | + $newToken = $this->secureRandom->generate(64); |
|
| 96 | + $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); |
|
| 97 | 97 | |
| 98 | - return new DataResponse($newToken); |
|
| 99 | - } |
|
| 98 | + return new DataResponse($newToken); |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -34,84 +34,84 @@ |
||
| 34 | 34 | use OCP\Util; |
| 35 | 35 | |
| 36 | 36 | class Admin implements ISettings { |
| 37 | - /** @var IConfig */ |
|
| 38 | - private $config; |
|
| 39 | - /** @var UpdateChecker */ |
|
| 40 | - private $updateChecker; |
|
| 41 | - /** @var IDateTimeFormatter */ |
|
| 42 | - private $dateTimeFormatter; |
|
| 37 | + /** @var IConfig */ |
|
| 38 | + private $config; |
|
| 39 | + /** @var UpdateChecker */ |
|
| 40 | + private $updateChecker; |
|
| 41 | + /** @var IDateTimeFormatter */ |
|
| 42 | + private $dateTimeFormatter; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param IConfig $config |
|
| 46 | - * @param UpdateChecker $updateChecker |
|
| 47 | - * @param IDateTimeFormatter $dateTimeFormatter |
|
| 48 | - */ |
|
| 49 | - public function __construct(IConfig $config, |
|
| 50 | - UpdateChecker $updateChecker, |
|
| 51 | - IDateTimeFormatter $dateTimeFormatter) { |
|
| 52 | - $this->config = $config; |
|
| 53 | - $this->updateChecker = $updateChecker; |
|
| 54 | - $this->dateTimeFormatter = $dateTimeFormatter; |
|
| 55 | - } |
|
| 44 | + /** |
|
| 45 | + * @param IConfig $config |
|
| 46 | + * @param UpdateChecker $updateChecker |
|
| 47 | + * @param IDateTimeFormatter $dateTimeFormatter |
|
| 48 | + */ |
|
| 49 | + public function __construct(IConfig $config, |
|
| 50 | + UpdateChecker $updateChecker, |
|
| 51 | + IDateTimeFormatter $dateTimeFormatter) { |
|
| 52 | + $this->config = $config; |
|
| 53 | + $this->updateChecker = $updateChecker; |
|
| 54 | + $this->dateTimeFormatter = $dateTimeFormatter; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return TemplateResponse |
|
| 59 | - */ |
|
| 60 | - public function getForm(): TemplateResponse { |
|
| 61 | - $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); |
|
| 62 | - $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp); |
|
| 57 | + /** |
|
| 58 | + * @return TemplateResponse |
|
| 59 | + */ |
|
| 60 | + public function getForm(): TemplateResponse { |
|
| 61 | + $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); |
|
| 62 | + $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp); |
|
| 63 | 63 | |
| 64 | - $channels = [ |
|
| 65 | - 'daily', |
|
| 66 | - 'beta', |
|
| 67 | - 'stable', |
|
| 68 | - 'production', |
|
| 69 | - ]; |
|
| 70 | - $currentChannel = Util::getChannel(); |
|
| 64 | + $channels = [ |
|
| 65 | + 'daily', |
|
| 66 | + 'beta', |
|
| 67 | + 'stable', |
|
| 68 | + 'production', |
|
| 69 | + ]; |
|
| 70 | + $currentChannel = Util::getChannel(); |
|
| 71 | 71 | |
| 72 | - // Remove the currently used channel from the channels list |
|
| 73 | - if(($key = array_search($currentChannel, $channels, true)) !== false) { |
|
| 74 | - unset($channels[$key]); |
|
| 75 | - } |
|
| 76 | - $updateState = $this->updateChecker->getUpdateState(); |
|
| 72 | + // Remove the currently used channel from the channels list |
|
| 73 | + if(($key = array_search($currentChannel, $channels, true)) !== false) { |
|
| 74 | + unset($channels[$key]); |
|
| 75 | + } |
|
| 76 | + $updateState = $this->updateChecker->getUpdateState(); |
|
| 77 | 77 | |
| 78 | - $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
| 78 | + $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); |
|
| 79 | 79 | |
| 80 | - $defaultUpdateServerURL = 'https://updates.nextcloud.com/server/'; |
|
| 81 | - $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL); |
|
| 80 | + $defaultUpdateServerURL = 'https://updates.nextcloud.com/server/'; |
|
| 81 | + $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL); |
|
| 82 | 82 | |
| 83 | - $params = [ |
|
| 84 | - 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), |
|
| 85 | - 'isUpdateChecked' => $lastUpdateCheckTimestamp > 0, |
|
| 86 | - 'lastChecked' => $lastUpdateCheck, |
|
| 87 | - 'currentChannel' => $currentChannel, |
|
| 88 | - 'channels' => $channels, |
|
| 89 | - 'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'], |
|
| 90 | - 'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'], |
|
| 91 | - 'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'], |
|
| 92 | - 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL, |
|
| 93 | - 'updateServerURL' => $updateServerURL, |
|
| 94 | - 'notify_groups' => implode('|', $notifyGroups), |
|
| 95 | - ]; |
|
| 83 | + $params = [ |
|
| 84 | + 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), |
|
| 85 | + 'isUpdateChecked' => $lastUpdateCheckTimestamp > 0, |
|
| 86 | + 'lastChecked' => $lastUpdateCheck, |
|
| 87 | + 'currentChannel' => $currentChannel, |
|
| 88 | + 'channels' => $channels, |
|
| 89 | + 'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'], |
|
| 90 | + 'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'], |
|
| 91 | + 'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'], |
|
| 92 | + 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL, |
|
| 93 | + 'updateServerURL' => $updateServerURL, |
|
| 94 | + 'notify_groups' => implode('|', $notifyGroups), |
|
| 95 | + ]; |
|
| 96 | 96 | |
| 97 | - return new TemplateResponse('updatenotification', 'admin', $params, ''); |
|
| 98 | - } |
|
| 97 | + return new TemplateResponse('updatenotification', 'admin', $params, ''); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return string the section ID, e.g. 'sharing' |
|
| 102 | - */ |
|
| 103 | - public function getSection(): string { |
|
| 104 | - return 'server'; |
|
| 105 | - } |
|
| 100 | + /** |
|
| 101 | + * @return string the section ID, e.g. 'sharing' |
|
| 102 | + */ |
|
| 103 | + public function getSection(): string { |
|
| 104 | + return 'server'; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @return int whether the form should be rather on the top or bottom of |
|
| 109 | - * the admin section. The forms are arranged in ascending order of the |
|
| 110 | - * priority values. It is required to return a value between 0 and 100. |
|
| 111 | - * |
|
| 112 | - * E.g.: 70 |
|
| 113 | - */ |
|
| 114 | - public function getPriority(): int { |
|
| 115 | - return 1; |
|
| 116 | - } |
|
| 107 | + /** |
|
| 108 | + * @return int whether the form should be rather on the top or bottom of |
|
| 109 | + * the admin section. The forms are arranged in ascending order of the |
|
| 110 | + * priority values. It is required to return a value between 0 and 100. |
|
| 111 | + * |
|
| 112 | + * E.g.: 70 |
|
| 113 | + */ |
|
| 114 | + public function getPriority(): int { |
|
| 115 | + return 1; |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $currentChannel = Util::getChannel(); |
| 71 | 71 | |
| 72 | 72 | // Remove the currently used channel from the channels list |
| 73 | - if(($key = array_search($currentChannel, $channels, true)) !== false) { |
|
| 73 | + if (($key = array_search($currentChannel, $channels, true)) !== false) { |
|
| 74 | 74 | unset($channels[$key]); |
| 75 | 75 | } |
| 76 | 76 | $updateState = $this->updateChecker->getUpdateState(); |
@@ -28,48 +28,48 @@ |
||
| 28 | 28 | use OC\Updater\VersionCheck; |
| 29 | 29 | |
| 30 | 30 | class UpdateChecker { |
| 31 | - /** @var VersionCheck */ |
|
| 32 | - private $updater; |
|
| 31 | + /** @var VersionCheck */ |
|
| 32 | + private $updater; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param VersionCheck $updater |
|
| 36 | - */ |
|
| 37 | - public function __construct(VersionCheck $updater) { |
|
| 38 | - $this->updater = $updater; |
|
| 39 | - } |
|
| 34 | + /** |
|
| 35 | + * @param VersionCheck $updater |
|
| 36 | + */ |
|
| 37 | + public function __construct(VersionCheck $updater) { |
|
| 38 | + $this->updater = $updater; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return array |
|
| 43 | - */ |
|
| 44 | - public function getUpdateState(): array { |
|
| 45 | - $data = $this->updater->check(); |
|
| 46 | - $result = []; |
|
| 41 | + /** |
|
| 42 | + * @return array |
|
| 43 | + */ |
|
| 44 | + public function getUpdateState(): array { |
|
| 45 | + $data = $this->updater->check(); |
|
| 46 | + $result = []; |
|
| 47 | 47 | |
| 48 | - if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
| 49 | - $result['updateAvailable'] = true; |
|
| 50 | - $result['updateVersion'] = $data['versionstring']; |
|
| 51 | - $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
| 52 | - if (strpos($data['web'], 'https://') === 0) { |
|
| 53 | - $result['updateLink'] = $data['web']; |
|
| 54 | - } |
|
| 55 | - if (strpos($data['url'], 'https://') === 0) { |
|
| 56 | - $result['downloadLink'] = $data['url']; |
|
| 57 | - } |
|
| 48 | + if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
| 49 | + $result['updateAvailable'] = true; |
|
| 50 | + $result['updateVersion'] = $data['versionstring']; |
|
| 51 | + $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
| 52 | + if (strpos($data['web'], 'https://') === 0) { |
|
| 53 | + $result['updateLink'] = $data['web']; |
|
| 54 | + } |
|
| 55 | + if (strpos($data['url'], 'https://') === 0) { |
|
| 56 | + $result['downloadLink'] = $data['url']; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return $result; |
|
| 60 | - } |
|
| 59 | + return $result; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return []; |
|
| 63 | - } |
|
| 62 | + return []; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param array $data |
|
| 67 | - */ |
|
| 68 | - public function populateJavaScriptVariables(array $data) { |
|
| 69 | - $data['array']['oc_updateState'] = json_encode([ |
|
| 70 | - 'updateAvailable' => true, |
|
| 71 | - 'updateVersion' => $this->getUpdateState()['updateVersion'], |
|
| 72 | - 'updateLink' => $this->getUpdateState()['updateLink'] ?? '', |
|
| 73 | - ]); |
|
| 74 | - } |
|
| 65 | + /** |
|
| 66 | + * @param array $data |
|
| 67 | + */ |
|
| 68 | + public function populateJavaScriptVariables(array $data) { |
|
| 69 | + $data['array']['oc_updateState'] = json_encode([ |
|
| 70 | + 'updateAvailable' => true, |
|
| 71 | + 'updateVersion' => $this->getUpdateState()['updateVersion'], |
|
| 72 | + 'updateLink' => $this->getUpdateState()['updateLink'] ?? '', |
|
| 73 | + ]); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @param array $data |
| 67 | 67 | */ |
| 68 | 68 | public function populateJavaScriptVariables(array $data) { |
| 69 | - $data['array']['oc_updateState'] = json_encode([ |
|
| 69 | + $data['array']['oc_updateState'] = json_encode([ |
|
| 70 | 70 | 'updateAvailable' => true, |
| 71 | 71 | 'updateVersion' => $this->getUpdateState()['updateVersion'], |
| 72 | 72 | 'updateLink' => $this->getUpdateState()['updateLink'] ?? '', |