[Rt-commit] [rtir] 01/02: Update Status update and OCFV delete subs
Jim Brandt
jbrandt at bestpractical.com
Tue Jun 25 10:02:49 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 da66cadaa561db5c9a93424241282568b9beefc5
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 | 58 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 47 insertions(+), 11 deletions(-)
diff --git a/etc/upgrade/2.9.0/content b/etc/upgrade/2.9.0/content
index 3768a18..3299b30 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' );
@@ -228,15 +241,27 @@ our @Final = (
OPERATOR => 'IS NOT',
VALUE => 'NULL'
);
- $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: "
+ . $ocfv->Id . " " . $ok)
+ unless $ok;
+ }
}
}
+
+ $RT::Logger->debug("OCFV delete complete");
},
# delete tickets' Status changes (txns) in RTIR queues,
@@ -447,3 +472,14 @@ sub process_home_page_settings {
return $found;
}
+package RT::ObjectCustomFieldValue;
+
+no warnings 'redefine';
+
+# Override delete to actually remove these records rather than just
+# mark them disabled.
+
+sub Delete {
+ my $self = shift;
+ $self->SUPER::Delete();
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Rt-commit
mailing list