[Rt-commit] r12186 - rt/branches/3.8-TESTING/etc/upgrade
ruz at bestpractical.com
ruz at bestpractical.com
Fri May 9 10:42:56 EDT 2008
Author: ruz
Date: Fri May 9 10:42:55 2008
New Revision: 12186
Added:
rt/branches/3.8-TESTING/etc/upgrade/shrink_cgm_table.pl
Log:
* add CGM table shrinker
Added: rt/branches/3.8-TESTING/etc/upgrade/shrink_cgm_table.pl
==============================================================================
--- (empty file)
+++ rt/branches/3.8-TESTING/etc/upgrade/shrink_cgm_table.pl Fri May 9 10:42:55 2008
@@ -0,0 +1,53 @@
+#!/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 => 'MemberId',
+ OPERATOR => '=',
+ VALUE => 'main.GroupId',
+ QUOTEVALUE => 0,
+ ENTRYAGGREGATOR => 'AND',
+);
+$cgms->Limit(
+ FIELD => 'id',
+ OPERATOR => '=',
+ VALUE => 'main.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;
+ }
+ }
+}
More information about the Rt-commit
mailing list