diff --git a/apps/settings/lib/Settings/Admin/Server.php b/apps/settings/lib/Settings/Admin/Server.php index 6216af4aada..40333e1043c 100644 --- a/apps/settings/lib/Settings/Admin/Server.php +++ b/apps/settings/lib/Settings/Admin/Server.php @@ -29,16 +29,19 @@ namespace OCA\Settings\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; +use OCP\IDBConnection; use OCP\Settings\ISettings; class Server implements ISettings { + + /** @var IDBConnection */ + private $connection; /** @var IConfig */ private $config; - /** - * @param IConfig $config - */ - public function __construct(IConfig $config) { + public function __construct(IDBConnection $connection, + IConfig $config) { + $this->connection = $connection; $this->config = $config; } @@ -46,10 +49,25 @@ class Server implements ISettings { * @return TemplateResponse */ public function getForm() { + $query = $this->connection->getQueryBuilder(); + $query->select('last_checked') + ->from('jobs') + ->orderBy('last_checked', 'ASC') + ->setMaxResults(1); + + $result = $query->execute(); + if ($row = $result->fetch()) { + $maxAge = (int) $row['last_checked']; + } else { + $maxAge = time(); + } + $result->closeCursor(); + $parameters = [ // Background jobs 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'), 'lastcron' => $this->config->getAppValue('core', 'lastcron', false), + 'cronMaxAge' => $maxAge, 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'), 'cli_based_cron_possible' => function_exists('posix_getpwuid'), 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '', diff --git a/apps/settings/templates/settings/admin/server.php b/apps/settings/templates/settings/admin/server.php index 92bf433ca6c..513e82ece5a 100644 --- a/apps/settings/templates/settings/admin/server.php +++ b/apps/settings/templates/settings/admin/server.php @@ -29,26 +29,40 @@

t('Background jobs'));?>

- getDateTimeFormatter(); $absolute_time = $formatter->formatDateTime($_['lastcron'], 'long', 'long'); - if (time() - $_['lastcron'] <= 600): ?> - - - t("Last job ran %s.", [$relative_time]));?> - - + $maxAgeAbsoluteTime = $formatter->formatDateTime($_['cronMaxAge'], 'long', 'long'); + if (time() - $_['lastcron'] > 600) { ?> - t("Last job execution ran %s. Something seems wrong.", [$relative_time]));?> - - + t("Last job execution ran %s. Something seems wrong.", [$relative_time]));?> + + 12*3600) { + if ($_['backgroundjobs_mode'] === 'cron') { ?> + + + t("Some jobs haven’t been executed since %s. Please consider increasing the execution frequency.", [$maxAgeRelativeTime]));?> + + + + + t("Some jobs didn’t execute since %s. Please consider switching to system cron.", [$maxAgeRelativeTime]));?> + + + + + t("Last job ran %s.", [$relative_time]));?> + + t("Background job didn’t run yet!")); - endif; ?> + } ?>