From 26e1c4d458d229b3a6497413c17b74e28a0f9d64 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 3 May 2016 19:20:58 +0200 Subject: [PATCH] Avoid SQL errors because of existing entries --- include/oembed.php | 9 ++++++--- mod/parse_url.php | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/oembed.php b/include/oembed.php index b1770f6890..c362ab45e6 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -75,10 +75,13 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){ else { //save in cache $j = json_decode($txt); if ($j->type != "error") - q("INSERT INTO `oembed` (`url`, `content`, `created`) VALUES ('%s', '%s', '%s')", - dbesc(normalise_link($embedurl)), dbesc($txt), dbesc(datetime_convert())); + q("INSERT INTO `oembed` (`url`, `content`, `created`) VALUES ('%s', '%s', '%s') + ON DUPLICATE KEY UPDATE `content` = '%s', `created` = '%s'", + dbesc(normalise_link($embedurl)), + dbesc($txt), dbesc(datetime_convert()), + dbesc($txt), dbesc(datetime_convert())); - Cache::set($a->videowidth . $embedurl,$txt, CACHE_DAY); + Cache::set($a->videowidth.$embedurl,$txt, CACHE_DAY); } } diff --git a/mod/parse_url.php b/mod/parse_url.php index 6a1fc11010..df5436b626 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -72,8 +72,11 @@ function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = tr $data = parseurl_getsiteinfo($url, $no_guessing, $do_oembed); - q("INSERT INTO `parsed_url` (`url`, `guessing`, `oembed`, `content`, `created`) VALUES ('%s', %d, %d, '%s', '%s')", - dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed), dbesc(serialize($data)), dbesc(datetime_convert())); + q("INSERT INTO `parsed_url` (`url`, `guessing`, `oembed`, `content`, `created`) VALUES ('%s', %d, %d, '%s', '%s') + ON DUPLICATE KEY UPDATE `content` = '%s', `created` = '%s'", + dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed), + dbesc(serialize($data)), dbesc(datetime_convert()), + dbesc(serialize($data)), dbesc(datetime_convert())); return $data; } -- 2.39.5