From 26d56adbe9d06e259d28068987304ba5e323889c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 13 Apr 2018 09:38:50 +0200 Subject: [PATCH] Bug 18725: (QA follow-up) Use make_column_dirty instead of status change Moving the status to the invalid 'processing' might well have unwanted side-effects. (The status column will be set to empty string and we have a problem if it is not processed.) This patch allows pass-through of DBIX's make_column_dirty in Koha::Object (simple tests included) and uses it to force an update. If the update does not return true, it still exits. Test plan: [1] Read the changes. [2] Run t/db_dependent/Koha/Object.t Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart Conflicts: Koha/Object.pm (cherry picked from commit 40e865ba1632c002af37e9ddc1255bfacb3fd8d0) Signed-off-by: Fridolin Somers --- C4/Letters.pm | 4 ++-- Koha/Object.pm | 3 ++- t/db_dependent/Koha/Object.t | 13 +++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index deddf10941..4023d34a7f 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1035,9 +1035,9 @@ sub SendQueuedMessages { my $unsent_messages = _get_unsent_messages(); MESSAGE: foreach my $message ( @$unsent_messages ) { my $message_object = Koha::Notice::Messages->find( $message->{message_id} ); - $message_object->status('processing'); # If this fails the database is unwritable and we won't manage to send a message that continues to be marked 'pending' - return unless $message_object->store(); + $message_object->make_column_dirty('status'); + return unless $message_object->store; # warn Data::Dumper->Dump( [ $message ], [ 'message' ] ); warn sprintf( 'sending %s message to patron: %s', diff --git a/Koha/Object.pm b/Koha/Object.pm index d305542200..773d2d4742 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -301,7 +301,8 @@ sub AUTOLOAD { } } - my @known_methods = qw( is_changed id in_storage get_column discard_changes update ); + my @known_methods = qw( is_changed id in_storage get_column discard_changes update make_column_dirty ); + Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods; my $r = eval { $self->_result->$method(@_) }; diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index ea06544d24..74e47e6dc4 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -38,8 +38,8 @@ BEGIN { my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new(); -subtest 'is_changed' => sub { - plan tests => 6; +subtest 'is_changed / make_column_dirty' => sub { + plan tests => 9; $schema->storage->txn_begin; @@ -65,6 +65,15 @@ subtest 'is_changed' => sub { $object->store(); is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" ); + # Test make_column_dirty + $object->make_column_dirty('firstname'); + is( $object->is_changed, 1, "Object is changed after make dirty" ); + $object->store; + is( $object->is_changed, 0, "Store clears dirty mark" ); + $object->make_column_dirty('firstname'); + $object->discard_changes; + is( $object->is_changed, 0, "Discard clears dirty mark too" ); + $schema->storage->txn_rollback; }; -- 2.39.5