+=head3 fill
+
+ $hold->fill;
+
+This method marks the hold as filled. It effectively moves it to old_reserves.
+
+=cut
+
+sub fill {
+ my ( $self ) = @_;
+ $self->_result->result_source->schema->txn_do(
+ sub {
+ my $patron = $self->patron;
+
+ $self->set(
+ {
+ found => 'F',
+ priority => 0,
+ }
+ );
+
+ my $old_me = $self->_move_to_old;
+
+ Koha::Plugins->call(
+ 'after_hold_action',
+ {
+ action => 'fill',
+ payload => { hold => $old_me->get_from_storage }
+ }
+ );
+
+ # anonymize if required
+ $old_me->anonymize
+ if $patron->privacy == 2;
+
+ $self->SUPER::delete(); # Do not add a DELETE log
+
+ # now fix the priority on the others....
+ C4::Reserves::_FixPriority({ biblionumber => $self->biblionumber });
+
+ if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) {
+ my $fee = $patron->category->reservefee // 0;
+ if ( $fee > 0 ) {
+ $patron->account->add_debit(
+ {
+ amount => $fee,
+ description => $self->biblio->title,
+ user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef,
+ library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
+ interface => C4::Context->interface,
+ type => 'RESERVE',
+ item_id => $self->itemnumber
+ }
+ );
+ }
+ }
+
+ C4::Log::logaction( 'HOLDS', 'FILL', $self->id, $self )
+ if C4::Context->preference('HoldsLog');
+
+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
+ {
+ biblio_ids => [ $old_me->biblionumber ]
+ }
+ ) if C4::Context->preference('RealTimeHoldsQueue');
+ }
+ );
+ return $self;
+}
+
+=head3 store
+
+Override base store method to set default
+expirationdate for holds.
+
+=cut
+
+sub store {
+ my ($self) = @_;
+
+ Koha::Exceptions::Hold::MissingPickupLocation->throw() unless $self->branchcode;
+
+ if ( !$self->in_storage ) {
+ if ( ! $self->expirationdate && $self->patron_expiration_date ) {
+ $self->expirationdate($self->patron_expiration_date);
+ }
+
+ if (
+ C4::Context->preference('DefaultHoldExpirationdate')
+ && !$self->expirationdate
+ )
+ {
+ $self->_set_default_expirationdate;
+ }
+ }
+ else {
+
+ my %updated_columns = $self->_result->get_dirty_columns;
+ return $self->SUPER::store unless %updated_columns;
+
+ if ( exists $updated_columns{reservedate} ) {
+ if (
+ C4::Context->preference('DefaultHoldExpirationdate')
+ && ! exists $updated_columns{expirationdate}
+ )
+ {
+ $self->_set_default_expirationdate;
+ }
+ }
+ }
+
+ $self = $self->SUPER::store;
+}
+
+sub _set_default_expirationdate {
+ my $self = shift;
+
+ my $period = C4::Context->preference('DefaultHoldExpirationdatePeriod') || 0;
+ my $timeunit =
+ C4::Context->preference('DefaultHoldExpirationdateUnitOfTime') || 'days';
+
+ $self->expirationdate(
+ dt_from_string( $self->reservedate )->add( $timeunit => $period ) );
+}
+