WebOrbiton
v1.0.0.8

Publisium

41 lines · 1.0 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (PHP_SAPI !== 'cli') {
  6. http_response_code(403);
  7. exit('This script can only be run from the command line (cron).');
  8. }
  9. ​
  10. require_once __DIR__ . '/includes/config.php';
  11. require_once __DIR__ . '/includes/database.php';
  12. require_once __DIR__ . '/includes/activity-log.php';
  13. require_once __DIR__ . '/includes/updater.php';
  14. ​
  15. if (!Config::isInstalled()) {
  16. fwrite(STDERR, "Publisium is not installed.\n");
  17. exit(1);
  18. }
  19. ​
  20. if (Updater::lockedByConfig()) {
  21. fwrite(STDOUT, "The updater is disabled in the server configuration (UPDATER_DISABLED=1).\n");
  22. exit(0);
  23. }
  24. ​
  25. set_time_limit(600);
  26. ​
  27. try {
  28. $db = Database::site();
  29. $outcome = Updater::runAutomatic($db);
  30. } catch (Throwable $exception) {
  31. fwrite(STDERR, 'Automatic update failed: ' . $exception->getMessage() . "\n");
  32. exit(1);
  33. }
  34. ​
  35. if ($outcome['installed']) {
  36. ActivityLog::record('updater.auto_install', 'updater', null, $outcome['message'], true);
  37. }
  38. ​
  39. fwrite($outcome['ok'] ? STDOUT : STDERR, $outcome['message'] . "\n");
  40. exit($outcome['ok'] ? 0 : 1);
  41. ​