actualize_script.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. require(__DIR__ . '/../cli/_cli.php');
  3. session_cache_limiter('');
  4. ob_implicit_flush(false);
  5. ob_start();
  6. echo 'Results: ', "\n"; //Buffered
  7. if (defined('STDOUT')) {
  8. $begin_date = date_create('now');
  9. fwrite(STDOUT, 'Starting feed actualization at ' . $begin_date->format('c') . "\n"); //Unbuffered
  10. }
  11. // Set the header params ($_GET) to call the FRSS application.
  12. $_GET['c'] = 'feed';
  13. $_GET['a'] = 'actualize';
  14. $_GET['ajax'] = 1;
  15. $_GET['force'] = true;
  16. $_SERVER['HTTP_HOST'] = '';
  17. $app = new FreshRSS();
  18. $system_conf = Minz_Configuration::get('system');
  19. $system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
  20. // make sure the PHP setup of the CLI environment is compatible with FreshRSS as well
  21. performRequirementCheck($system_conf->db['type']);
  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. $min_last_activity = time() - $limits['max_inactivity'];
  32. foreach ($users as $user) {
  33. if (($user !== $system_conf->default_user) &&
  34. (FreshRSS_UserDAO::mtime($user) < $min_last_activity)) {
  35. Minz_Log::notice('FreshRSS skip inactive user ' . $user, ADMIN_LOG);
  36. if (defined('STDOUT')) {
  37. fwrite(STDOUT, 'FreshRSS skip inactive user ' . $user . "\n"); //Unbuffered
  38. }
  39. continue;
  40. }
  41. Minz_Log::notice('FreshRSS actualize ' . $user, ADMIN_LOG);
  42. if (defined('STDOUT')) {
  43. fwrite(STDOUT, 'Actualize ' . $user . "...\n"); //Unbuffered
  44. }
  45. echo $user, ' '; //Buffered
  46. Minz_Session::_param('currentUser', $user);
  47. new Minz_ModelPdo($user); //TODO: FIXME: Quick-fix while waiting for a better FreshRSS() constructor/init
  48. FreshRSS_Auth::giveAccess();
  49. $app->init();
  50. $app->run();
  51. if (!invalidateHttpCache()) {
  52. Minz_Log::warning('FreshRSS write access problem in ' . join_path(USERS_PATH, $user, 'log.txt'), ADMIN_LOG);
  53. if (defined('STDERR')) {
  54. fwrite(STDERR, 'Write access problem in ' . join_path(USERS_PATH, $user, 'log.txt') . "\n");
  55. }
  56. }
  57. }
  58. Minz_Log::notice('FreshRSS actualize done.', ADMIN_LOG);
  59. if (defined('STDOUT')) {
  60. fwrite(STDOUT, 'Done.' . "\n");
  61. $end_date = date_create('now');
  62. $duration = date_diff($end_date, $begin_date);
  63. fwrite(STDOUT, 'Ending feed actualization at ' . $end_date->format('c') . "\n"); //Unbuffered
  64. 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
  65. }
  66. echo 'End.', "\n";
  67. ob_end_flush();