[Rt-commit] r11249 - rtir/branches/2.3-EXPERIMENTAL/etc/upgrade
ruz at bestpractical.com
ruz at bestpractical.com
Fri Mar 28 09:49:49 EDT 2008
Author: ruz
Date: Fri Mar 28 09:49:47 2008
New Revision: 11249
Modified:
rtir/branches/2.3-EXPERIMENTAL/etc/upgrade/upgrade.pl
Log:
* fix etc/upgrade/upgrade.pl script
** it could miss incidents, now we're using temp file to store intermediate results
Modified: rtir/branches/2.3-EXPERIMENTAL/etc/upgrade/upgrade.pl
==============================================================================
--- rtir/branches/2.3-EXPERIMENTAL/etc/upgrade/upgrade.pl (original)
+++ rtir/branches/2.3-EXPERIMENTAL/etc/upgrade/upgrade.pl Fri Mar 28 09:49:47 2008
@@ -16,6 +16,7 @@
# Load the config file
RT::LoadConfig();
+RT->Config->Set( LogToScreen => 'warning' );
#Connect to the database and get RT::SystemUser and RT::Nobody loaded
RT::Init();
@@ -24,18 +25,27 @@
# Get the open incidents with no due dates
my $incidents = RT::Tickets->new( $current_user );
-$incidents->FromSQL(
+my $incidents_query =
"Queue = 'Incidents' AND Due <= '1970-01-02'"
- ." AND ( ". join( ' OR ', map "Status = '$_'", RT::Queue->ActiveStatusArray() ) ." )"
-);
+ ." AND ( ". join( ' OR ', map "Status = '$_'", RT::Queue->ActiveStatusArray() ) ." )";
+$incidents->FromSQL( $incidents_query );
+
+print "\n\nGoing to update due dates of Incidents where it's not set\n";
+
+print "Query for incidents: $incidents_query\n\n";
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'";
+print "Base query for children: $base_query\n\n";
+
# Get the children for each Incident
my $children = RT::Tickets->new( $current_user );
+require File::Temp;
+my $tmp = new File::Temp; # croak on error
+
FetchNext( $incidents, 1 );
while ( my $inc = FetchNext( $incidents ) ) {
$children->FromSQL( "( $base_query ) AND MemberOf = " . $inc->Id );
@@ -43,9 +53,27 @@
$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 );
+ print $tmp $inc->id ." ". $child->DueObj->ISO ."\n";
+}
+
+seek $tmp, 0, 0;
+while ( my $str = <$tmp> ) {
+ chomp $str;
+ my ($id, $date) = split /\s/, $str, 2;
+ my $inc = RT::Ticket->new( $RT::SystemUser );
+ $inc->Load( $id );
+ unless ( $inc->id ) {
+ print STDERR "Couldn't load incident #$id\n";
+ next;
+ }
+ my ($status, $msg) = $inc->SetDue( $date );
+ unless ( $status ) {
+ print STDERR "Couldn't set due date of the incident #$id: $msg\n";
+ next;
+ }
+ print "Updated inc #$id, due is $date\n";
}
+print "done.\n";
use constant PAGE_SIZE => 100;
sub FetchNext {
More information about the Rt-commit
mailing list