Changeset 28 in bookmarks
- Timestamp:
- 05/23/13 01:08:27 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Bookmarks.pm
r26 r28 154 154 my $uri = $bookmark->{uri}; 155 155 my $title = $bookmark->{title}; 156 #TODO: accept a ctime or mtime157 156 my $ctime = $bookmark->{ctime} || time; 158 157 my $mtime = $bookmark->{mtime} || $ctime; … … 176 175 177 176 # create the bookmark 177 my $bookmark_exists = 0; 178 178 my ($sql_bookmark, @bind_bookmark) = sql_interp( 179 179 'insert into bookmarks', { ($id ? (id => $id) : ()), uri => $uri, ctime => $ctime, mtime => $mtime } … … 186 186 if ($@ =~ /column uri is not unique/) { 187 187 # this is not truly an error condition; the bookmark was already there 188 # update the mtime instead 189 # TODO: only update mtime if the tag list is changed? 190 my $sth_update = $self->dbh->prepare('update bookmarks set mtime = ? where uri = ?'); 191 $sth_update->execute($mtime, $uri); 188 # set this flag so that later we can update the mtime if tags change 189 $bookmark_exists = 1; 192 190 } else { 193 191 die $@; … … 195 193 } 196 194 195 my $changed_tags = 0; 197 196 my %new_tags = map { $_ => 1 } @{ $bookmark->{tags} }; 198 197 my $sth_delete_tag = $self->dbh->prepare('delete from tags where uri = ? and tag = ?'); … … 204 203 # if a current tag is not in the new tags, remove it from the database 205 204 $sth_delete_tag->execute($uri, $tag); 205 $changed_tags++; 206 206 } else { 207 207 # if a new tag is already in the database, remove it from the list of tags to add … … 211 211 for my $tag (keys %new_tags) { 212 212 $sth_insert_tag->execute($uri, $tag); 213 } 214 215 =begin 216 217 # clear all tags 218 my $sth_delete_tag = $self->dbh->prepare('delete from tags where uri = ?'); 219 $sth_delete_tag->execute($uri); 220 my $sth_tag = $self->dbh->prepare('insert into tags (uri, tag) values (?, ?)'); 221 for my $tag (@{ $bookmark->{tags} }) { 222 #print $tag, "\n"; 223 # prevent duplicate (uri,tag) pairs in the database 224 # TODO: should POST with a set of tags ever remove tags? 225 eval { 226 $sth_tag->execute($uri, $tag); 227 }; 228 if ($@) { 229 if ($@ =~ /columns uri, tag are not unique/) { 230 # this is not truly an error condition; the tag was already there 231 } else { 232 die $@; 233 } 234 } 235 } 236 237 =cut 213 $changed_tags++; 214 } 215 216 if ($bookmark_exists && $changed_tags) { 217 # update the mtime if the bookmark already existed but the tags were changed 218 my $sth_update = $self->dbh->prepare('update bookmarks set mtime = ? where uri = ?'); 219 $sth_update->execute($mtime, $uri); 220 } 238 221 239 222 # return the newly created or updated bookmark
Note: See TracChangeset
for help on using the changeset viewer.