Changeset 76 in bookmarks for trunk


Ignore:
Timestamp:
04/11/14 11:29:34 (11 years ago)
Author:
peter
Message:
  • only update the title if it has changed
  • update the mtime if the bookmark title has changed
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Bookmarks.pm

    r75 r76  
    247247    my $mtime = time; 
    248248 
     249    # update the URI, if it has changed 
    249250    my $changed_uri = 0; 
    250251    my $sth_current = $self->dbh->prepare('select uri from bookmarks where id = ?'); 
     
    259260    } 
    260261 
    261     # update the title 
    262     # TODO: only do this if the title has changed 
    263     # TODO: should we update mtime if the title changes? 
    264     my $sth_update = $self->dbh->prepare('update resources set title = ? where uri = ?'); 
    265     $sth_update->execute($bookmark->title, $bookmark->uri); 
    266  
     262    # update the title, if it has changed 
     263    my $changed_title = 0; 
     264    my $sth_current_title = $self->dbh->prepare('select title from resources where uri = ?'); 
     265    $sth_current_title->execute($bookmark->uri); 
     266    my ($stored_title) = $sth_current_title->fetchrow_array; 
     267 
     268    if ($stored_title ne $bookmark->title) { 
     269        my $sth_update = $self->dbh->prepare('update resources set title = ? where uri = ?'); 
     270        $sth_update->execute($bookmark->title, $bookmark->uri); 
     271        $changed_title++; 
     272    } 
     273 
     274    # update the tags, if they have changed 
    267275    my $changed_tags = $self->_update_tags($bookmark->uri, $bookmark->tags); 
    268276 
    269     if ($changed_uri or $changed_tags) { 
     277    # update the mtime, if the bookmark has actually been changed 
     278    if ($changed_uri or $changed_title or $changed_tags) { 
    270279        # update the mtime if the bookmark already existed but the tags were changed 
    271280        my $sth_update = $self->dbh->prepare('update bookmarks set mtime = ? where uri = ?'); 
Note: See TracChangeset for help on using the changeset viewer.