[Jifty-commit] r3999 - in apps/CASPlus/trunk: lib/CASPlus/Util
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Aug 29 12:49:17 EDT 2007
Author: sterling
Date: Wed Aug 29 12:49:16 2007
New Revision: 3999
Modified:
apps/CASPlus/trunk/ (props changed)
apps/CASPlus/trunk/lib/CASPlus/Util/Relationship.pm
Log:
r8965 at riddle: andrew | 2007-08-25 19:35:05 -0500
Adding a new helper for removing relationships, remove_relationship().
Modified: apps/CASPlus/trunk/lib/CASPlus/Util/Relationship.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/Util/Relationship.pm (original)
+++ apps/CASPlus/trunk/lib/CASPlus/Util/Relationship.pm Wed Aug 29 12:49:16 2007
@@ -31,6 +31,8 @@
my $class = shift;
my %args = @_;
+# Test::More::diag("ADDING :@{[$args{parent}->unique_id]}:\@@{[$args{relationship}->id]}:@{[$args{child}->unique_id]}:");
+
$class->add_immediate_relationship(%args);
$class->add_append_relationships(%args);
$class->add_prepend_relationships(%args);
@@ -202,6 +204,69 @@
}
}
+=head2 remove_relationship
+
+ CASPlus::Util::Relationship->remove_relationship(
+ parent => $parent,
+ relationship => $relationship,
+ child => $child,
+ );
+
+Breaks the relationship between the given parent and child objects that are linked by the given relationship.
+
+=cut
+
+sub remove_relationship {
+ my $class = shift;
+ my %args = @_;
+
+ my ($child, $relationship, $parent)
+ = @args{qw/ child relationship parent /};
+
+ # Create abbreviated names for the IDs in the cache path
+ my $cid = $child->unique_id;
+ my $rid = $relationship->id;
+ my $pid = $parent->unique_id;
+
+ # Build the cache path matcher
+ my $cache_path = ":$cid:\@$rid:$pid:";
+
+ # Load the cache paths that are affected
+ my $cache_paths = CASPlus::Model::RoleMemberPathCacheCollection->new;
+ $cache_paths->limit(
+ column => 'cache_path',
+ operator => 'MATCHES',
+ value => $cache_path,
+ );
+
+ # Delete them, these are all removed
+ while (my $path_cache = $cache_paths->next) {
+ $path_cache->delete;
+ }
+
+ # Load the role memberships that now have an empty cache path
+ my $role_members = CASPlus::Model::RoleMemberCollection->new;
+ $cache_paths = $role_members->join(
+ column1 => 'id',
+ table2 => CASPlus::Model::RoleMemberPathCache->table,
+ column2 => 'role_member',
+ );
+ $role_members->group_by({
+ column => 'id',
+ });
+ $role_members->limit(
+ 'alias' => $cache_paths,
+ 'column' => 'cache_path',
+ 'function' => 'COUNT',
+ 'value' => 0,
+ );
+
+ # Delete these role memberships, they no longer hold
+ while (my $role_member = $role_members->next) {
+ $role_member->delete;
+ }
+}
+
=head2 recalculate_role_cache_for_object
CASPlus::Util::Relationship->recalculate_role_cache_for_object($object);
More information about the Jifty-commit
mailing list