You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB

13 years ago
  1. <?php
  2. declare(strict_types=1);
  3. use OC\Core\Service\CronService;
  4. use OCP\Server;
  5. use Psr\Log\LoggerInterface;
  6. /**
  7. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  8. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  9. * SPDX-License-Identifier: AGPL-3.0-only
  10. */
  11. require_once __DIR__ . '/lib/versioncheck.php';
  12. try {
  13. require_once __DIR__ . '/lib/base.php';
  14. if (isset($argv[1]) && ($argv[1] === '-h' || $argv[1] === '--help')) {
  15. echo 'Description:
  16. Run the background job routine
  17. Usage:
  18. php -f cron.php -- [-h] [--verbose] [<job-classes>...]
  19. Arguments:
  20. job-classes Optional job class list to only run those jobs
  21. Providing a class will ignore the time-sensitivity restriction
  22. Options:
  23. -h, --help Display this help message
  24. -v, --verbose Output more information' . PHP_EOL;
  25. exit(0);
  26. }
  27. $cronService = Server::get(CronService::class);
  28. if (isset($argv[1])) {
  29. $verbose = $argv[1] === '-v' || $argv[1] === '--verbose';
  30. $jobClasses = array_slice($argv, $verbose ? 2 : 1);
  31. $jobClasses = empty($jobClasses) ? null : $jobClasses;
  32. if ($verbose) {
  33. $cronService->registerVerboseCallback(function (string $message): void {
  34. echo $message . PHP_EOL;
  35. });
  36. }
  37. } else {
  38. $jobClasses = null;
  39. }
  40. $cronService->run($jobClasses);
  41. if (!OC::$CLI) {
  42. $data = [
  43. 'status' => 'success',
  44. ];
  45. header('Content-Type: application/json; charset=utf-8');
  46. echo json_encode($data, JSON_HEX_TAG);
  47. }
  48. exit(0);
  49. } catch (Throwable $e) {
  50. Server::get(LoggerInterface::class)->error(
  51. $e->getMessage(),
  52. ['app' => 'cron', 'exception' => $e]
  53. );
  54. if (OC::$CLI) {
  55. echo $e->getMessage() . PHP_EOL;
  56. } else {
  57. $data = [
  58. 'status' => 'error',
  59. 'message' => $e->getMessage(),
  60. ];
  61. header('Content-Type: application/json; charset=utf-8');
  62. echo json_encode($data, JSON_HEX_TAG);
  63. }
  64. exit(1);
  65. }