View | Details | Raw Unified | Return to bug 23185
Collapse All | Expand All

(-)a/Koha/Exceptions/Object.pm (+4 lines)
Lines 55-60 use Exception::Class ( Link Here
55
        description => 'Invalid data passed',
55
        description => 'Invalid data passed',
56
        fields      => ['type', 'property', 'value'],
56
        fields      => ['type', 'property', 'value'],
57
    },
57
    },
58
    'Koha::Exceptions::Object::NotInStorage' => {
59
        isa         => 'Koha::Exceptions::Object',
60
        description => 'The object is not in storage yet',
61
    },
58
);
62
);
59
63
60
sub full_message {
64
sub full_message {
(-)a/Koha/Object.pm (-1 / +2 lines)
Lines 208-214 A shortcut for set + store in one call. Link Here
208
208
209
sub update {
209
sub update {
210
    my ($self, $values) = @_;
210
    my ($self, $values) = @_;
211
    return $self->set($values)->store();
211
    Koha::Exceptions::Object::NotInStorage->throw unless $self->in_storage;
212
    $self->set($values)->store();
212
}
213
}
213
214
214
=head3 $object->delete();
215
=head3 $object->delete();
(-)a/Koha/Objects.pm (-3 / +30 lines)
Lines 194-199 sub delete { Link Here
194
    return $self->_resultset->delete;
194
    return $self->_resultset->delete;
195
}
195
}
196
196
197
=head3 update
198
199
=cut
200
201
sub update {
202
    my ($self, $params) = @_;
203
204
    my $no_triggers = delete $params->{no_triggers};
205
206
    if (
207
        !$no_triggers
208
        && ( Class::Inspector->function_exists( $self->object_class, 'update' )
209
          or Class::Inspector->function_exists( $self->object_class, 'store' ) )
210
      )
211
    {
212
        my $objects_updated;
213
        $self->_resultset->result_source->schema->txn_do( sub {
214
            while ( my $o = $self->next ) {
215
                $o->update($params);
216
                $objects_updated++;
217
            }
218
        });
219
        return $objects_updated;
220
    }
221
222
    return $self->_resultset->update($params);
223
}
224
197
=head3 single
225
=head3 single
198
226
199
my $object = Koha::Objects->search({}, { rows => 1 })->single
227
my $object = Koha::Objects->search({}, { rows => 1 })->single
Lines 474-487 The autoload method is used call DBIx::Class method on a resultset. Link Here
474
502
475
Important: If you plan to use one of the DBIx::Class methods you must provide
503
Important: If you plan to use one of the DBIx::Class methods you must provide
476
relevant tests in t/db_dependent/Koha/Objects.t
504
relevant tests in t/db_dependent/Koha/Objects.t
477
Currently count, is_paged, pager, update, result_class, single and slice are covered.
505
Currently count, is_paged, pager, result_class, single and slice are covered.
478
506
479
=cut
507
=cut
480
508
481
sub AUTOLOAD {
509
sub AUTOLOAD {
482
    my ( $self, @params ) = @_;
510
    my ( $self, @params ) = @_;
483
511
484
    my @known_methods = qw( count is_paged pager update result_class single slice );
512
    my @known_methods = qw( count is_paged pager result_class single slice );
485
    my $method = our $AUTOLOAD;
513
    my $method = our $AUTOLOAD;
486
    $method =~ s/.*:://;
514
    $method =~ s/.*:://;
487
515
488
- 

Return to bug 23185