From: Chris W. <la...@us...> - 2005-02-13 20:36:20
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9176/OpenInteract2 Modified Files: SPOPS.pm Log Message: OIN-38: remove code related to object keys Index: SPOPS.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/SPOPS.pm,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** SPOPS.pm 6 Jan 2005 09:03:05 -0000 1.27 --- SPOPS.pm 13 Feb 2005 20:36:11 -0000 1.28 *************** *** 16,136 **** my ( $log ); - # TODO: - # - move object key stuff to a separate class - - use constant OBJECT_KEY_TABLE => 'object_keys'; - # This is not public, look away, look away! $OpenInteract2::SPOPS::TRACKING_DISABLED = 0; ######################################## - # RULESET FACTORY BEHAVIOR - ######################################## - - # TODO: Make this optional? Are we even using object keys anymore? - - sub ruleset_factory { - my ( $class, $rs_table ) = @_; - push @{ $rs_table->{post_save_action} }, \&save_object_key; - return __PACKAGE__; - } - - - # Use the object class and ID to update the object key table - - sub save_object_key { - my ( $self, $p ) = @_; - $log ||= get_logger( LOG_SPOPS ); - - # Don't create an object key if we're explicitly told not to - return 1 if ( $self->CONFIG->{skip_object_key} || $p->{skip_object_key} ); - - $p ||= {}; - my $obj_key = $self->fetch_object_key; - unless ( $obj_key ) { - $obj_key = $self->generate_object_key; - my $id = $self->id; - my $db = CTX->datasource( CTX->lookup_system_datasource_name ); - eval { - SPOPS::SQLInterface->db_insert({ - %{ $p }, - table => OBJECT_KEY_TABLE, - field => [ qw/ object_key class object_id / ], - value => [ $obj_key, ref( $self ), $id ], - db => $db, }) - }; - if ( $@ ) { - $log->error( "Cannot save object key: $@" ); - return undef; - } - } - return $self->{tmp_object_key} = $obj_key; - } - - - ######################################## - # OBJECT KEY - - # Create a unique key based on the class and ID - - sub generate_object_key { - my ( $self ) = @_; - return md5_hex( ref( $self ) . $self->id ); - } - - - # Retrieve the object key based on the class and ID - - sub fetch_object_key { - my ( $self, $p ) = @_; - $p ||= {}; - my $id = $self->id; - my $db = CTX->datasource( CTX->lookup_system_datasource_name ); - my $row = $self->db_select({ %{ $p }, - from => OBJECT_KEY_TABLE, - select => [ 'object_key' ], - where => 'class = ? AND object_id = ?', - value => [ ref $self, scalar $id ], - return => 'single', - db => $db }); - return $row->[0] if ( $row ); - return undef; - } - - - # Retrieve the object class and ID given an object_key - - sub fetch_object_info_by_key { - my ( $class, $key, $p ) = @_; - $p ||= {}; - my $db = CTX->datasource( CTX->lookup_system_datasource_name ); - die "Cannot retrieve object info without key!" unless ( $key ); - my $row = SPOPS::SQLInterface->db_select({ - %{ $p }, - from => OBJECT_KEY_TABLE, - select => [ 'class', 'object_id' ], - where => 'object_key = ?', - value => [ $key ], - return => 'single', - db => $db }); - return ( $row->[0], $row->[1] ) if ( $row ); - return undef; - } - - - # Retrieve an object given an object_key - - sub fetch_object_by_key { - my ( $class, $key, $p ) = @_; - my ( $object_class, $object_id ) = - $class->fetch_object_info_by_key( $key, $p ); - if ( $object_class and $object_id ) { - return $object_class->fetch( $object_id, $p ); - } - return undef; - } - - - ######################################## # OBJECT TRACK METHODS --- 16,23 ---- *************** *** 508,558 **** [ uid of updater, date of update ] - =head1 OBJECT KEY METHODS - - We use a object key to uniquely identify each object in the - system. (Generally the object key is a digest formed from the class - and object ID.) - - B<generate_object_key()> - - Creates a unique key based on the class and ID. (Currently using - L<Digest::MD5>.) - - B<save_object_key( \%params )> - - Checks to see if an object key already exists for this class and ID - and if not, creates a new key and saves it to the lookup table. - - Returns: the object key retrieved or saved - - B<fetch_object_key()> - - Retreives an object key based on the class and ID of an object. - - Returns: the object key associated with the class and ID, or undef if - none found. - - B<fetch_object_info_by_key( $key, \%params )> - - Given an object key, lookup the object class and ID associated with it. - - Returns: If matching information found, a two-element list -- the - first element is the object class, the second is the object ID. If no - matching information is found, undef. matching information found, re - - B<fetch_object_by_key( $key, \%params )> - - Given an object key, fetch the object associated with it. - - Returns: If key matches class and ID in lookup table, the object with - the class and ID. If no match found, return undef. - - =head1 RULESET METHODS - - We create one rule in the ruleset of each object. In the - B<post_save_action> step we ensure that this object has an entry in - the object key table. (See description of C<save_object_key()> for - information about the implementation.) - =head1 METHODS --- 395,398 ---- |