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

(-)a/C4/CourseReserves.pm (-11 / +66 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
        }
554
        # The field was already enabled, copy the incoming value to the item.
555
        # The "original" ( when not on course reserve ) value is already in the storage field
556
        elsif ( $course_item->itype_enabled) {
557
            $item_fields->{itype} = $params{itype};
558
        }
551
559
560
        if ( $params{ccode_enabled} && !$course_item->ccode_enabled ) {
561
            $enabled{ccode_storage} = $item->ccode;
562
            $item_fields->{ccode} = $params{ccode};
563
        }
564
        elsif ( !$params{ccode_enabled} && $course_item->ccode_enabled ) {
565
            $item_fields->{ccode} = $course_item->ccode_storage;
566
            $enabled{ccode_storage} = undef;
567
        } elsif ( $course_item->ccode_enabled) {
568
            $item_fields->{ccode} = $params{ccode};
569
        }
570
571
        if ( $params{location_enabled} && !$course_item->location_enabled ) {
572
            $enabled{location_storage} = $item->location;
573
            $item_fields->{location} = $params{location};
574
        }
575
        elsif ( !$params{location_enabled} && $course_item->location_enabled ) {
576
            $item_fields->{location} = $course_item->location_storage;
577
            $enabled{location_storage} = undef;
578
        } elsif ( $course_item->location_enabled) {
579
            $item_fields->{location} = $params{location};
580
        }
581
582
        if ( $params{homebranch_enabled} && !$course_item->homebranch_enabled ) {
583
            $enabled{homebranch_storage} = $item->homebranch;
584
            $item_fields->{homebranch} = $params{homebranch};
585
        }
586
        elsif ( !$params{homebranch_enabled} && $course_item->homebranch_enabled ) {
587
            $item_fields->{homebranch} = $course_item->homebranch_storage;
588
            $enabled{homebranch_storage} = undef;
589
        } elsif ( $course_item->homebranch_enabled) {
590
            $item_fields->{homebranch} = $params{homebranch};
591
        }
592
593
        if ( $params{holdingbranch_enabled} && !$course_item->holdingbranch_enabled ) {
594
            $enabled{holdingbranch_storage} = $item->holdingbranch;
595
            $item_fields->{holdingbranch} = $params{holdingbranch};
596
        }
597
        elsif ( !$params{holdingbranch_enabled} && $course_item->holdingbranch_enabled ) {
598
            $item_fields->{holdingbranch} = $course_item->holdingbranch_storage;
599
            $enabled{holdingbranch_storage} = undef;
600
        } elsif ( $course_item->holdingbranch_enabled) {
601
            $item_fields->{holdingbranch} = $params{holdingbranch};
602
        }
603
604
        $item->set( $item_fields )->store
605
            if keys %$item_fields;
552
    }
606
    }
553
607
608
    $course_item->update( { %data, %enabled } );
609
554
}
610
}
555
611
556
=head2 _RevertFields
612
=head2 _RevertFields
557
- 

Return to bug 25444