Bugfix [ 886432 ] endless loop in group of groups

This commit is contained in:
Len Kranendonk 2004-02-26 10:34:04 +00:00
parent aa0bcfe693
commit 585d18da7b
2 changed files with 13 additions and 5 deletions

View file

@ -18,6 +18,8 @@ use strict;
use WebGUI::DateTime;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::ErrorHandler;
use WebGUI::Utility;
=head1 NAME
@ -74,7 +76,8 @@ sub addGroupsToGroups {
foreach my $toGid (@{$_[1]}) {
my ($isIn) = WebGUI::SQL->quickArray("select count(*) from groupGroupings
where groupId=$gid and inGroup=$toGid");
unless ($isIn) {
my $recursive = isIn($toGid, @{getGroupsInGroup($gid,1)});
unless ($isIn || $recursive) {
WebGUI::SQL->write("insert into groupGroupings (groupId,inGroup) values ($gid,$toGid)");
}
}
@ -257,9 +260,14 @@ sub getGroupsInGroup {
return undef unless $_[0];
my $groups = WebGUI::SQL->buildArrayRef("select groupId from groupGroupings where inGroup=$_[0]");
if ($_[1]) {
my $loopCount = $_[2]++ || 1;
if ($loopCount > 99) {
WebGUI::ErrorHandler::fatalError("Endless recursive loop detected while determinating".
" groups in group.\nRequested groupId: ".$_[0]."\nGroups in that group: ".join(",",@$groups));
}
my @groupsOfGroups = @$groups;
foreach my $group (@$groups) {
my $gog = getGroupsInGroup($group,1);
my $gog = getGroupsInGroup($group,1,$loopCount);
push(@groupsOfGroups, @$gog);
}
return \@groupsOfGroups;