File size: 1,913 Bytes
38b4eff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

declare(strict_types=1);

use OC\Core\Service\CronService;
use OCP\Server;
use Psr\Log\LoggerInterface;

/**
 * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-only
 */

require_once __DIR__ . '/lib/versioncheck.php';

try {
	require_once __DIR__ . '/lib/base.php';

	if (isset($argv[1]) && ($argv[1] === '-h' || $argv[1] === '--help')) {
		echo 'Description:
  Run the background job routine

Usage:
  php -f cron.php -- [-h] [--verbose] [<job-classes>...]

Arguments:
  job-classes                  Optional job class list to only run those jobs
                               Providing a class will ignore the time-sensitivity restriction

Options:
  -h, --help                 Display this help message
  -v, --verbose              Output more information' . PHP_EOL;
		exit(0);
	}

	$cronService = Server::get(CronService::class);
	if (isset($argv[1])) {
		$verbose = $argv[1] === '-v' || $argv[1] === '--verbose';
		$jobClasses = array_slice($argv, $verbose ? 2 : 1);
		$jobClasses = empty($jobClasses) ? null : $jobClasses;

		if ($verbose) {
			$cronService->registerVerboseCallback(function (string $message): void {
				echo $message . PHP_EOL;
			});
		}
	} else {
		$jobClasses = null;
	}

	$cronService->run($jobClasses);
	if (!OC::$CLI) {
		$data = [
			'status' => 'success',
		];
		header('Content-Type: application/json; charset=utf-8');
		echo json_encode($data, JSON_HEX_TAG);
	}
	exit(0);
} catch (Throwable $e) {
	Server::get(LoggerInterface::class)->error(
		$e->getMessage(),
		['app' => 'cron', 'exception' => $e]
	);
	if (OC::$CLI) {
		echo $e->getMessage() . PHP_EOL;
	} else {
		$data = [
			'status' => 'error',
			'message' => $e->getMessage(),
		];
		header('Content-Type: application/json; charset=utf-8');
		echo json_encode($data, JSON_HEX_TAG);
	}
	exit(1);
}