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

(-)a/C4/CourseReserves.pm (-11 / +53 lines)
Lines 535-556 sub _UpdateCourseItem { Link Here
535
    my %data = map { $_ => $params{$_} } @FIELDS;
535
    my %data = map { $_ => $params{$_} } @FIELDS;
536
    my %enabled = map { $_ . "_enabled" => $params{ $_ . "_enabled" } } @FIELDS;
536
    my %enabled = map { $_ . "_enabled" => $params{ $_ . "_enabled" } } @FIELDS;
537
537
538
    $course_item->update( { %data, %enabled } );
538
    my $item = Koha::Items->find( $course_item->itemnumber );
539
540
    # Handle updates to changed fields for a course item, both adding and removing
539
    if ( $course_item->is_enabled ) {
541
    if ( $course_item->is_enabled ) {
540
        my $item_fields = {};
542
        my $item_fields = {};
541
        $item_fields->{itype}         = $course_item->itype         if $course_item->itype_enabled;
542
        $item_fields->{ccode}         = $course_item->ccode         if $course_item->ccode_enabled;
543
        $item_fields->{location}      = $course_item->location      if $course_item->location_enabled;
544
        $item_fields->{homebranch}    = $course_item->homebranch    if $course_item->homebranch_enabled;
545
        $item_fields->{holdingbranch} = $course_item->holdingbranch if $course_item->holdingbranch_enabled;
546
543
547
        Koha::Items->find( $course_item->itemnumber )
544
        # Find newly enabled field and add item value to storage
548
                   ->set( $item_fields )
545
        if ( $params{itype_enabled} && !$course_item->itype_enabled ) {
549
                   ->store
546
            $enabled{itype_storage} = $item->itype;
550
            if keys %$item_fields;
547
            $item_fields->{itype} = $params{itype};
548
        }
549
        # Find newly disabled field and copy the storage value to the item, unset storage value
550
        elsif ( !$params{itype_enabled} && $course_item->itype_enabled ) {
551
            $item_fields->{itype} = $course_item->itype_storage;
552
            $enabled{itype_storage} = undef;
553
        }
551
554
555
        if ( $params{ccode_enabled} && !$course_item->ccode_enabled ) {
556
            $enabled{ccode_storage} = $item->ccode;
557
            $item_fields->{ccode} = $params{ccode};
558
        }
559
        elsif ( !$params{ccode_enabled} && $course_item->ccode_enabled ) {
560
            $item_fields->{ccode} = $course_item->ccode_storage;
561
            $enabled{ccode_storage} = undef;
562
        }
563
564
        if ( $params{location_enabled} && !$course_item->location_enabled ) {
565
            $enabled{location_storage} = $item->location;
566
            $item_fields->{location} = $params{location};
567
        }
568
        elsif ( !$params{location_enabled} && $course_item->location_enabled ) {
569
            $item_fields->{location} = $course_item->location_storage;
570
            $enabled{location_storage} = undef;
571
        }
572
573
        if ( $params{homebranch_enabled} && !$course_item->homebranch_enabled ) {
574
            $enabled{homebranch_storage} = $item->homebranch;
575
            $item_fields->{homebranch} = $params{homebranch};
576
        }
577
        elsif ( !$params{homebranch_enabled} && $course_item->homebranch_enabled ) {
578
            $item_fields->{homebranch} = $course_item->homebranch_storage;
579
            $enabled{homebranch_storage} = undef;
580
        }
581
582
        if ( $params{holdingbranch_enabled} && !$course_item->holdingbranch_enabled ) {
583
            $enabled{holdingbranch_storage} = $item->holdingbranch;
584
            $item_fields->{holdingbranch} = $params{holdingbranch};
585
        }
586
        elsif ( !$params{holdingbranch_enabled} && $course_item->holdingbranch_enabled ) {
587
            $item_fields->{holdingbranch} = $course_item->holdingbranch_storage;
588
            $enabled{holdingbranch_storage} = undef;
589
        }
590
591
        $item->set( $item_fields )->store
592
            if keys %$item_fields;
552
    }
593
    }
553
594
595
    $course_item->update( { %data, %enabled } );
596
554
}
597
}
555
598
556
=head2 _RevertFields
599
=head2 _RevertFields
557
- 

Return to bug 25444