actualize_script.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env php
  2. <?php
  3. require(__DIR__ . '/../cli/_cli.php');
  4. /**
  5. * Writes to FreshRSS admin log, and if it is not already done by default,
  6. * writes to syslog (only if simplepie_syslog_enabled in FreshRSS configuration) and to STDOUT
  7. */
  8. function notice($message) {
  9. Minz_Log::notice($message, ADMIN_LOG);
  10. if (!COPY_LOG_TO_SYSLOG && SIMPLEPIE_SYSLOG_ENABLED) {
  11. syslog(LOG_NOTICE, $message);
  12. }
  13. if (defined('STDOUT') && !COPY_SYSLOG_TO_STDERR) {
  14. fwrite(STDOUT, $message . "\n"); //Unbuffered
  15. }
  16. }
  17. session_cache_limiter('');
  18. ob_implicit_flush(false);
  19. ob_start();
  20. $begin_date = date_create('now');
  21. // Set the header params ($_GET) to call the FRSS application.
  22. $_GET['c'] = 'feed';
  23. $_GET['a'] = 'actualize';
  24. $_GET['ajax'] = 1;
  25. $_GET['force'] = true;
  26. $_SERVER['HTTP_HOST'] = '';
  27. $app = new FreshRSS();
  28. FreshRSS_Context::initSystem();
  29. FreshRSS_Context::$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
  30. define('SIMPLEPIE_SYSLOG_ENABLED', FreshRSS_Context::$system_conf->simplepie_syslog_enabled);
  31. notice('FreshRSS starting feeds actualization at ' . $begin_date->format('c'));
  32. // make sure the PHP setup of the CLI environment is compatible with FreshRSS as well
  33. echo 'Failed requirements!', "\n";
  34. performRequirementCheck(FreshRSS_Context::$system_conf->db['type']);
  35. ob_clean();
  36. echo 'Results: ', "\n"; //Buffered
  37. // Create the list of users to actualize.
  38. // Users are processed in a random order but always start with default user
  39. $users = listUsers();
  40. shuffle($users);
  41. if (FreshRSS_Context::$system_conf->default_user !== '') {
  42. array_unshift($users, FreshRSS_Context::$system_conf->default_user);
  43. $users = array_unique($users);
  44. }
  45. $limits = FreshRSS_Context::$system_conf->limits;
  46. $min_last_activity = time() - $limits['max_inactivity'];
  47. foreach ($users as $user) {
  48. FreshRSS_Context::initUser($user);
  49. if (FreshRSS_Context::$user_conf == null) {
  50. notice('Invalid user ' . $user);
  51. continue;
  52. }
  53. if (!FreshRSS_Context::$user_conf->enabled) {
  54. notice('FreshRSS skip disabled user ' . $user);
  55. continue;
  56. }
  57. if (($user !== FreshRSS_Context::$system_conf->default_user) &&
  58. (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) {
  59. notice('FreshRSS skip inactive user ' . $user);
  60. continue;
  61. }
  62. FreshRSS_Auth::giveAccess();
  63. Minz_ExtensionManager::callHook('freshrss_user_maintenance');
  64. $app->init();
  65. notice('FreshRSS actualize ' . $user . '...');
  66. echo $user, ' '; //Buffered
  67. $app->run();
  68. if (!invalidateHttpCache()) {
  69. Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG);
  70. if (defined('STDERR')) {
  71. fwrite(STDERR, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n");
  72. }
  73. }
  74. gc_collect_cycles();
  75. }
  76. $end_date = date_create('now');
  77. $duration = date_diff($end_date, $begin_date);
  78. notice('FreshRSS actualization done for ' . count($users) .
  79. ' users, using ' . format_bytes(memory_get_peak_usage(true)) . ' of memory, in ' .
  80. $duration->format('%a day(s), %h hour(s), %i minute(s) and %s seconds.'));
  81. echo 'End.', "\n";
  82. ob_end_flush();