From 50e1cee5c7a8e9354e2bafac22a60b0e369a720f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jan 2018 11:38:26 +0100 Subject: Automatic DI for Controllers also works Signed-off-by: Joas Schilling --- .../updatenotification/lib/AppInfo/Application.php | 48 ++++++---------------- .../lib/Controller/AdminController.php | 19 +++------ 2 files changed, 18 insertions(+), 49 deletions(-) (limited to 'apps/updatenotification/lib') diff --git a/apps/updatenotification/lib/AppInfo/Application.php b/apps/updatenotification/lib/AppInfo/Application.php index 5eba176f312..49b046c6fef 100644 --- a/apps/updatenotification/lib/AppInfo/Application.php +++ b/apps/updatenotification/lib/AppInfo/Application.php @@ -1,56 +1,32 @@ * - * @author Lukas Reschke - * @author Thomas Müller + * @author Joas Schilling * - * @license AGPL-3.0 + * @license GNU AGPL version 3 or any later version * - * 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 free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. * * 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 + * 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 + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . * */ namespace OCA\UpdateNotification\AppInfo; -use OC\AppFramework\Utility\TimeFactory; -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() - ); - }); + public function __construct() { + parent::__construct('updatenotification', []); } - } diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index 9d2a5074a4a..78f2d411bb8 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -25,6 +25,7 @@ namespace OCA\UpdateNotification\Controller; +use OCA\UpdateNotification\ResetTokenBackgroundJob; use OCA\UpdateNotification\UpdateChecker; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; @@ -37,6 +38,7 @@ use OCP\IL10N; use OCP\IRequest; use OCP\Security\ISecureRandom; use OCP\Settings\ISettings; +use OCP\Util; class AdminController extends Controller implements ISettings { /** @var IJobList */ @@ -87,7 +89,7 @@ class AdminController extends Controller implements ISettings { /** * @return TemplateResponse */ - public function displayPanel() { + public function getForm() { $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp); @@ -97,7 +99,7 @@ class AdminController extends Controller implements ISettings { 'stable', 'production', ]; - $currentChannel = \OCP\Util::getChannel(); + $currentChannel = Util::getChannel(); // Remove the currently used channel from the channels list if(($key = array_search($currentChannel, $channels)) !== false) { @@ -128,13 +130,11 @@ class AdminController extends Controller implements ISettings { } /** - * @UseSession - * * @param string $channel * @return DataResponse */ public function setChannel($channel) { - \OCP\Util::setChannel($channel); + Util::setChannel($channel); $this->config->setAppValue('core', 'lastupdatedat', 0); return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); } @@ -144,7 +144,7 @@ class AdminController extends Controller implements ISettings { */ public function createCredentials() { // Create a new job and store the creation date - $this->jobList->add('OCA\UpdateNotification\ResetTokenBackgroundJob'); + $this->jobList->add(ResetTokenBackgroundJob::class); $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); // Create a new token @@ -154,13 +154,6 @@ class AdminController extends Controller implements ISettings { return new DataResponse($newToken); } - /** - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered - */ - public function getForm() { - return $this->displayPanel(); - } - /** * @return string the section ID, e.g. 'sharing' */ -- cgit v1.2.3