actualize_script.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. require(dirname(__FILE__) . '/../constants.php');
  3. require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader
  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. // Set the header params ($_GET) to call the FRSS application.
  13. $_GET['c'] = 'feed';
  14. $_GET['a'] = 'actualize';
  15. $_GET['ajax'] = 1;
  16. $_GET['force'] = true;
  17. $_SERVER['HTTP_HOST'] = '';
  18. $app = new FreshRSS();
  19. $app->init();
  20. $system_conf = Minz_Configuration::get('system');
  21. $system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
  22. // Create the list of users to actualize.
  23. // Users are processed in a random order but always start with admin
  24. $users = listUsers();
  25. shuffle($users);
  26. if ($system_conf->default_user !== ''){
  27. array_unshift($users, $system_conf->default_user);
  28. $users = array_unique($users);
  29. }
  30. $limits = $system_conf->limits;
  31. $minLastActivity = time() - $limits['max_inactivity'];
  32. foreach ($users as $myUser) {
  33. if (($myUser !== $system_conf->default_user) &&
  34. (FreshRSS_UserDAO::mtime($myUser) < $minLastActivity)) {
  35. syslog(LOG_INFO, 'FreshRSS skip inactive user ' . $myUser);
  36. if (defined('STDOUT')) {
  37. fwrite(STDOUT, 'FreshRSS skip inactive user ' . $myUser . "\n"); //Unbuffered
  38. }
  39. continue;
  40. }
  41. syslog(LOG_INFO, 'FreshRSS actualize ' . $myUser);
  42. if (defined('STDOUT')) {
  43. fwrite(STDOUT, 'Actualize ' . $myUser . "...\n"); //Unbuffered
  44. }
  45. echo $myUser, ' '; //Buffered
  46. Minz_Session::_param('currentUser', $myUser);
  47. $app->run();
  48. if (!invalidateHttpCache()) {
  49. syslog(LOG_NOTICE, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $myUser, 'log.txt'));
  50. if (defined('STDERR')) {
  51. fwrite(STDERR, 'Write access problem in ' . join_path(USERS_PATH, $myUser, 'log.txt') . "\n");
  52. }
  53. }
  54. }
  55. syslog(LOG_INFO, 'FreshRSS actualize done.');
  56. if (defined('STDOUT')) {
  57. fwrite(STDOUT, 'Done.' . "\n");
  58. $end_date = date_create('now');
  59. $duration = date_diff($end_date, $begin_date);
  60. fwrite(STDOUT, 'Ending feed actualization at ' . $end_date->format('c') . "\n"); //Unbuffered
  61. 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
  62. }
  63. echo 'End.', "\n";
  64. ob_end_flush();