use hashed guids in a hopefully backwards compatible fashion

This commit is contained in:
Andrew Dolgov 2013-04-15 19:28:11 +04:00
parent bc7a144dd5
commit 5e3d5480f7
2 changed files with 22 additions and 12 deletions

View File

@ -88,7 +88,7 @@ class Article extends Handler_Protected {
static function create_published_article($link, $title, $url, $content, $labels_str, static function create_published_article($link, $title, $url, $content, $labels_str,
$owner_uid) { $owner_uid) {
$guid = sha1($url . $owner_uid); // include owner_uid to prevent global GUID clash $guid = 'SHA1:' . sha1("ttshared:" . $url . $owner_uid); // include owner_uid to prevent global GUID clash
$content_hash = sha1($content); $content_hash = sha1($content);
if ($labels_str != "") { if ($labels_str != "") {

View File

@ -517,14 +517,16 @@
if (!$entry_guid) $entry_guid = $item->get_link(); if (!$entry_guid) $entry_guid = $item->get_link();
if (!$entry_guid) $entry_guid = make_guid_from_title($item->get_title()); if (!$entry_guid) $entry_guid = make_guid_from_title($item->get_title());
if ($debug_enabled) {
_debug("update_rss_feed: guid $entry_guid");
}
if (!$entry_guid) continue; if (!$entry_guid) continue;
$entry_guid = "$owner_uid,$entry_guid"; $entry_guid = "$owner_uid,$entry_guid";
$entry_guid_hashed = db_escape_string($link, 'SHA1:' . sha1($entry_guid));
if ($debug_enabled) {
_debug("update_rss_feed: guid $entry_guid / $entry_guid_hashed");
}
$entry_timestamp = ""; $entry_timestamp = "";
$entry_timestamp = strtotime($item->get_date()); $entry_timestamp = strtotime($item->get_date());
@ -633,7 +635,7 @@
// FIXME not sure if owner_uid is a good idea here, we may have a base entry without user entry (?) // FIXME not sure if owner_uid is a good idea here, we may have a base entry without user entry (?)
$result = db_query($link, "SELECT plugin_data,title,content,link,tag_cache,author FROM ttrss_entries, ttrss_user_entries $result = db_query($link, "SELECT plugin_data,title,content,link,tag_cache,author FROM ttrss_entries, ttrss_user_entries
WHERE ref_id = id AND guid = '".db_escape_string($link, $entry_guid)."' AND owner_uid = $owner_uid"); WHERE ref_id = id AND (guid = '".db_escape_string($link, $entry_guid)."' OR guid = '$entry_guid_hashed') AND owner_uid = $owner_uid");
if (db_num_rows($result) != 0) { if (db_num_rows($result) != 0) {
$entry_plugin_data = db_fetch_result($result, 0, "plugin_data"); $entry_plugin_data = db_fetch_result($result, 0, "plugin_data");
@ -684,7 +686,7 @@
db_query($link, "BEGIN"); db_query($link, "BEGIN");
$result = db_query($link, "SELECT id FROM ttrss_entries $result = db_query($link, "SELECT id FROM ttrss_entries
WHERE guid = '$entry_guid'"); WHERE (guid = '$entry_guid' OR guid = '$entry_guid_hashed')");
if (db_num_rows($result) == 0) { if (db_num_rows($result) == 0) {
@ -712,7 +714,7 @@
author) author)
VALUES VALUES
('$entry_title', ('$entry_title',
'$entry_guid', '$entry_guid_hashed',
'$entry_link', '$entry_link',
'$entry_timestamp_fmt', '$entry_timestamp_fmt',
'$entry_content', '$entry_content',
@ -745,13 +747,13 @@
// now it should exist, if not - bad luck then // now it should exist, if not - bad luck then
$result = db_query($link, "SELECT $result = db_query($link, "SELECT
id,content_hash,no_orig_date,title,plugin_data, id,content_hash,no_orig_date,title,plugin_data,guid,
".SUBSTRING_FOR_DATE."(date_updated,1,19) as date_updated, ".SUBSTRING_FOR_DATE."(date_updated,1,19) as date_updated,
".SUBSTRING_FOR_DATE."(updated,1,19) as updated, ".SUBSTRING_FOR_DATE."(updated,1,19) as updated,
num_comments num_comments
FROM FROM
ttrss_entries ttrss_entries
WHERE guid = '$entry_guid'"); WHERE guid = '$entry_guid' OR guid = '$entry_guid_hashed'");
$entry_ref_id = 0; $entry_ref_id = 0;
$entry_int_id = 0; $entry_int_id = 0;
@ -759,7 +761,7 @@
if (db_num_rows($result) == 1) { if (db_num_rows($result) == 1) {
if ($debug_enabled) { if ($debug_enabled) {
_debug("update_rss_feed: base guid [$entry_guid] found, checking for user record"); _debug("update_rss_feed: base guid found, checking for user record");
} }
// this will be used below in update handler // this will be used below in update handler
@ -773,6 +775,14 @@
$ref_id = db_fetch_result($result, 0, "id"); $ref_id = db_fetch_result($result, 0, "id");
$entry_ref_id = $ref_id; $entry_ref_id = $ref_id;
/* $stored_guid = db_fetch_result($result, 0, "guid");
if ($stored_guid != $entry_guid_hashed) {
if ($debug_enabled) _debug("upgrading compat guid to hashed one");
db_query($link, "UPDATE ttrss_entries SET guid = '$entry_guid_hashed' WHERE
id = '$ref_id'");
} */
// check for user post link to main table // check for user post link to main table
// do we allow duplicate posts with same GUID in different feeds? // do we allow duplicate posts with same GUID in different feeds?
@ -933,7 +943,7 @@
if ($post_needs_update) { if ($post_needs_update) {
if (defined('DAEMON_EXTENDED_DEBUG')) { if (defined('DAEMON_EXTENDED_DEBUG')) {
_debug("update_rss_feed: post $entry_guid needs update..."); _debug("update_rss_feed: post $entry_guid_hashed needs update...");
} }
// print "<!-- post $orig_title needs update : $post_needs_update -->"; // print "<!-- post $orig_title needs update : $post_needs_update -->";