[Rt-commit] r6285 - in rtir/branches/2.1-EXPERIMENTAL: etc/upgrade
ruz at bestpractical.com
ruz at bestpractical.com
Wed Oct 25 07:44:59 EDT 2006
Author: ruz
Date: Wed Oct 25 07:44:59 2006
New Revision: 6285
Modified:
rtir/branches/2.1-EXPERIMENTAL/ (props changed)
rtir/branches/2.1-EXPERIMENTAL/etc/upgrade/upgrade.pl
Log:
r1692 at cubic-pc (orig r6156): ruz | 2006-10-04 12:08:51 +0400
* rwwrite upgrade.pl a little
Modified: rtir/branches/2.1-EXPERIMENTAL/etc/upgrade/upgrade.pl
==============================================================================
--- rtir/branches/2.1-EXPERIMENTAL/etc/upgrade/upgrade.pl (original)
+++ rtir/branches/2.1-EXPERIMENTAL/etc/upgrade/upgrade.pl Wed Oct 25 07:44:59 2006
@@ -9,6 +9,7 @@
use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
use RT::Tickets;
use RT::Template;
+use RT::Queue;
#Clean out all the nasties from the environment
CleanEnv();
@@ -19,21 +20,45 @@
#Connect to the database and get RT::SystemUser and RT::Nobody loaded
RT::Init();
+my $current_user = GetCurrentUser();
+
# Get the open incidents with no due dates
-my $incidents = new RT::Tickets(GetCurrentUser());
-$incidents->FromSQL("Queue = 'Incidents' AND Due <= '1970-01-01' AND (Status = 'new' OR Status = 'open')");
+my $incidents = RT::Tickets->new( $current_user );
+$incidents->FromSQL(
+ "Queue = 'Incidents' AND Due <= '1970-01-02'"
+ ." AND ( ". join( ' OR ', map "Status = '$_'", RT::Queue->ActiveStatusArray() ) ." )"
+);
+
+my $base_query = "( Queue = 'Incident Reports' OR Queue = 'Investigations' OR Queue = 'Blocks' )"
+ ." AND ( ". join( ' OR ', map "Status = '$_'", RT::Queue->ActiveStatusArray() ) ." )"
+ ." AND Due > '1970-01-02'";
# Get the children for each Incident
-my $children = new RT::Tickets(GetCurrentUser());
-while (my $inc = $incidents->Next) {
- $children->FromSQL("MemberOf = " . $inc->Id . " AND (Queue = 'Incident Reports' OR Queue = 'Investigations' OR Queue = 'Blocks') AND (Status = 'new' OR Status = 'open')");
- $children->OrderBy(FIELD => 'Due', ORDER => 'ASC');
-
- # Find the most due child
- my $child = $children->First;
- next unless $child;
+my $children = RT::Tickets->new( $current_user );
+
+FetchNext( $incidents, 1 );
+while ( my $inc = FetchNext( $incidents ) ) {
+ $children->FromSQL( "( $base_query ) AND MemberOf = " . $inc->Id );
+ $children->OrderBy( FIELD => 'Due', ORDER => 'ASC' );
+ $children->RowsPerPage(1);
+ my $child = $children->First or next;
# Set the due date of the Incident to the due date of the child
- $inc->SetDue($child->DueObj->ISO);
+ $inc->SetDue( $child->DueObj->ISO );
+}
+
+use constant PAGE_SIZE => 100;
+sub FetchNext {
+ my ($objs, $init) = @_;
+ if ( $init ) {
+ $objs->RowsPerPage( PAGE_SIZE );
+ $objs->FirstPage;
+ return;
+ }
+
+ my $obj = $objs->Next;
+ return $obj if $obj;
+ $objs->NextPage;
+ return $objs->Next;
}
More information about the Rt-commit
mailing list