]> git.wh0rd.org - tt-rss.git/blobdiff - classes/rssutils.php
remove cache/simplepie
[tt-rss.git] / classes / rssutils.php
index bd20a6b480154195fa116502e1a396a168ca2cdd..e76dd3e78b4e94c3f14be79bc5d1d30ec59a20cd 100755 (executable)
@@ -50,8 +50,8 @@ class RSSUtils {
                        if (!$tmph->fetch()) {
 
                                $tmph = $pdo->prepare("INSERT INTO ttrss_feedbrowser_cache
-                                       (feed_url, site_url, title, subscribers) 
-                                       VALUES 
+                                       (feed_url, site_url, title, subscribers)
+                                       VALUES
                                        (?, ?, ?, ?)");
 
                                $tmph->execute([$feed_url, $site_url, $title, $subscribers]);
@@ -187,7 +187,19 @@ class RSSUtils {
                                        array_push($batch_owners, $tline["owner_uid"]);
 
                                $fstarted = microtime(true);
-                               RSSUtils::update_rss_feed($tline["id"], true, false);
+
+                               try {
+                                       RSSUtils::update_rss_feed($tline["id"], true, false);
+                               } catch (PDOException $e) {
+                                       Logger::get()->log_error(E_USER_NOTICE, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString());
+
+                                       try {
+                                               $pdo->rollback();
+                                       } catch (PDOException $e) {
+                                               // it doesn't matter if there wasn't actually anything to rollback, PDO Exception can be
+                                               // thrown outside of an active transaction during feed update
+                                       }
+                               }
                                _debug_suppress(false);
 
                                _debug(sprintf("    %.4f (sec)", microtime(true) - $fstarted));
@@ -328,12 +340,12 @@ class RSSUtils {
                $sth = $pdo->prepare("SELECT id,update_interval,auth_login,
                        feed_url,auth_pass,cache_images,
                        mark_unread_on_update, owner_uid,
-                       auth_pass_encrypted, feed_language, 
-                       last_modified, 
-                       ".SUBSTRING_FOR_DATE."(last_unconditional, 1, 19) AS last_unconditional                 
+                       auth_pass_encrypted, feed_language,
+                       last_modified,
+                       ".SUBSTRING_FOR_DATE."(last_unconditional, 1, 19) AS last_unconditional
                        FROM ttrss_feeds WHERE id = ?");
                $sth->execute([$feed]);
-               
+
                if ($row = $sth->fetch()) {
 
                        $owner_uid = $row["owner_uid"];
@@ -847,7 +859,7 @@ class RSSUtils {
 
                                        $usth = $pdo->prepare(
                                                "INSERT INTO ttrss_entries
-                                                       (title, 
+                                                       (title,
                                                        guid,
                                                        link,
                                                        updated,
@@ -916,7 +928,7 @@ class RSSUtils {
 
                                                _debug("user record FOUND: RID: $entry_ref_id, IID: $entry_int_id", $debug_enabled);
                                        } else {
-                                               
+
                                                _debug("user record not found, creating...", $debug_enabled);
 
                                                if ($score >= -500 && !RSSUtils::find_article_filter($article_filters, 'catchup') && !$entry_force_catchup) {
@@ -979,7 +991,7 @@ class RSSUtils {
                                                        num_comments = :num_comments,
                                                        plugin_data = :plugin_data,
                                                        author = :author,
-                                                       lang = :lang                                                                                                            
+                                                       lang = :lang
                                                WHERE id = :id");
 
                                        $params = [":title" => $entry_title,
@@ -1060,7 +1072,7 @@ class RSSUtils {
                                }
 
                                $esth = $pdo->prepare("SELECT id FROM ttrss_enclosures
-                                               WHERE content_url = ? AND post_id = ?");
+                                               WHERE content_url = ? AND content_type = ? AND post_id = ?");
 
                                $usth = $pdo->prepare("INSERT INTO ttrss_enclosures
                                                        (content_url, content_type, title, duration, post_id, width, height) VALUES
@@ -1074,7 +1086,7 @@ class RSSUtils {
                                        $enc_width = intval($enc[4]);
                                        $enc_height = intval($enc[5]);
 
-                                       $esth->execute([$enc_url, $entry_ref_id]);
+                                       $esth->execute([$enc_url, $enc_type, $entry_ref_id]);
 
                                        if (!$esth->fetch()) {
                                                $usth->execute([$enc_url, $enc_type, (string)$enc_title, $enc_dur, $entry_ref_id, $enc_width, $enc_height]);
@@ -1213,7 +1225,7 @@ class RSSUtils {
                                        if ($file_content && strlen($file_content) > MIN_CACHE_FILE_SIZE) {
                                                file_put_contents($local_filename, $file_content);
                                        }
-                               } else {
+                               } else if (is_writable($local_filename)) {
                                        touch($local_filename);
                                }
                        }
@@ -1239,15 +1251,17 @@ class RSSUtils {
 
                                $local_filename = CACHE_DIR . "/images/" . sha1($src);
 
-                               if ($debug) _debug("cache_media: downloading: $src to $local_filename");
+                               if ($debug) _debug("cache_media: checking $src");
 
                                if (!file_exists($local_filename)) {
+                                       if ($debug) _debug("cache_media: downloading: $src to $local_filename");
+
                                        $file_content = fetch_file_contents($src);
 
                                        if ($file_content && strlen($file_content) > MIN_CACHE_FILE_SIZE) {
                                                file_put_contents($local_filename, $file_content);
                                        }
-                               } else {
+                               } else if (is_writable($local_filename)) {
                                        touch($local_filename);
                                }
                        }
@@ -1290,7 +1304,7 @@ class RSSUtils {
        }
 
        static function expire_cached_files($debug) {
-               foreach (array("simplepie", "feeds", "images", "export", "upload") as $dir) {
+               foreach (array("feeds", "images", "export", "upload") as $dir) {
                        $cache_dir = CACHE_DIR . "/$dir";
 
 //                     if ($debug) _debug("Expiring $cache_dir");