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

(-)a/Koha/ERM/EHoldings/Title.pm (-9 / +9 lines)
Lines 44-65 sub store { Link Here
44
    # * Provide a mapping for each attribute of title
44
    # * Provide a mapping for each attribute of title
45
    # * Create a txn
45
    # * Create a txn
46
46
47
    # If the 'title' is alreay linked to a biblio, then we update the title subfield only
47
    # If the 'title' is already linked to a biblio, then we update the title subfield only
48
    if ( $self->biblio_id ){
48
    if ( $self->biblio_id ) {
49
        my $biblio = Koha::Biblios->find( $self->biblio_id );
49
        my $biblio = Koha::Biblios->find( $self->biblio_id );
50
        my ($title_tag, $title_subfield) = GetMarcFromKohaField( 'biblio.title' );
50
        my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title');
51
        my $record = $biblio->metadata->record();
51
        my $record      = $biblio->metadata->record();
52
        my $title_field = $record->field($title_tag);
52
        my $title_field = $record->field($title_tag);
53
        $title_field->update( $title_subfield => $self->publication_title );
53
        $title_field->update( $title_subfield => $self->publication_title );
54
        C4::Biblio::ModBiblio( $record, $self->biblio_id, '' );
54
        C4::Biblio::ModBiblio( $record, $self->biblio_id, '' );
55
    } else {
55
    } else {
56
    # If it's not linked, we create a simple biblio and save the biblio id to the 'title'
56
57
        # If it's not linked, we create a simple biblio and save the biblio id to the 'title'
57
        my $marc_record = TransformKohaToMarc(
58
        my $marc_record = TransformKohaToMarc(
58
            {
59
            {
59
                'biblio.title' => $self->publication_title,
60
                'biblio.title' => $self->publication_title,
60
            }
61
            }
61
        );
62
        );
62
        my ( $biblio_id ) = C4::Biblio::AddBiblio($marc_record, '');
63
        my ($biblio_id) = C4::Biblio::AddBiblio( $marc_record, '' );
63
        $self->biblio_id($biblio_id);
64
        $self->biblio_id($biblio_id);
64
    }
65
    }
65
66
Lines 77-83 Returns the resources linked to this title Link Here
77
sub resources {
78
sub resources {
78
    my ( $self, $resources ) = @_;
79
    my ( $self, $resources ) = @_;
79
80
80
    if ( $resources ) {
81
    if ($resources) {
81
        my $schema = $self->_result->result_source->schema;
82
        my $schema = $self->_result->result_source->schema;
82
        $schema->txn_do(
83
        $schema->txn_do(
83
            sub {
84
            sub {
Lines 85-92 sub resources { Link Here
85
86
86
                # Cannot use the dbic RS, we need to trigger ->store overwrite
87
                # Cannot use the dbic RS, we need to trigger ->store overwrite
87
                for my $resource (@$resources) {
88
                for my $resource (@$resources) {
88
                    Koha::ERM::EHoldings::Resource->new(
89
                    Koha::ERM::EHoldings::Resource->new( { %$resource, title_id => $self->title_id } )->store;
89
                        { %$resource, title_id => $self->title_id } )->store;
90
                }
90
                }
91
            }
91
            }
92
        );
92
        );
(-)a/t/db_dependent/api/v1/erm_eholdings_titles.t (-3 / +2 lines)
Lines 479-491 subtest 'update() tests' => sub { Link Here
479
            ->status_is(200)->json_is( '/publication_title' => 'The journal of writing unit tests :' );
479
            ->status_is(200)->json_is( '/publication_title' => 'The journal of writing unit tests :' );
480
480
481
        $biblio->discard_changes;
481
        $biblio->discard_changes;
482
        warn $biblio->title;
482
483
        my $record_after = $biblio->metadata->record;
483
        my $record_after = $biblio->metadata->record;
484
484
485
        my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title');
485
        my ( $title_tag, $title_subfield ) = GetMarcFromKohaField('biblio.title');
486
        is(
486
        is(
487
            $record_after->subfield( $title_tag, $title_subfield ), "The journal of writing unit tests :",
487
            $record_after->subfield( $title_tag, $title_subfield ), "The journal of writing unit tests :",
488
            "Biblio title is correctly update by eholding title update"
488
            "Biblio title is correctly updated by eholding title update"
489
        );
489
        );
490
490
491
        is( $record->fields(), $record_after->fields(), "We have the same number of fields after edit" );
491
        is( $record->fields(), $record_after->fields(), "We have the same number of fields after edit" );
492
- 

Return to bug 35115