Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @author Joas Schilling <[email protected]>
*
Expand Down
2 changes: 0 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@
class Application extends App {
public function __construct (array $urlParams = array()) {
parent::__construct('survey_client', $urlParams);

$this->getContainer()->registerAlias('EndpointController', 'OCA\Survey_Client\Controller\EndpointController');
}
}
14 changes: 7 additions & 7 deletions lib/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -151,9 +152,9 @@ public function getReport() {
}

/**
* @return \OC\OCS\Result
* @return DataResponse
*/
public function sendReport() {
public function sendReport(): DataResponse {
$report = $this->getReport();

$client = $this->clientService->newClient();
Expand All @@ -166,7 +167,7 @@ public function sendReport() {
],
]);
} catch (\Exception $e) {
return new \OC\OCS\Result(
return new DataResponse(
$report,
Http::STATUS_INTERNAL_SERVER_ERROR
);
Expand All @@ -175,13 +176,12 @@ public function sendReport() {
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: <status>failure</status><statuscode>200</statuscode>
return new DataResponse(
$report
);
}

return new \OC\OCS\Result(
return new DataResponse(
$report,
Http::STATUS_INTERNAL_SERVER_ERROR
);
Expand Down
35 changes: 21 additions & 14 deletions lib/Controller/EndpointController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @author Joas Schilling <[email protected]>
*
Expand All @@ -22,13 +23,15 @@
namespace OCA\Survey_Client\Controller;

use OCA\Survey_Client\Collector;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cough

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;
Expand All @@ -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;
Expand All @@ -55,35 +62,35 @@ public function __construct($appName, IRequest $request, Collector $collector, I
}

/**
* @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();
}
}