From 28948ca4b4ec25aaa3b677441a1545e6897fd9a4 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Wed, 28 Oct 2015 22:21:37 +0100
Subject: [PATCH] refresh when trying to insert a duplicate

---
 lib/sites/parser.pm | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/sites/parser.pm b/lib/sites/parser.pm
index e29343a..bd481dd 100644
--- a/lib/sites/parser.pm
+++ b/lib/sites/parser.pm
@@ -74,7 +74,8 @@ sub parse {
             eval {
                 my $sth = $dbh->prepare('
                     INSERT INTO playbot (type, url, sender, title, duration)
-                    VALUES (?,?,?,?,?)');
+                    VALUES (?,?,?,?,?)
+                ');
 		        $log->error("Couldn't prepare querie; aborting") unless (defined $sth);
 
 		        $sth->execute($content{'site'}, $content{'url'},
@@ -83,7 +84,22 @@ sub parse {
             if ($@) {
                 # seems to be already present in database 
                 $new = 0;
-			    $log->error("Couldn't finish transaction: " . $@);
+
+                my $sth = $dbh->prepare('
+                    UPDATE playbot playbot SET
+                    sender = ?,
+                    title = ?,
+                    duration = ?
+                    WHERE url = ?
+                ');
+		        $log->error("Couldn't prepare querie; aborting") unless (defined $sth);
+
+		        $sth->execute(
+                    $content{'author'},
+                    $content{'title'},
+                    $content{'duration'},
+                    $content{'url'},
+                );
             }
 	    }
 
-- 
GitLab