Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use DI for MonthlyReport
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Apr 8, 2022
commit fa7b69dc9f4f570abbacfb526f62ac5a3a6cb258
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
"name": "nextcloud/survey_client",
"description": "Usage survey",
"license": "AGPL",
"require": {
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"nextcloud/coding-standard": "^1.0.0",
"christophwurst/nextcloud": "dev-master@dev",
"vimeo/psalm": "^4.3.2"
"vimeo/psalm": "^4.3.2",
"christophwurst/nextcloud": "dev-master"
},
"config": {
"optimize-autoloader": true,
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions lib/BackgroundJobs/MonthlyReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,34 @@

namespace OCA\Survey_Client\BackgroundJobs;

use OCA\Survey_Client\AppInfo\Application;
use OCA\Survey_Client\Collector;
use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\TimedJob;
use Psr\Log\LoggerInterface;

class MonthlyReport extends TimedJob {
public function __construct(ITimeFactory $time) {
protected Collector $collector;
protected LoggerInterface $logger;

public function __construct(ITimeFactory $time,
Collector $collector,
LoggerInterface $logger) {
parent::__construct($time);
$this->collector = $collector;
$this->logger = $logger;
// Run all 28 days
$this->setInterval(28 * 24 * 60 * 60);
// keeping time sensitive to not overload the target server at a single specific time of the day
$this->setTimeSensitivity(IJob::TIME_SENSITIVE);
}

protected function run($argument) {
$application = new Application();
/** @var \OCA\Survey_Client\Collector $collector */
$collector = $application->getContainer()->query('OCA\Survey_Client\Collector');
$result = $collector->sendReport();
$result = $this->collector->sendReport();

if ($result->getStatus() !== Http::STATUS_OK) {
\OC::$server->getLogger()->info('Error while sending usage statistic');
$this->logger->info('Error while sending usage statistic');
}
}
}