Changeset 477


Ignore:
Timestamp:
Oct 26, 2008, 2:31:28 PM (13 years ago)
Author:
kake
Message:

Applied a modified version of tgj's patch (OpenGuides? ticket #23). Also fixed minor POD error while I was at it.

Location:
wiki-toolkit/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/Database.pm

    r466 r477  
    176176=item B<metadata> - a reference to a hash containing any caller-supplied
    177177metadata sent along the last time the node was written
     178
     179=back
    178180
    179181The node parameter is mandatory. The version parameter is optional and
     
    282284}
    283285
    284 # Expects a hash as returned by ->retrieve_node
     286# Expects a hash as returned by ->retrieve_node - it's actually slightly lax
     287# in this, in that while ->retrieve_node always wraps up the metadata values in
     288# (refs to) arrays, this method will accept scalar metadata values too.
    285289sub _checksum {
    286290    my ($self, %node_data) = @_;
     
    288292    my %metadata = %{ $node_data{metadata} || {} };
    289293    foreach my $key ( sort keys %metadata ) {
    290         $string .= "\0\0\0" . $key . "\0\0"
    291                  . join("\0", sort @{$metadata{$key}} );
     294        $string .= "\0\0\0" . $key . "\0\0";
     295        my $val = $metadata{$key};
     296        if ( ref $val eq "ARRAY" ) {
     297            $string .= join("\0", sort @$val );
     298        } else {
     299            $string .= $val;
     300        }
    292301    }
    293302    return md5_hex($self->charset_encode($string));
     
    451460you (or your chosen subclass). This method shouldn't really be used
    452461directly as it might overwrite someone else's changes. Croaks on error
    453 but otherwise returns the version number of the update just made.
     462but otherwise returns the version number of the update just made.  A
     463return value of -1 indicates that the change was not applied.  This
     464may be because the plugins voted against the change, or because the
     465content and metadata in the proposed new version were identical to the
     466current version (a "null" change).
    454467
    455468Supplying a ref to an array of nodes that this ones links to is
     
    511524    if($write_allowed < 1) {
    512525        # The plugins didn't want to allow this action
     526        return -1;
     527    }
     528
     529    if ( $self->_checksum( %args ) eq $args{checksum} ) {
     530        # Refuse to commit as nothing has changed
    513531        return -1;
    514532    }
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/MySQL.pm

    r466 r477  
    4747C<write_node_post_locking> with all supplied arguments, unlocks the
    4848node. Returns the version of the updated node on successful writing, 0 if
    49 checksum doesn't match, croaks on error.
     49checksum doesn't match, -1 if the change was not applied, croaks on error.
    5050
    5151Note:  Uses MySQL's user level locking, so any locks are released when
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/Pg.pm

    r466 r477  
    4747C<write_node_post_locking> with all supplied arguments, unlocks the
    4848node. Returns the version of the updated node on successful writing, 0 if
    49 checksum doesn't match, croaks on error.
     49checksum doesn't match, -1 if the change was not applied, croaks on error.
    5050
    5151=cut
  • wiki-toolkit/trunk/lib/Wiki/Toolkit/Store/SQLite.pm

    r466 r477  
    5858C<write_node_post_locking> with all supplied arguments, unlocks the
    5959node. Returns the version of the updated node on successful writing, 0 if
    60 checksum doesn't match, croaks on error.
     60checksum doesn't match, -1 if the change was not applied, croaks on error.
    6161
    6262=cut
Note: See TracChangeset for help on using the changeset viewer.