diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-05-03 10:00:17 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-05-03 10:20:59 +0200 |
commit | 9ad4a898163fc71ec8366378123aec90fd872fbb (patch) | |
tree | 698f08215309095a7837e5f931dc43a50e08e17b /apps/updatenotification/lib | |
parent | adf7e7295ed94a04bd9fcb056b81e664b45b4f07 (diff) | |
download | nextcloud-server-9ad4a898163fc71ec8366378123aec90fd872fbb.tar.gz nextcloud-server-9ad4a898163fc71ec8366378123aec90fd872fbb.zip |
Move comments, systemtags and updatenotifications to PSR-4
Diffstat (limited to 'apps/updatenotification/lib')
-rw-r--r-- | apps/updatenotification/lib/AppInfo/Application.php | 55 | ||||
-rw-r--r-- | apps/updatenotification/lib/Controller/AdminController.php | 140 | ||||
-rw-r--r-- | apps/updatenotification/lib/ResetTokenBackgroundJob.php (renamed from apps/updatenotification/lib/resettokenbackgroundjob.php) | 0 | ||||
-rw-r--r-- | apps/updatenotification/lib/UpdateChecker.php (renamed from apps/updatenotification/lib/updatechecker.php) | 0 |
4 files changed, 195 insertions, 0 deletions
diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php new file mode 100644 index 00000000000..08ff4abf766 --- /dev/null +++ b/apps/updatenotification/lib/AppInfo/Application.php @@ -0,0 +1,55 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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\AppInfo; + +use OC\AppFramework\Utility\TimeFactory; +use OC\Updater; +use OCA\UpdateNotification\Controller\AdminController; +use OCA\UpdateNotification\UpdateChecker; +use OCP\AppFramework\App; +use OCP\AppFramework\IAppContainer; + +class Application extends App { + public function __construct (array $urlParams = array()) { + parent::__construct('updatenotification', $urlParams); + $container = $this->getContainer(); + + $container->registerService('AdminController', function(IAppContainer $c) { + $updater = new \OC\Updater\VersionCheck( + \OC::$server->getHTTPClientService(), + \OC::$server->getConfig() + ); + return new AdminController( + $c->query('AppName'), + $c->query('Request'), + $c->getServer()->getJobList(), + $c->getServer()->getSecureRandom(), + $c->getServer()->getConfig(), + new TimeFactory(), + $c->getServer()->getL10N($c->query('AppName')), + new UpdateChecker($updater), + $c->getServer()->getDateTimeFormatter() + ); + }); + } + +} diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php new file mode 100644 index 00000000000..5dbcc685809 --- /dev/null +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -0,0 +1,140 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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\Controller; + +use OCA\UpdateNotification\UpdateChecker; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\IJobList; +use OCP\IConfig; +use OCP\IDateTimeFormatter; +use OCP\IL10N; +use OCP\IRequest; +use OCP\Security\ISecureRandom; + +class AdminController extends Controller { + /** @var IJobList */ + private $jobList; + /** @var ISecureRandom */ + private $secureRandom; + /** @var IConfig */ + private $config; + /** @var ITimeFactory */ + private $timeFactory; + /** @var UpdateChecker */ + private $updateChecker; + /** @var IL10N */ + private $l10n; + /** @var IDateTimeFormatter */ + private $dateTimeFormatter; + + /** + * @param string $appName + * @param IRequest $request + * @param IJobList $jobList + * @param ISecureRandom $secureRandom + * @param IConfig $config + * @param ITimeFactory $timeFactory + * @param IL10N $l10n + * @param UpdateChecker $updateChecker + * @param IDateTimeFormatter $dateTimeFormatter + */ + public function __construct($appName, + IRequest $request, + IJobList $jobList, + ISecureRandom $secureRandom, + IConfig $config, + ITimeFactory $timeFactory, + IL10N $l10n, + UpdateChecker $updateChecker, + IDateTimeFormatter $dateTimeFormatter) { + parent::__construct($appName, $request); + $this->jobList = $jobList; + $this->secureRandom = $secureRandom; + $this->config = $config; + $this->timeFactory = $timeFactory; + $this->l10n = $l10n; + $this->updateChecker = $updateChecker; + $this->dateTimeFormatter = $dateTimeFormatter; + } + + /** + * @return TemplateResponse + */ + public function displayPanel() { + $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime( + $this->config->getAppValue('core', 'lastupdatedat') + ); + + $channels = [ + 'daily', + 'beta', + 'stable', + 'production', + ]; + $currentChannel = \OCP\Util::getChannel(); + + // Remove the currently used channel from the channels list + if(($key = array_search($currentChannel, $channels)) !== false) { + unset($channels[$key]); + } + $updateState = $this->updateChecker->getUpdateState(); + $params = [ + 'isNewVersionAvailable' => ($updateState === []) ? false : true, + 'lastChecked' => $lastUpdateCheck, + 'currentChannel' => $currentChannel, + 'channels' => $channels, + 'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'], + ]; + + return new TemplateResponse($this->appName, 'admin', $params, ''); + } + + /** + * @UseSession + * + * @param string $channel + * @return DataResponse + */ + public function setChannel($channel) { + \OCP\Util::setChannel($channel); + $this->config->setAppValue('core', 'lastupdatedat', 0); + return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Updated channel')]]); + } + + /** + * @return DataResponse + */ + public function createCredentials() { + // Create a new job and store the creation date + $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob'); + $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); + + // Create a new token + $newToken = $this->secureRandom->generate(64); + $this->config->setSystemValue('updater.secret', password_hash($newToken, PASSWORD_DEFAULT)); + + return new DataResponse($newToken); + } +} diff --git a/apps/updatenotification/lib/resettokenbackgroundjob.php b/apps/updatenotification/lib/ResetTokenBackgroundJob.php index 61bd9fc0490..61bd9fc0490 100644 --- a/apps/updatenotification/lib/resettokenbackgroundjob.php +++ b/apps/updatenotification/lib/ResetTokenBackgroundJob.php diff --git a/apps/updatenotification/lib/updatechecker.php b/apps/updatenotification/lib/UpdateChecker.php index bf653c23b8f..bf653c23b8f 100644 --- a/apps/updatenotification/lib/updatechecker.php +++ b/apps/updatenotification/lib/UpdateChecker.php |