aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-09-24 20:43:52 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-09-24 20:43:52 +0200
commit0a79d4085b18c5607438f8ebd56543508e7db3a8 (patch)
treec411c89cdaaa8709e23a800bbe118aa93d149aac
parent6a812b0d31df275d9b8b211a90628400ee097644 (diff)
Refactor controller for actualize feed
-rwxr-xr-xapp/Controllers/feedController.php46
-rw-r--r--lib/lib_rss.php2
-rw-r--r--p/api/pshb.php7
3 files changed, 28 insertions, 27 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 0364424f5..25d504480 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -261,33 +261,18 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
}
- /**
- * This action actualizes entries from one or several feeds.
- *
- * Parameters are:
- * - id (default: false): Feed ID
- * - url (default: false): Feed URL
- * - force (default: false)
- * If id and url are not specified, all the feeds are actualized. But if force is
- * false, process stops at 10 feeds to avoid time execution problem.
- */
- public function actualizeAction($simplePiePush = null) {
+ public static function actualizeFeed($feed_id, $feed_url, $force, $simplePiePush = null) {
@set_time_limit(300);
$feedDAO = FreshRSS_Factory::createFeedDao();
$entryDAO = FreshRSS_Factory::createEntryDao();
- Minz_Session::_param('actualize_feeds', false);
- $id = Minz_Request::param('id');
- $url = Minz_Request::param('url');
- $force = Minz_Request::param('force');
-
// Create a list of feeds to actualize.
- // If id is set and valid, corresponding feed is added to the list but
+ // If feed_id is set and valid, corresponding feed is added to the list but
// alone in order to automatize further process.
$feeds = array();
- if ($id || $url) {
- $feed = $id ? $feedDAO->searchById($id) : $feedDAO->searchByUrl($url);
+ if ($feed_id > 0 || $feed_url) {
+ $feed = $feed_id > 0 ? $feedDAO->searchById($feed_id) : $feedDAO->searchByUrl($feed_url);
if ($feed) {
$feeds[] = $feed;
}
@@ -309,7 +294,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$url = $feed->url(); //For detection of HTTP 301
$pubSubHubbubEnabled = $pubsubhubbubEnabledGeneral && $feed->pubSubHubbubEnabled();
- if ((!$simplePiePush) && (!$id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) {
+ if ((!$simplePiePush) && (!$feed_id) && $pubSubHubbubEnabled && ($feed->lastUpdate() > $pshbMinAge)) {
//$text = 'Skip pull of feed using PubSubHubbub: ' . $url;
//Minz_Log::debug($text);
//file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND);
@@ -464,6 +449,26 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
break;
}
}
+ return array($updated_feeds, reset($feeds));
+ }
+
+ /**
+ * This action actualizes entries from one or several feeds.
+ *
+ * Parameters are:
+ * - id (default: false): Feed ID
+ * - url (default: false): Feed URL
+ * - force (default: false)
+ * If id and url are not specified, all the feeds are actualized. But if force is
+ * false, process stops at 10 feeds to avoid time execution problem.
+ */
+ public function actualizeAction() {
+ Minz_Session::_param('actualize_feeds', false);
+ $id = Minz_Request::param('id');
+ $url = Minz_Request::param('url');
+ $force = Minz_Request::param('force');
+
+ list($updated_feeds, $feed) = self::actualizeFeed($id, $url, $force);
if (Minz_Request::param('ajax')) {
// Most of the time, ajax request is for only one feed. But since
@@ -479,7 +484,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
} else {
// Redirect to the main page with correct notification.
if ($updated_feeds === 1) {
- $feed = reset($feeds);
Minz_Request::good(_t('feedback.sub.feed.actualized', $feed->name()), array(
'params' => array('get' => 'f_' . $feed->id())
));
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 82ddced2c..a4cd8e782 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -165,7 +165,7 @@ function customSimplePie() {
$system_conf = Minz_Configuration::get('system');
$limits = $system_conf->limits;
$simplePie = new SimplePie();
- $simplePie->set_useragent(_t('gen.freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
+ $simplePie->set_useragent('FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
$simplePie->set_syslog($system_conf->simplepie_syslog_enabled);
$simplePie->set_cache_location(CACHE_PATH);
$simplePie->set_cache_duration($limits['cache_duration']);
diff --git a/p/api/pshb.php b/p/api/pshb.php
index 650767114..94a0068ed 100644
--- a/p/api/pshb.php
+++ b/p/api/pshb.php
@@ -88,9 +88,6 @@ if ($ORIGINAL_INPUT == '') {
Minz_Configuration::register('system', DATA_PATH . '/config.php', DATA_PATH . '/config.default.php');
$system_conf = Minz_Configuration::get('system');
$system_conf->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
-Minz_Translate::init('en');
-Minz_Request::_param('ajax', true);
-$feedController = new FreshRSS_feed_Controller();
$simplePie = customSimplePie();
$simplePie->set_raw_data($ORIGINAL_INPUT);
@@ -106,7 +103,6 @@ if ($self !== base64url_decode($canonical64)) {
//die('Self URL does not match registered canonical URL!');
$self = base64url_decode($canonical64);
}
-Minz_Request::_param('url', $self);
$nb = 0;
foreach ($users as $userFilename) {
@@ -121,7 +117,8 @@ foreach ($users as $userFilename) {
join_path(USERS_PATH, $username, 'config.php'),
join_path(USERS_PATH, '_', 'config.default.php'));
FreshRSS_Context::init();
- if ($feedController->actualizeAction($simplePie) > 0) {
+ list($updated_feeds, $feed) = FreshRSS_feed_Controller::actualizeFeed(0, $self, false, $simplePie);
+ if ($updated_feeds > 0) {
$nb++;
}
} catch (Exception $e) {