actualize_script.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/php
  2. <?php
  3. require(__DIR__ . '/../cli/_cli.php');
  4. session_cache_limiter('');
  5. ob_implicit_flush(false);
  6. ob_start();
  7. echo 'Results: ', "\n"; //Buffered
  8. if (defined('STDOUT')) {
  9. $begin_date = date_create('now');
  10. fwrite(STDOUT, 'Starting feed actualization at ' . $begin_date->format('c') . "\n"); //Unbuffered
  11. }
  12. syslog(LOG_INFO, 'FreshRSS Start feeds actualization...');
  13. // Set the header params ($_GET) to call the FRSS application.
  14. $_GET['c'] = 'feed';
  15. $_GET['a'] = 'actualize';
  16. $_GET['ajax'] = 1;
  17. $_GET['force'] = true;
  18. $_SERVER['HTTP_HOST'] = '';
  19. $app = new FreshRSS();
  20. $system_conf = Minz_Configuration::get('system');
  21. $system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
  22. // make sure the PHP setup of the CLI environment is compatible with FreshRSS as well
  23. performRequirementCheck($system_conf->db['type']);
  24. // Create the list of users to actualize.
  25. // Users are processed in a random order but always start with admin
  26. $users = listUsers();
  27. shuffle($users);
  28. if ($system_conf->default_user !== '') {
  29. array_unshift($users, $system_conf->default_user);
  30. $users = array_unique($users);
  31. }
  32. $limits = $system_conf->limits;
  33. $min_last_activity = time() - $limits['max_inactivity'];
  34. foreach ($users as $user) {
  35. if (($user !== $system_conf->default_user) &&
  36. (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) {
  37. Minz_Log::notice('FreshRSS skip inactive user ' . $user, ADMIN_LOG);
  38. if (defined('STDOUT')) {
  39. fwrite(STDOUT, 'FreshRSS skip inactive user ' . $user . "\n"); //Unbuffered
  40. }
  41. continue;
  42. }
  43. Minz_Log::notice('FreshRSS actualize ' . $user, ADMIN_LOG);
  44. if (defined('STDOUT')) {
  45. fwrite(STDOUT, 'Actualize ' . $user . "...\n"); //Unbuffered
  46. }
  47. echo $user, ' '; //Buffered
  48. Minz_Session::_param('currentUser', $user);
  49. new Minz_ModelPdo($user); //TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init
  50. FreshRSS_Auth::giveAccess();
  51. $app->init();
  52. $app->run();
  53. if (!invalidateHttpCache()) {
  54. Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG);
  55. if (defined('STDERR')) {
  56. fwrite(STDERR, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n");
  57. }
  58. }
  59. }
  60. Minz_Log::notice('FreshRSS actualize done.', ADMIN_LOG);
  61. if (defined('STDOUT')) {
  62. fwrite(STDOUT, 'Done.' . "\n");
  63. $end_date = date_create('now');
  64. $duration = date_diff($end_date, $begin_date);
  65. fwrite(STDOUT, 'Ending feed actualization at ' . $end_date->format('c') . "\n"); //Unbuffered
  66. fwrite(STDOUT, 'Feed actualizations took ' . $duration->format('%a day(s), %h hour(s), %i minute(s) and %s seconds') . ' for ' . count($users) . " users\n"); //Unbuffered
  67. }
  68. echo 'End.', "\n";
  69. ob_end_flush();
  70. syslog(LOG_INFO, 'FreshRSS feeds actualization done.');