[Rt-commit] [rtir] 01/01: Update Status update and OCFV delete subs
Jim Brandt
jbrandt at bestpractical.com
Tue Jun 18 16:58:52 EDT 2013
This is an automated email from the git hooks/post-receive script.
jbrandt pushed a commit to branch 2.9/2.9.0-db-update-code
in repository rtir.
commit d607c37a4105f8a61fc99f021d350f155aeb2f5e
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Tue Jun 18 16:56:34 2013 -0400
Update Status update and OCFV delete subs
On MySQL, the previous update and delete statements with
sub selects were taking a long time to run. This is likely due
to issues MySQL has with these types of statements. Move to
code-based loops.
---
etc/upgrade/2.9.0/content | 44 ++++++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/etc/upgrade/2.9.0/content b/etc/upgrade/2.9.0/content
index 3768a18..365edf0 100644
--- a/etc/upgrade/2.9.0/content
+++ b/etc/upgrade/2.9.0/content
@@ -162,6 +162,8 @@ our @Final = (
my ($queue, $cf) = get_queue_and_state_cf( $qname );
next unless $queue && $cf;
+ $RT::Logger->debug("Working on $qname");
+
my @states = custom_field_real_values( $cf );
foreach my $state ( @states ) {
@@ -171,13 +173,22 @@ our @Final = (
$values->Limit( FIELD => 'Content', VALUE => $state );
$values->Columns('ObjectId');
- my $res = $RT::Handle->SimpleUpdateFromSelect(
- 'Tickets', { Status => $state }, $values->BuildSelectQuery
- );
- $RT::Logger->error("Couldn't update tickets: $res")
- unless $res;
+ while( my $value = $values->Next ){
+ my $ticket = RT::Ticket->new ( $RT::SystemUser );
+ $ticket->Load($value->ObjectId);
+ next unless $ticket->Status ne $state;
+
+ my ($res, $msg) = $ticket->_Set(
+ Field => 'Status',
+ Value => $state,
+ RecordTransaction => 0);
+
+ $RT::Logger->error("Couldn't update ticket: " . $ticket->Id . " $res $msg")
+ unless $res;
+ }
}
}
+ $RT::Logger->debug("Ticket Status update complete");
},
sub {
@@ -218,6 +229,8 @@ our @Final = (
my ($queue, $cf) = get_queue_and_state_cf( $qname );
next unless $queue && $cf;
+ $RT::Logger->debug("Working on $qname");
+
foreach my $old_new (qw(Old New)) {
my $txns = RT::Transactions->new( $RT::SystemUser );
$txns->Limit( FIELD => ObjectType => VALUE => 'RT::Ticket' );
@@ -230,13 +243,24 @@ our @Final = (
);
$txns->Columns( $old_new .'Reference' );
- my $res = $RT::Handle->DeleteFromSelect(
- 'ObjectCustomFieldValues', $txns->BuildSelectQuery
- );
- $RT::Logger->error("Couldn't delete ObjectCustomFieldValues")
- unless $res;
+ while( my $txn = $txns->Next ){
+ my $ocfv = RT::ObjectCustomFieldValue->new($RT::SystemUser);
+ my ($res, $msg);
+ if ( $old_new eq 'New' ){
+ ($res, $msg) = $ocfv->LoadById($txn->NewReference);
+ }
+ else {
+ ($res, $msg) = $ocfv->LoadById($txn->OldReference);
+ }
+ next unless $res and $ocfv->Id;
+ my $ok = $ocfv->Delete;
+
+ $RT::Logger->error("Couldn't delete ObjectCustomFieldValues")
+ unless $ok;
+ }
}
}
+ $RT::Logger->debug("OCFV delete complete");
},
# delete tickets' Status changes (txns) in RTIR queues,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Rt-commit
mailing list