[Jifty-commit] r5109 - in apps/CASPlus/trunk: lib/CASPlus/Util
Jifty commits
jifty-commit at lists.jifty.org
Thu Feb 14 15:44:15 EST 2008
Author: sterling
Date: Thu Feb 14 15:44:15 2008
New Revision: 5109
Modified:
apps/CASPlus/trunk/ (props changed)
apps/CASPlus/trunk/lib/CASPlus/Util/Relationship.pm
Log:
r15310 at riddle: andrew | 2008-02-14 14:39:03 -0600
Made role calculation more robust.
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 Thu Feb 14 15:44:15 2008
@@ -3,6 +3,8 @@
package CASPlus::Util::Relationship;
+use Scalar::Util qw/ blessed /;
+
=head1 NAME
CASPlus::Util::Relationship - utilties for relationships and role caching
@@ -244,27 +246,7 @@
$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;
- }
+ $class->clear_abandoned_role_members;
}
=head2 recalculate_role_cache_for_object
@@ -338,6 +320,8 @@
while (my $path_cache = $cache_paths->next) {
$path_cache->delete;
}
+
+ $class->clear_abandoned_role_members;
}
=head2 add_parent_relationships
@@ -379,6 +363,14 @@
elsif (not $relationship->many_parents) {
my $parent = $child->$method;
+ # Make it into an object if it isn't
+ if (defined $parent and not blessed $parent) {
+ my $obj = $relationship->relation_parent->record_class->new;
+ $obj->load($parent);
+ die "Cannot load parent by ID $parent" unless $obj->id;
+ $parent = $obj;
+ }
+
# Only add it if it's set
if (defined $parent and $parent->id) {
push @parents, $parent;
@@ -495,21 +487,22 @@
# Load the role memberships that now have an empty cache path
my $role_members = CASPlus::Model::RoleMemberCollection->new;
- my $cache_paths_alias = $role_members->join(
- column1 => 'id',
- table2 => CASPlus::Model::RoleMemberPathCache->table,
- column2 => 'role_member',
+ my $cache_paths = $role_members->join(
+ type => 'left',
+ is_distinct => 1,
+ column1 => 'id',
+ table2 => CASPlus::Model::RoleMemberPathCache->table,
+ column2 => 'role_member',
);
- $role_members->group_by({
- column => 'id',
- });
$role_members->limit(
- 'alias' => $cache_paths_alias,
- 'column' => 'cache_path',
- 'function' => 'COUNT',
- 'value' => 0,
+ 'alias' => $cache_paths,
+ 'column' => 'id',
+ 'operator' => 'IS',
+ 'value' => 'NULL',
);
+# Jifty->log->error($role_members->build_select_query);
+
# Delete these role memberships, they no longer hold
while (my $role_member = $role_members->next) {
$role_member->delete;
More information about the Jifty-commit
mailing list