summaryrefslogtreecommitdiffstats
path: root/apps/settings/lib
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-01-15 15:05:14 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-01-18 10:02:23 +0100
commit27514adef4cdfb51675211644dad6819323b142f (patch)
treeb18cfaad73b0acb85435fe13386c8761c76420c7 /apps/settings/lib
parent86bfd7339c4db1ccb178a93e7ca0133ad909333e (diff)
downloadnextcloud-server-27514adef4cdfb51675211644dad6819323b142f.tar.gz
nextcloud-server-27514adef4cdfb51675211644dad6819323b142f.zip
Migrate Cron checks to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/settings/lib')
-rw-r--r--apps/settings/lib/AppInfo/Application.php4
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php26
-rw-r--r--apps/settings/lib/SetupChecks/CronErrors.php62
-rw-r--r--apps/settings/lib/SetupChecks/CronInfo.php81
4 files changed, 147 insertions, 26 deletions
diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php
index 8b2e9e12a1e..820ee4f98ac 100644
--- a/apps/settings/lib/AppInfo/Application.php
+++ b/apps/settings/lib/AppInfo/Application.php
@@ -52,6 +52,8 @@ use OCA\Settings\SetupChecks\AppDirsWithDifferentOwner;
use OCA\Settings\SetupChecks\BruteForceThrottler;
use OCA\Settings\SetupChecks\CheckUserCertificates;
use OCA\Settings\SetupChecks\CodeIntegrity;
+use OCA\Settings\SetupChecks\CronErrors;
+use OCA\Settings\SetupChecks\CronInfo;
use OCA\Settings\SetupChecks\DatabaseHasMissingColumns;
use OCA\Settings\SetupChecks\DatabaseHasMissingIndices;
use OCA\Settings\SetupChecks\DatabaseHasMissingPrimaryKeys;
@@ -172,6 +174,8 @@ class Application extends App implements IBootstrap {
$context->registerSetupCheck(BruteForceThrottler::class);
$context->registerSetupCheck(CheckUserCertificates::class);
$context->registerSetupCheck(CodeIntegrity::class);
+ $context->registerSetupCheck(CronErrors::class);
+ $context->registerSetupCheck(CronInfo::class);
$context->registerSetupCheck(DatabaseHasMissingColumns::class);
$context->registerSetupCheck(DatabaseHasMissingIndices::class);
$context->registerSetupCheck(DatabaseHasMissingPrimaryKeys::class);
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php
index c7f1f59ba7d..00883a0d51e 100644
--- a/apps/settings/lib/Controller/CheckSetupController.php
+++ b/apps/settings/lib/Controller/CheckSetupController.php
@@ -55,7 +55,6 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
-use OCP\IDateTimeFormatter;
use OCP\IL10N;
use OCP\IRequest;
use OCP\ITempManager;
@@ -78,8 +77,6 @@ class CheckSetupController extends Controller {
private $checker;
/** @var LoggerInterface */
private $logger;
- /** @var IDateTimeFormatter */
- private $dateTimeFormatter;
/** @var ITempManager */
private $tempManager;
/** @var IManager */
@@ -94,7 +91,6 @@ class CheckSetupController extends Controller {
IL10N $l10n,
Checker $checker,
LoggerInterface $logger,
- IDateTimeFormatter $dateTimeFormatter,
ITempManager $tempManager,
IManager $manager,
ISetupCheckManager $setupCheckManager,
@@ -106,7 +102,6 @@ class CheckSetupController extends Controller {
$this->l10n = $l10n;
$this->checker = $checker;
$this->logger = $logger;
- $this->dateTimeFormatter = $dateTimeFormatter;
$this->tempManager = $tempManager;
$this->manager = $manager;
$this->setupCheckManager = $setupCheckManager;
@@ -302,25 +297,6 @@ Raw output
);
}
- protected function getLastCronInfo(): array {
- $lastCronRun = (int)$this->config->getAppValue('core', 'lastcron', '0');
- return [
- 'diffInSeconds' => time() - $lastCronRun,
- 'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun),
- 'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
- ];
- }
-
- protected function getCronErrors() {
- $errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true);
-
- if (is_array($errors)) {
- return $errors;
- }
-
- return [];
- }
-
private function isTemporaryDirectoryWritable(): bool {
try {
if (!empty($this->tempManager->getTempBaseDir())) {
@@ -388,8 +364,6 @@ Raw output
public function check() {
return new DataResponse(
[
- 'cronInfo' => $this->getLastCronInfo(),
- 'cronErrors' => $this->getCronErrors(),
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(),
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
diff --git a/apps/settings/lib/SetupChecks/CronErrors.php b/apps/settings/lib/SetupChecks/CronErrors.php
new file mode 100644
index 00000000000..a2ebbf5f12c
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/CronErrors.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Settings\SetupChecks;
+
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class CronErrors implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IConfig $config,
+ ) {
+ }
+
+ public function getCategory(): string {
+ return 'system';
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('Cron errors');
+ }
+
+ public function run(): SetupResult {
+ $errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true);
+ if (is_array($errors) && count($errors) > 0) {
+ return SetupResult::error(
+ $this->l10n->t(
+ "It was not possible to execute the cron job via CLI. The following technical errors have appeared:\n%s",
+ implode("\n", array_map(fn (array $error) => '- '.$error['error'].' '.$error['hint'], $errors))
+ )
+ );
+ } else {
+ return SetupResult::success($this->l10n->t('The last cron job ran without errors.'));
+ }
+ }
+}
diff --git a/apps/settings/lib/SetupChecks/CronInfo.php b/apps/settings/lib/SetupChecks/CronInfo.php
new file mode 100644
index 00000000000..d08bb6852a8
--- /dev/null
+++ b/apps/settings/lib/SetupChecks/CronInfo.php
@@ -0,0 +1,81 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Settings\SetupChecks;
+
+use OCP\IConfig;
+use OCP\IDateTimeFormatter;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\ISetupCheck;
+use OCP\SetupCheck\SetupResult;
+
+class CronInfo implements ISetupCheck {
+ public function __construct(
+ private IL10N $l10n,
+ private IConfig $config,
+ private IURLGenerator $urlGenerator,
+ private IDateTimeFormatter $dateTimeFormatter,
+ ) {
+ }
+
+ public function getCategory(): string {
+ return 'system';
+ }
+
+ public function getName(): string {
+ return $this->l10n->t('Cron last run');
+ }
+
+ public function run(): SetupResult {
+ $lastCronRun = (int)$this->config->getAppValue('core', 'lastcron', '0');
+ $relativeTime = $this->dateTimeFormatter->formatTimeSpan($lastCronRun);
+
+ if ((time() - $lastCronRun) > 3600) {
+ return SetupResult::error(
+ $this->l10n->t(
+ 'Last background job execution ran %s. Something seems wrong. {link}.',
+ [$relativeTime]
+ ),
+ descriptionParameters:[
+ 'link' => [
+ 'type' => 'highlight',
+ 'id' => 'backgroundjobs',
+ 'name' => 'Check the background job settings',
+ 'link' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
+ ],
+ ],
+ );
+ } else {
+ return SetupResult::success(
+ $this->l10n->t(
+ 'Last background job execution ran %s.',
+ [$relativeTime]
+ )
+ );
+ }
+ }
+}