[Rt-commit] rt branch, 4.0/time-fields-on-merge, updated. rt-4.0.6-251-gb1c32c6
Ruslan Zakirov
ruz at bestpractical.com
Thu Jul 26 11:59:31 EDT 2012
The branch, 4.0/time-fields-on-merge has been updated
via b1c32c61c675c34acfa85ef0d68d046f772eb9cc (commit)
from ce5520aa140d236b0cfe7259cf1e326db9de8616 (commit)
Summary of changes:
etc/upgrade/time-worked-history.pl | 63 ++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 etc/upgrade/time-worked-history.pl
- Log -----------------------------------------------------------------
commit b1c32c61c675c34acfa85ef0d68d046f772eb9cc
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Jul 26 19:31:21 2012 +0400
script that deletes bad (Set, TimeWorked) txns
It try to fix history and do it as safe as possible.
It calcs time worked using history, by the way collects
candidates for deletion. Transactions are deleted only
if time on ticket is equal to time from history minus
time on candidates.
It's probably possible to write similar script for TimeLeft
and TimeEstimated, but it's much harder to do as the value
is not recorded on Create unlike time worked which is stored
in TimeTaken column.
diff --git a/etc/upgrade/time-worked-history.pl b/etc/upgrade/time-worked-history.pl
new file mode 100644
index 0000000..7ed5535
--- /dev/null
+++ b/etc/upgrade/time-worked-history.pl
@@ -0,0 +1,63 @@
+#!/usr/bin/env perl
+use 5.8.3;
+use strict;
+use warnings;
+
+use RT;
+RT::LoadConfig();
+RT->Config->Set('LogToScreen' => 'info');
+RT::Init();
+
+my $dbh = $RT::Handle->dbh;
+my $ids = $dbh->selectcol_arrayref(
+ "SELECT t1.id FROM Tickets t1, Tickets t2 WHERE t1.id = t2.EffectiveId"
+ ." AND t2.id != t2.EffectiveId AND t2.EffectiveId = t1.id"
+);
+foreach my $id ( @$ids ) {
+ my $t = RT::Ticket->new( RT->SystemUser );
+ $t->Load( $id );
+ unless ( $t->id ) {
+ $RT::Logger->error("Couldn't load ticket #$id");
+ next;
+ }
+
+ fix_time_worked_history($t);
+}
+
+sub fix_time_worked_history {
+ my ($t) = (@_);
+
+ my $history = 0;
+ my $candidate = undef;
+ my @delete = ();
+ my $delete_time = 0;
+
+ my $txns = $t->Transactions;
+ while ( my $txn = $txns->Next ) {
+ if ( $txn->Type =~ /^(Create|Correspond|Comment)$/ ) {
+ $history += $txn->TimeTaken || 0;
+ } elsif ( $txn->Type eq 'Set' && $txn->Field eq 'TimeWorked' ) {
+ $history += $txn->NewValue - $txn->OldValue;
+ $candidate = $txn;
+ } elsif ( $candidate && $txn->Field eq 'MergedInto' ) {
+ if ($candidate->Creator eq $txn->Creator ) {
+ push @delete, $candidate;
+ $delete_time += $candidate->NewValue - $candidate->OldValue;
+ }
+
+ $candidate = undef;
+ }
+ }
+
+ if ( $history == $t->TimeWorked ) {
+ $RT::Logger->info("Ticket #". $t->id . " has TimeWorked matching history. Skipping");
+ } elsif ( $history - $delete_time == $t->TimeWorked ) {
+ $RT::Logger->warn( "Ticket #". $t->id ." has TimeWorked mismatch. Deleting transactions" );
+ foreach my $dtxn ( @delete ) {
+ my ($status, $msg) = $dtxn->Delete;
+ $RT::Logger->error("Couldn't delete transaction: $msg") unless $status;
+ }
+ } else {
+ $RT::Logger->error( "Ticket #". $t->id ." has TimeWorked mismatch, but we couldn't find correct transactions to delete. Skipping" );
+ }
+}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list