actualize_script.php 2.7 KB

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