1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/perl
use 5.8.3;
use strict;
use warnings;
use RT;
RT::LoadConfig();
RT->Config->Set('LogToScreen' => 'debug');
RT::Init();
use RT::CachedGroupMembers;
my $cgms = RT::CachedGroupMembers->new( $RT::SystemUser );
$cgms->Limit(
FIELD => 'id',
OPERATOR => '!=',
VALUE => 'main.Via',
QUOTEVALUE => 0,
ENTRYAGGREGATOR => 'AND',
);
$cgms->FindAllRows;
my $alias = $cgms->Join(
TYPE => 'LEFT',
FIELD1 => 'Via',
TABLE2 => 'CachedGroupMembers',
FIELD2 => 'id',
);
$cgms->Limit(
ALIAS => $alias,
FIELD => 'MemberId',
OPERATOR => '=',
VALUE => $alias .'.GroupId',
QUOTEVALUE => 0,
ENTRYAGGREGATOR => 'AND',
);
$cgms->Limit(
ALIAS => $alias,
FIELD => 'id',
OPERATOR => '=',
VALUE => $alias .'.Via',
QUOTEVALUE => 0,
ENTRYAGGREGATOR => 'AND',
);
FetchNext( $cgms, 'init' );
while ( my $rec = FetchNext( $cgms ) ) {
$RT::Handle->BeginTransaction;
my ($status) = $rec->Delete;
unless ($status) {
print STDERR "Couldn't delete CGM #". $rec->id;
exit 1;
}
$RT::Handle->Commit;
}
use constant PAGE_SIZE => 1000;
sub FetchNext {
my ($objs, $init) = @_;
if ( $init ) {
$objs->RowsPerPage( PAGE_SIZE );
$objs->FirstPage;
return;
}
my $obj = $objs->Next;
return $obj if $obj;
$objs->RedoSearch;
$objs->FirstPage;
return $objs->Next;
}
|