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 193-198 sub delete { Link Here
193
    return $self->_resultset->delete;
193
    return $self->_resultset->delete;
194
}
194
}
195
195
196
=head3 update
197
198
=cut
199
200
sub update {
201
    my ($self, $params) = @_;
202
203
    my $no_triggers = delete $params->{no_triggers};
204
205
    if (
206
        !$no_triggers
207
        && ( Class::Inspector->function_exists( $self->object_class, 'update' )
208
          or Class::Inspector->function_exists( $self->object_class, 'store' ) )
209
      )
210
    {
211
        my $objects_updated;
212
        $self->_resultset->result_source->schema->txn_do( sub {
213
            while ( my $o = $self->next ) {
214
                $o->update($params);
215
                $objects_updated++;
216
            }
217
        });
218
        return $objects_updated;
219
    }
220
221
    return $self->_resultset->update($params);
222
}
223
196
=head3 single
224
=head3 single
197
225
198
my $object = Koha::Objects->search({}, { rows => 1 })->single
226
my $object = Koha::Objects->search({}, { rows => 1 })->single
Lines 453-466 The autoload method is used call DBIx::Class method on a resultset. Link Here
453
481
454
Important: If you plan to use one of the DBIx::Class methods you must provide
482
Important: If you plan to use one of the DBIx::Class methods you must provide
455
relevant tests in t/db_dependent/Koha/Objects.t
483
relevant tests in t/db_dependent/Koha/Objects.t
456
Currently count, is_paged, pager, update, result_class, single and slice are covered.
484
Currently count, is_paged, pager, result_class, single and slice are covered.
457
485
458
=cut
486
=cut
459
487
460
sub AUTOLOAD {
488
sub AUTOLOAD {
461
    my ( $self, @params ) = @_;
489
    my ( $self, @params ) = @_;
462
490
463
    my @known_methods = qw( count is_paged pager update result_class single slice );
491
    my @known_methods = qw( count is_paged pager result_class single slice );
464
    my $method = our $AUTOLOAD;
492
    my $method = our $AUTOLOAD;
465
    $method =~ s/.*:://;
493
    $method =~ s/.*:://;
466
494
467
- 

Return to bug 23185