summaryrefslogtreecommitdiff
path: root/classes/rssutils.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/rssutils.php')
-rwxr-xr-xclasses/rssutils.php121
1 files changed, 67 insertions, 54 deletions
diff --git a/classes/rssutils.php b/classes/rssutils.php
index 6479d9f97..11a94162c 100755
--- a/classes/rssutils.php
+++ b/classes/rssutils.php
@@ -53,48 +53,54 @@ class RSSUtils {
}
static function update_daemon_common($limit = null, $options = []) {
- $schema_version = get_schema_version();
-
if (!$limit) $limit = Config::get(Config::DAEMON_FEED_LIMIT);
- if ($schema_version != SCHEMA_VERSION) {
+ if (get_schema_version() != SCHEMA_VERSION) {
die("Schema version is wrong, please upgrade the database.\n");
}
$pdo = Db::pdo();
if (!Config::get(Config::SINGLE_USER_MODE) && Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT) > 0) {
+ $login_limit = (int) Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT);
+
if (Config::get(Config::DB_TYPE) == "pgsql") {
- $login_thresh_qpart = "AND ttrss_users.last_login >= NOW() - INTERVAL '".Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT)." days'";
+ $login_thresh_qpart = "AND last_login >= NOW() - INTERVAL '$login_limit days'";
} else {
- $login_thresh_qpart = "AND ttrss_users.last_login >= DATE_SUB(NOW(), INTERVAL ".Config::get(Config::DAEMON_UPDATE_LOGIN_LIMIT)." DAY)";
+ $login_thresh_qpart = "AND last_login >= DATE_SUB(NOW(), INTERVAL $login_limit DAY)";
}
} else {
$login_thresh_qpart = "";
}
+ $default_interval = (int) Prefs::get_default(Prefs::DEFAULT_UPDATE_INTERVAL);
+
if (Config::get(Config::DB_TYPE) == "pgsql") {
$update_limit_qpart = "AND ((
- ttrss_feeds.update_interval = 0
- AND ttrss_user_prefs.value != '-1'
- AND last_updated < NOW() - CAST((ttrss_user_prefs.value || ' minutes') AS INTERVAL)
+ update_interval = 0
+ AND p.value != '-1'
+ AND last_updated < NOW() - CAST((COALESCE(p.value, '$default_interval') || ' minutes') AS INTERVAL)
+ ) OR (
+ update_interval > 0
+ AND last_updated < NOW() - CAST((update_interval || ' minutes') AS INTERVAL)
) OR (
- ttrss_feeds.update_interval > 0
- AND last_updated < NOW() - CAST((ttrss_feeds.update_interval || ' minutes') AS INTERVAL)
- ) OR ((last_updated = '1970-01-01 00:00:00' OR last_updated IS NULL)
- AND ttrss_feeds.update_interval >= 0
- AND ttrss_user_prefs.value != '-1'))";
+ update_interval >= 0
+ AND p.value != '-1'
+ AND (last_updated = '1970-01-01 00:00:00' OR last_updated IS NULL)
+ ))";
} else {
$update_limit_qpart = "AND ((
- ttrss_feeds.update_interval = 0
- AND ttrss_user_prefs.value != '-1'
- AND last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(ttrss_user_prefs.value, SIGNED INTEGER) MINUTE)
+ update_interval = 0
+ AND p.value != '-1'
+ AND last_updated < DATE_SUB(NOW(), INTERVAL CONVERT(COALESCE(p.value, '$default_interval'), SIGNED INTEGER) MINUTE)
) OR (
- ttrss_feeds.update_interval > 0
- AND last_updated < DATE_SUB(NOW(), INTERVAL ttrss_feeds.update_interval MINUTE)
- ) OR ((last_updated = '1970-01-01 00:00:00' OR last_updated IS NULL)
- AND ttrss_feeds.update_interval >= 0
- AND ttrss_user_prefs.value != '-1'))";
+ update_interval > 0
+ AND last_updated < DATE_SUB(NOW(), INTERVAL update_interval MINUTE)
+ ) OR (
+ update_interval >= 0
+ AND p.value != '-1'
+ AND (last_updated = '1970-01-01 00:00:00' OR last_updated IS NULL)
+ ))";
}
// Test if feed is currently being updated by another process.
@@ -108,20 +114,23 @@ class RSSUtils {
// Update the least recently updated feeds first
$query_order = "ORDER BY last_updated";
- if (Config::get(Config::DB_TYPE) == "pgsql") $query_order .= " NULLS FIRST";
- $query = "SELECT DISTINCT ttrss_feeds.feed_url, ttrss_feeds.last_updated
+ if (Config::get(Config::DB_TYPE) == "pgsql")
+ $query_order .= " NULLS FIRST";
+
+ $query = "SELECT f.feed_url, f.last_updated
FROM
- ttrss_feeds, ttrss_users, ttrss_user_prefs
+ ttrss_feeds f, ttrss_users u LEFT JOIN ttrss_user_prefs2 p ON
+ (p.owner_uid = u.id AND profile IS NULL AND pref_name = 'DEFAULT_UPDATE_INTERVAL')
WHERE
- ttrss_feeds.owner_uid = ttrss_users.id
- AND ttrss_user_prefs.profile IS NULL
- AND ttrss_users.id = ttrss_user_prefs.owner_uid
- AND ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL'
- $login_thresh_qpart $update_limit_qpart
+ f.owner_uid = u.id
+ $login_thresh_qpart
+ $update_limit_qpart
$updstart_thresh_qpart
$query_order $query_limit";
+ //print "$query\n";
+
$res = $pdo->query($query);
$feeds_to_update = array();
@@ -144,34 +153,38 @@ class RSSUtils {
$nf = 0;
$bstarted = microtime(true);
- $batch_owners = array();
+ $batch_owners = [];
- // since we have the data cached, we can deal with other feeds with the same url
- $usth = $pdo->prepare("SELECT
- DISTINCT ttrss_feeds.id,
+ $user_query = "SELECT f.id,
last_updated,
- ttrss_feeds.owner_uid,
- ttrss_feeds.title
- FROM ttrss_feeds, ttrss_users, ttrss_user_prefs WHERE
- ttrss_user_prefs.owner_uid = ttrss_feeds.owner_uid AND
- ttrss_users.id = ttrss_user_prefs.owner_uid AND
- ttrss_user_prefs.pref_name = 'DEFAULT_UPDATE_INTERVAL' AND
- ttrss_user_prefs.profile IS NULL AND
- feed_url = ?
- $update_limit_qpart
+ f.owner_uid,
+ u.login AS owner,
+ f.title
+ FROM ttrss_feeds f, ttrss_users u LEFT JOIN ttrss_user_prefs2 p ON
+ (p.owner_uid = u.id AND profile IS NULL AND pref_name = 'DEFAULT_UPDATE_INTERVAL')
+ WHERE
+ f.owner_uid = u.id
+ AND feed_url = :feed
$login_thresh_qpart
- ORDER BY ttrss_feeds.id $query_limit");
+ $update_limit_qpart
+ ORDER BY f.id $query_limit";
+
+ //print "$user_query\n";
+
+ // since we have feed xml cached, we can deal with other feeds with the same url
+ $usth = $pdo->prepare($user_query);
foreach ($feeds_to_update as $feed) {
Debug::log("Base feed: $feed");
- $usth->execute([$feed]);
+ $usth->execute(["feed" => $feed]);
if ($tline = $usth->fetch()) {
- Debug::log(sprintf("=> %s (ID: %d, UID: %d), last updated: %s", $tline["title"], $tline["id"], $tline["owner_uid"],
+ Debug::log(sprintf("=> %s (ID: %d, U: %s [%d]), last updated: %s", $tline["title"], $tline["id"],
+ $tline["owner"], $tline["owner_uid"],
$tline["last_updated"] ? $tline["last_updated"] : "never"));
- if (array_search($tline["owner_uid"], $batch_owners) === false)
+ if (!in_array($tline["owner_uid"], $batch_owners))
array_push($batch_owners, $tline["owner_uid"]);
$fstarted = microtime(true);
@@ -201,7 +214,7 @@ class RSSUtils {
Debug::log("!! Last error: $error_message");
- Logger::get()->log(E_USER_NOTICE,
+ Logger::log(E_USER_NOTICE,
sprintf("Update process for feed %d (%s, owner UID: %d) failed with exit code: %d (%s).",
$tline["id"], clean($tline["title"]), $tline["owner_uid"], $exit_code, clean($error_message)));
@@ -218,7 +231,7 @@ class RSSUtils {
if (!self::update_rss_feed($tline["id"], true)) {
global $fetch_last_error;
- Logger::get()->log(E_USER_NOTICE,
+ Logger::log(E_USER_NOTICE,
sprintf("Update request for feed %d (%s, owner UID: %d) failed: %s.",
$tline["id"], clean($tline["title"]), $tline["owner_uid"], clean($fetch_last_error)));
}
@@ -226,7 +239,7 @@ class RSSUtils {
Debug::log(sprintf("<= %.4f (sec) (not using a separate process)", microtime(true) - $fstarted));
} catch (PDOException $e) {
- Logger::get()->log_error(E_USER_WARNING, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
+ Logger::log_error(E_USER_WARNING, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
try {
$pdo->rollback();
@@ -275,7 +288,7 @@ class RSSUtils {
$fetch_url = $row["feed_url"];
$pluginhost = new PluginHost();
- $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
+ $user_plugins = get_pref(Prefs::_ENABLED_PLUGINS, $owner_uid);
$pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL);
$pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid);
@@ -386,7 +399,7 @@ class RSSUtils {
$feed_language = mb_strtolower($row["feed_language"]);
if (!$feed_language)
- $feed_language = mb_strtolower(get_pref('DEFAULT_SEARCH_LANGUAGE', $owner_uid));
+ $feed_language = mb_strtolower(get_pref(Prefs::DEFAULT_SEARCH_LANGUAGE, $owner_uid));
if (!$feed_language)
$feed_language = 'simple';
@@ -400,7 +413,7 @@ class RSSUtils {
$cache_filename = Config::get(Config::CACHE_DIR) . "/feeds/" . sha1($fetch_url) . ".xml";
$pluginhost = new PluginHost();
- $user_plugins = get_pref("_ENABLED_PLUGINS", $owner_uid);
+ $user_plugins = get_pref(Prefs::_ENABLED_PLUGINS, $owner_uid);
$pluginhost->load(Config::get(Config::PLUGINS), PluginHost::KIND_ALL);
$pluginhost->load((string)$user_plugins, PluginHost::KIND_USER, $owner_uid);
@@ -1193,7 +1206,7 @@ class RSSUtils {
$boring_tags = array_map('trim',
explode(",", mb_strtolower(
- get_pref('BLACKLISTED_TAGS', $owner_uid))));
+ get_pref(Prefs::BLACKLISTED_TAGS, $owner_uid))));
$entry_tags = FeedItem_Common::normalize_categories(
array_unique(
@@ -1604,7 +1617,7 @@ class RSSUtils {
$sth->execute();
while ($row = $sth->fetch()) {
- Logger::get()->log(E_USER_NOTICE,
+ Logger::log(E_USER_NOTICE,
sprintf("Auto disabling feed %d (%s, UID: %d) because it failed to update for %d days.",
$row["id"], clean($row["title"]), $row["owner_uid"], Config::get(Config::DAEMON_UNSUCCESSFUL_DAYS_LIMIT)));