2012-08-08 18:48:36 -04:00
|
|
|
<?php
|
2024-02-08 07:57:48 -05:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2025-10-02 09:48:42 -04:00
|
|
|
use OC\Core\Service\CronService;
|
|
|
|
|
use OCP\Server;
|
|
|
|
|
use Psr\Log\LoggerInterface;
|
2025-05-14 18:39:44 -04:00
|
|
|
|
2012-08-08 18:48:36 -04:00
|
|
|
/**
|
2024-05-24 13:43:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-04-20 15:26:47 -04:00
|
|
|
*/
|
2024-02-08 07:57:48 -05:00
|
|
|
|
2017-10-13 15:30:29 -04:00
|
|
|
require_once __DIR__ . '/lib/versioncheck.php';
|
2016-12-19 09:29:52 -05:00
|
|
|
|
2013-06-10 07:45:19 -04:00
|
|
|
try {
|
2016-10-06 06:13:02 -04:00
|
|
|
require_once __DIR__ . '/lib/base.php';
|
2013-03-16 19:48:10 -04:00
|
|
|
|
2024-06-06 09:30:16 -04:00
|
|
|
if (isset($argv[1]) && ($argv[1] === '-h' || $argv[1] === '--help')) {
|
2024-04-08 07:04:14 -04:00
|
|
|
echo 'Description:
|
|
|
|
|
Run the background job routine
|
|
|
|
|
|
|
|
|
|
Usage:
|
2024-09-15 09:47:11 -04:00
|
|
|
php -f cron.php -- [-h] [--verbose] [<job-classes>...]
|
2024-04-08 07:04:14 -04:00
|
|
|
|
|
|
|
|
Arguments:
|
2024-04-11 04:55:39 -04:00
|
|
|
job-classes Optional job class list to only run those jobs
|
2025-02-21 04:45:40 -05:00
|
|
|
Providing a class will ignore the time-sensitivity restriction
|
2024-04-08 07:04:14 -04:00
|
|
|
|
|
|
|
|
Options:
|
2024-09-15 09:47:11 -04:00
|
|
|
-h, --help Display this help message
|
|
|
|
|
-v, --verbose Output more information' . PHP_EOL;
|
2024-04-08 07:04:14 -04:00
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-02 09:48:42 -04:00
|
|
|
$cronService = Server::get(CronService::class);
|
|
|
|
|
if (isset($argv[1])) {
|
|
|
|
|
$verbose = $argv[1] === '-v' || $argv[1] === '--verbose';
|
2025-02-21 04:45:40 -05:00
|
|
|
$jobClasses = array_slice($argv, $verbose ? 2 : 1);
|
|
|
|
|
$jobClasses = empty($jobClasses) ? null : $jobClasses;
|
|
|
|
|
|
2025-10-02 09:48:42 -04:00
|
|
|
if ($verbose) {
|
2025-10-20 19:52:40 -04:00
|
|
|
$cronService->registerVerboseCallback(function (string $message): void {
|
2025-10-02 09:48:42 -04:00
|
|
|
echo $message . PHP_EOL;
|
|
|
|
|
});
|
2013-06-10 07:45:19 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2025-10-02 09:48:42 -04:00
|
|
|
$jobClasses = null;
|
2012-08-09 17:49:20 -04:00
|
|
|
}
|
2012-10-26 17:16:17 -04:00
|
|
|
|
2025-10-02 09:48:42 -04:00
|
|
|
$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) {
|
2024-02-08 07:57:48 -05:00
|
|
|
Server::get(LoggerInterface::class)->error(
|
2025-10-02 09:48:42 -04:00
|
|
|
$e->getMessage(),
|
|
|
|
|
['app' => 'cron', 'exception' => $e]
|
2024-02-08 07:57:48 -05:00
|
|
|
);
|
2025-10-02 09:48:42 -04:00
|
|
|
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);
|
|
|
|
|
}
|
2021-07-18 11:06:45 -04:00
|
|
|
exit(1);
|
2013-08-18 05:02:08 -04:00
|
|
|
}
|