]> git.wh0rd.org - tt-rss.git/blobdiff - classes/rssutils.php
rssutils: forbid question marks in tsvector data, PDO gets confused sometimes even...
[tt-rss.git] / classes / rssutils.php
index 349f859961bf82c5ac7e4a6181da6357ae0aa539..98f494d706b84d675feab579607a9e853e1ad9ad 100644 (file)
@@ -221,7 +221,7 @@ class RSSUtils {
 
                        $owner_uid = $row["owner_uid"];
 
-                       $auth_pass_encrypted = sql_bool_to_bool($row["auth_pass_encrypted"]);
+                       $auth_pass_encrypted = $row["auth_pass_encrypted"];
 
                        $auth_login = $row["auth_login"];
                        $auth_pass = $row["auth_pass"];
@@ -341,8 +341,8 @@ class RSSUtils {
                if ($row = $sth->fetch()) {
 
                        $owner_uid = $row["owner_uid"];
-                       $mark_unread_on_update = sql_bool_to_bool($row["mark_unread_on_update"]);
-                       $auth_pass_encrypted = sql_bool_to_bool($row["auth_pass_encrypted"]);
+                       $mark_unread_on_update = $row["mark_unread_on_update"];
+                       $auth_pass_encrypted = $row["auth_pass_encrypted"];
 
                        $sth = $pdo->prepare("UPDATE ttrss_feeds SET last_update_started = NOW()
                                WHERE id = ?");
@@ -358,7 +358,7 @@ class RSSUtils {
 
                        $stored_last_modified = $row["last_modified"];
                        $last_unconditional = $row["last_unconditional"];
-                       $cache_images = sql_bool_to_bool($row["cache_images"]);
+                       $cache_images = $row["cache_images"];
                        $fetch_url = $row["feed_url"];
                        $feed_language = mb_strtolower($row["feed_language"]);
                        if (!$feed_language) $feed_language = 'english';
@@ -515,7 +515,7 @@ class RSSUtils {
                        $sth->execute([$feed]);
 
                        if ($row = $sth->fetch()) {
-                               $favicon_needs_check = sql_bool_to_bool($row["favicon_needs_check"]);
+                               $favicon_needs_check = $row["favicon_needs_check"];
                                $favicon_avg_color = $row["favicon_avg_color"];
                                $owner_uid = $row["owner_uid"];
                        } else {
@@ -591,19 +591,26 @@ class RSSUtils {
                        $tstart = time();
 
                        foreach ($items as $item) {
+                               $pdo->beginTransaction();
+
                                if ($_REQUEST['xdebug'] == 3) {
                                        print_r($item);
                                }
 
                                if (ini_get("max_execution_time") > 0 && time() - $tstart >= ini_get("max_execution_time") * 0.7) {
                                        _debug("looks like there's too many articles to process at once, breaking out", $debug_enabled);
+                                       $pdo->commit();
                                        break;
                                }
 
                                $entry_guid = strip_tags($item->get_id());
                                if (!$entry_guid) $entry_guid = strip_tags($item->get_link());
                                if (!$entry_guid) $entry_guid = RSSUtils::make_guid_from_title($item->get_title());
-                               if (!$entry_guid) continue;
+
+                               if (!$entry_guid) {
+                                       $pdo->commit();
+                                       continue;
+                               }
 
                                $entry_guid = "$owner_uid,$entry_guid";
 
@@ -727,6 +734,7 @@ class RSSUtils {
                                                WHERE id = ?");
                                        $sth->execute([$base_entry_id]);
 
+                                       $pdo->commit();
                                        continue;
                                }
 
@@ -875,7 +883,7 @@ class RSSUtils {
                                                        $entry_current_hash,
                                                        $date_feed_processed,
                                                        $entry_comments,
-                                                       $num_comments,
+                                                       (int)$num_comments,
                                                        $entry_plugin_data,
                                                        $entry_language,
                                                        $entry_author]);
@@ -895,6 +903,7 @@ class RSSUtils {
                                        $entry_ref_id = $ref_id;
 
                                        if (RSSUtils::find_article_filter($article_filters, "filter")) {
+                                               $pdo->commit();
                                                continue;
                                        }
 
@@ -964,29 +973,39 @@ class RSSUtils {
                                        _debug("resulting RID: $entry_ref_id, IID: $entry_int_id", $debug_enabled);
 
                                        if (DB_TYPE == "pgsql") {
-                                               $tsvector_combined = mb_substr($entry_title . ' ' . strip_tags(str_replace('<', ' <', $entry_content)),
+                                               $tsvector_combined = mb_substr($entry_title . ' ' .
+                                                       preg_replace('/[<\?\:]/', ' ', strip_tags($entry_content)),
                                                        0, 1000000);
 
-                                               $tsvector_qpart = "tsvector_combined = to_tsvector('$feed_language', ".$pdo->quote($tsvector_combined)."),";
+                                               $tsvector_qpart = "tsvector_combined = to_tsvector(".$pdo->quote($feed_language).", ".$pdo->quote($tsvector_combined)."),";
 
                                        } else {
                                                $tsvector_qpart = "";
                                        }
 
+                                       //_debug($tsvector_qpart);
+
                                        $sth = $pdo->prepare("UPDATE ttrss_entries
-                                               SET title = ?,
-                                                       content = ?,
-                                                       content_hash = ?,
-                                                       updated = ?,
+                                               SET title = :title,
                                                        $tsvector_qpart
-                                                       num_comments = ?,
-                                                       plugin_data = ?,
-                                                       author = ?,
-                                                       lang = ?
-                                               WHERE id = ?");
-
-                                       $sth->execute([$entry_title, $entry_content, $entry_current_hash, $entry_timestamp_fmt,
-                                               $num_comments, $entry_plugin_data, $entry_author, $entry_language, $ref_id]);
+                                                       content = :content,
+                                                       content_hash = :content_hash,
+                                                       updated = :updated,
+                                                       num_comments = :num_comments,
+                                                       plugin_data = :plugin_data,
+                                                       author = :author,
+                                                       lang = :lang                                                                                                            
+                                               WHERE id = :id");
+
+                                       $sth->execute([":title" => $entry_title,
+                                               ":content" => $entry_content,
+                                               ":content_hash" => $entry_current_hash,
+                                               ":updated" => $entry_timestamp_fmt,
+                                               ":num_comments" => (int)$num_comments,
+                                               ":plugin_data" => $entry_plugin_data,
+                                               ":author" => $entry_author,
+                                               ":lang" => $entry_language,
+                                               ":id" => $ref_id]);
 
                                        // update aux data
                                        $sth = $pdo->prepare("UPDATE ttrss_user_entries
@@ -1048,7 +1067,7 @@ class RSSUtils {
                                foreach ($enclosures as $enc) {
                                        $enc_url = $enc[0];
                                        $enc_type = $enc[1];
-                                       $enc_dur = $enc[2];
+                                       $enc_dur = (int)$enc[2];
                                        $enc_title = $enc[3];
                                        $enc_width = intval($enc[4]);
                                        $enc_height = intval($enc[5]);
@@ -1138,6 +1157,8 @@ class RSSUtils {
                                }
 
                                _debug("article processed", $debug_enabled);
+
+                               $pdo->commit();
                        }
 
                        _debug("purging feed...", $debug_enabled);