[Rt-commit] r12187 - rt/branches/3.8-TESTING/etc/upgrade
ruz at bestpractical.com
ruz at bestpractical.com
Fri May 9 11:50:51 EDT 2008
Author: ruz
Date: Fri May 9 11:50:50 2008
New Revision: 12187
Modified:
rt/branches/3.8-TESTING/etc/upgrade/shrink_cgm_table.pl
Log:
* refactor scrip and use transactions to protect recursive deletions
Modified: rt/branches/3.8-TESTING/etc/upgrade/shrink_cgm_table.pl
==============================================================================
--- rt/branches/3.8-TESTING/etc/upgrade/shrink_cgm_table.pl (original)
+++ rt/branches/3.8-TESTING/etc/upgrade/shrink_cgm_table.pl Fri May 9 11:50:50 2008
@@ -12,42 +12,44 @@
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 => 'main.GroupId',
+ VALUE => $alias .'.GroupId',
QUOTEVALUE => 0,
ENTRYAGGREGATOR => 'AND',
);
$cgms->Limit(
+ ALIAS => $alias,
FIELD => 'id',
OPERATOR => '=',
- VALUE => 'main.Via',
+ VALUE => $alias .'.Via',
QUOTEVALUE => 0,
ENTRYAGGREGATOR => 'AND',
);
-$cgms->FindAllRows;
-
-while ( my $loop_cgm = $cgms->Next ) {
- my $descendants = RT::CachedGroupMembers->new( $RT::SystemUser );
- $descendants->Limit(
- FIELD => 'Via',
- VALUE => $loop_cgm->id,
- ENTRYAGGREGATOR => 'AND',
- );
- $descendants->Limit(
- FIELD => 'id',
- OPERATOR => '!=',
- VALUE => 'main.Via',
- QUOTEVALUE => 0,
- ENTRYAGGREGATOR => 'AND',
- );
- $descendants->FindAllRows;
- while ( my $rec = $descendants->Next ) {
- my ($status) = $rec->Delete;
- unless ($status) {
- print STDERR "Couldn't delete CGM #". $rec->id;
- exit 1;
- }
+while ( my $rec = $cgms->Next ) {
+ $RT::Handle->BeginTransaction;
+ my ($status) = $rec->Delete;
+ unless ($status) {
+ print STDERR "Couldn't delete CGM #". $rec->id;
+ exit 1;
}
+ $RT::Handle->Commit;
}
+
More information about the Rt-commit
mailing list