OSDN Git Service

timeline: add up/down vote feature for journal timeline
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Model / Tags.pm
index 06f77cb..dd4083b 100644 (file)
@@ -142,12 +142,23 @@ EOSQL
     my $dbh = $self->connect_db;
     my $rs = $dbh->do($sql, undef, $tagname_id, $globj_id, $uid, $private, $active);
     if (!$rs) {
-        $self->set_errorno($dbh->err);
+        $self->last_error($dbh->err);
         $self->disconnect_db;
         return;
     }
     my $id = $dbh->last_insert_id(undef, undef, undef, undef);
     $self->disconnect_db;
+
+    if (!$id) {
+        $rs = $self->select(tagnameid => $tagname_id,
+                            globjid => $globj_id);
+        if (!$rs) {
+            $self->last_error($dbh->err);
+            $self->disconnect_db;
+            return;
+        }
+        $id = $rs->[0]->{tagid};
+    }
     return $id;
 }