From 36cd89985db129961a7f070f2df6345c3a6664e9 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 17 Jan 2018 20:19:39 +0100 Subject: Move over to OCSController Signed-off-by: Roeland Jago Douma --- lib/AppInfo/Application.php | 2 -- lib/Collector.php | 14 +++++++------- lib/Controller/EndpointController.php | 35 +++++++++++++++++++++-------------- 3 files changed, 28 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index cb1e164..7786ab6 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -27,7 +27,5 @@ use OCP\AppFramework\App; class Application extends App { public function __construct (array $urlParams = array()) { parent::__construct('survey_client', $urlParams); - - $this->getContainer()->registerAlias('EndpointController', 'OCA\Survey_Client\Controller\EndpointController'); } } diff --git a/lib/Collector.php b/lib/Collector.php index af70d3d..dfad9a3 100644 --- a/lib/Collector.php +++ b/lib/Collector.php @@ -31,6 +31,7 @@ use OCA\Survey_Client\Categories\Php; use OCA\Survey_Client\Categories\Server; use OCA\Survey_Client\Categories\Stats; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IDBConnection; @@ -151,9 +152,9 @@ class Collector { } /** - * @return \OC\OCS\Result + * @return DataResponse */ - public function sendReport() { + public function sendReport(): DataResponse { $report = $this->getReport(); $client = $this->clientService->newClient(); @@ -166,7 +167,7 @@ class Collector { ], ]); } catch (\Exception $e) { - return new \OC\OCS\Result( + return new DataResponse( $report, Http::STATUS_INTERNAL_SERVER_ERROR ); @@ -175,13 +176,12 @@ class Collector { if ($response->getStatusCode() === Http::STATUS_OK) { $this->config->setAppValue('survey_client', 'last_sent', time()); $this->config->setAppValue('survey_client', 'last_report', json_encode($report)); - return new \OC\OCS\Result( - $report, - 100// HTTP::STATUS_OK, TODO: failure200 + return new DataResponse( + $report ); } - return new \OC\OCS\Result( + return new DataResponse( $report, Http::STATUS_INTERNAL_SERVER_ERROR ); diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php index bff9895..75dbf6d 100644 --- a/lib/Controller/EndpointController.php +++ b/lib/Controller/EndpointController.php @@ -1,4 +1,5 @@ * @@ -22,13 +23,15 @@ namespace OCA\Survey_Client\Controller; use OCA\Survey_Client\Collector; -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; + +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\OCSController; use OCP\BackgroundJob\IJobList; use OCP\IRequest; use OCP\Notification\IManager; +use OCA\Survey_Client\BackgroundJobs\MonthlyReport; -class EndpointController extends Controller { +class EndpointController extends OCSController { /** @var Collector */ protected $collector; @@ -46,7 +49,11 @@ class EndpointController extends Controller { * @param IJobList $jobList * @param IManager $manager */ - public function __construct($appName, IRequest $request, Collector $collector, IJobList $jobList, IManager $manager) { + public function __construct(string $appName, + IRequest $request, + Collector $collector, + IJobList $jobList, + IManager $manager) { parent::__construct($appName, $request); $this->collector = $collector; @@ -55,35 +62,35 @@ class EndpointController extends Controller { } /** - * @return \OC\OCS\Result + * @return DataResponse */ - public function enableMonthly() { - $this->jobList->add('OCA\Survey_Client\BackgroundJobs\MonthlyReport'); + public function enableMonthly(): DataResponse { + $this->jobList->add(MonthlyReport::class); $notification = $this->manager->createNotification(); $notification->setApp('survey_client'); $this->manager->markProcessed($notification); - return new \OC\OCS\Result(); + return new DataResponse([]); } /** - * @return \OC\OCS\Result + * @return DataResponse */ - public function disableMonthly() { - $this->jobList->remove('OCA\Survey_Client\BackgroundJobs\MonthlyReport'); + public function disableMonthly(): DataResponse { + $this->jobList->remove(MonthlyReport::class); $notification = $this->manager->createNotification(); $notification->setApp('survey_client'); $this->manager->markProcessed($notification); - return new \OC\OCS\Result(); + return new DataResponse([]); } /** - * @return \OC\OCS\Result + * @return DataResponse */ - public function sendReport() { + public function sendReport(): DataResponse { return $this->collector->sendReport(); } } -- cgit v1.2.3