Skip to content

Commit

Permalink
add cron status badge to admin setting
Browse files Browse the repository at this point in the history
Display  a info card in the settings, indicating when the last news update job ran.

Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
  • Loading branch information
Grotax committed Mar 5, 2023
1 parent 5fea38a commit b17e982
Show file tree
Hide file tree
Showing 7 changed files with 5,345 additions and 2,763 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1
## [21.x.x]
### Changed
- Remove unused background job OCA\News\Cron\Updater
- Add info card to the admin settings, showing last job execution (#2141)
### Fixed

# Releases
Expand Down
28 changes: 27 additions & 1 deletion lib/Service/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
use OCA\News\AppInfo\Application;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\BackgroundJob\IJobList;
use OCP\Util;
use OCA\News\Cron\UpdaterJob;


class StatusService
{
Expand All @@ -25,14 +29,18 @@ class StatusService
private $appName;
/** @var IDBConnection */
private $connection;
/** @var IJobList */
private $jobList;

public function __construct(
IConfig $settings,
IDBConnection $connection
IDBConnection $connection,
IJobList $jobList
) {
$this->settings = $settings;
$this->connection = $connection;
$this->appName = Application::NAME;
$this->jobList = $jobList;
}

/**
Expand Down Expand Up @@ -76,4 +84,22 @@ public function getStatus(): array
]
];
}

/**
* Get last update time
*/
public function getUpdateTime(): int
{

$time = 0;

[$major, $minor, $micro] = Util::getVersion();

if($major >= 26) {
$myJobList = $this->jobList->getJobsIterator(UpdaterJob::class, 1, 0);
$time = $myJobList->current()->getLastRun();
}

return $time;
}
}
14 changes: 13 additions & 1 deletion lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace OCA\News\Settings;

use OCA\News\AppInfo\Application;
use OCA\News\Service\StatusService;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\Settings\ISettings;
Expand All @@ -17,11 +18,14 @@ class AdminSettings implements ISettings
private $config;
/** @var IInitialState */
private $initialState;
/** @var StatusService */
private $service;

public function __construct(IConfig $config, IInitialState $initialState)
public function __construct(IConfig $config, IInitialState $initialState, StatusService $service)
{
$this->config = $config;
$this->initialState = $initialState;
$this->service = $service;
}

public function getForm()
Expand All @@ -33,6 +37,14 @@ public function getForm()
(string)Application::DEFAULT_SETTINGS[$setting]
));
}

if ($this->service->isCronProperlyConfigured()) {
$lastUpdate = $this->service->getUpdateTime();
} else {
$lastUpdate = 0;
}

$this->initialState->provideInitialState("lastCron", $lastUpdate);

return new TemplateResponse(Application::NAME, 'admin', []);
}
Expand Down
Loading

0 comments on commit b17e982

Please sign in to comment.