actualize_script.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. $system_conf = Minz_Configuration::get('system');
  20. $system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
  21. // Create the list of users to actualize.
  22. // Users are processed in a random order but always start with admin
  23. $users = listUsers();
  24. shuffle($users);
  25. if ($system_conf->default_user !== ''){
  26. array_unshift($users, $system_conf->default_user);
  27. $users = array_unique($users);
  28. }
  29. $limits = $system_conf->limits;
  30. $min_last_activity = time() - $limits['max_inactivity'];
  31. foreach ($users as $user) {
  32. if (($user !== $system_conf->default_user) &&
  33. (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) {
  34. syslog(LOG_INFO, 'FreshRSS skip inactive user ' . $user);
  35. if (defined('STDOUT')) {
  36. fwrite(STDOUT, 'FreshRSS skip inactive user ' . $user . "\n"); //Unbuffered
  37. }
  38. continue;
  39. }
  40. syslog(LOG_INFO, 'FreshRSS actualize ' . $user);
  41. if (defined('STDOUT')) {
  42. fwrite(STDOUT, 'Actualize ' . $user . "...\n"); //Unbuffered
  43. }
  44. echo $user, ' '; //Buffered
  45. Minz_Session::_param('currentUser', $user);
  46. new Minz_ModelPdo($user); //TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init
  47. FreshRSS_Auth::giveAccess();
  48. $app->init();
  49. $app->run();
  50. if (!invalidateHttpCache()) {
  51. syslog(LOG_NOTICE, 'FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'));
  52. if (defined('STDERR')) {
  53. fwrite(STDERR, 'Write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n");
  54. }
  55. }
  56. }
  57. syslog(LOG_INFO, 'FreshRSS actualize done.');
  58. if (defined('STDOUT')) {
  59. fwrite(STDOUT, 'Done.' . "\n");
  60. $end_date = date_create('now');
  61. $duration = date_diff($end_date, $begin_date);
  62. fwrite(STDOUT, 'Ending feed actualization at ' . $end_date->format('c') . "\n"); //Unbuffered
  63. 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
  64. }
  65. echo 'End.', "\n";
  66. ob_end_flush();