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

(-)a/authorities/merge.pl (-33 / +27 lines)
Lines 23-33 use CGI qw ( -utf8 ); Link Here
23
use C4::Output;
23
use C4::Output;
24
use C4::Auth;
24
use C4::Auth;
25
use C4::AuthoritiesMarc;
25
use C4::AuthoritiesMarc;
26
use Koha::MetadataRecord::Authority;
27
use C4::Koha;
26
use C4::Koha;
28
use C4::Biblio;
27
use C4::Biblio;
29
28
29
use Koha::Authority::Types;
30
use Koha::Exceptions;
30
use Koha::Exceptions;
31
use Koha::MetadataRecord::Authority;
31
32
32
my $input  = new CGI;
33
my $input  = new CGI;
33
my @authid = $input->multi_param('authid');
34
my @authid = $input->multi_param('authid');
Lines 52-63 if ($merge) { Link Here
52
53
53
    # Creating a new record from the html code
54
    # Creating a new record from the html code
54
    my $record   = TransformHtmlToMarc($input, 0);
55
    my $record   = TransformHtmlToMarc($input, 0);
55
    my $recordid1   = $input->param('recordid1');
56
    my $recordid1   = $input->param('recordid1') // q{};
56
    my $recordid2   = $input->param('recordid2');
57
    my $recordid2   = $input->param('recordid2') // q{};
57
    my $typecode = $input->param('frameworkcode');
58
    my $typecode = $input->param('frameworkcode');
58
59
60
    # Some error checking
61
    if( $recordid1 eq $recordid2 ) {
62
        push @errors, { code => 'DESTRUCTIVE_MERGE' };
63
    } elsif( !$typecode || !Koha::Authority::Types->find($typecode) ) {
64
        push @errors, { code => 'WRONG_FRAMEWORK' };
65
    } elsif( scalar $record->fields == 0 ) {
66
        push @errors, { code => 'EMPTY_MARC' };
67
    }
68
    if( @errors ) {
69
        $template->param( errors => \@errors );
70
        output_html_with_http_headers $input, $cookie, $template->output;
71
        exit;
72
    }
73
59
    # Rewriting the leader
74
    # Rewriting the leader
60
    $record->leader( GetAuthority($recordid1)->leader() );
75
    if( my $authrec = GetAuthority($recordid1) ) {
76
        $record->leader( $authrec->leader() );
77
    }
61
78
62
    # Modifying the reference record
79
    # Modifying the reference record
63
    # This triggers a merge for the biblios attached to $recordid1
80
    # This triggers a merge for the biblios attached to $recordid1
Lines 87-94 else { Link Here
87
104
88
    if ( scalar(@authid) != 2 ) {
105
    if ( scalar(@authid) != 2 ) {
89
        push @errors, { code => "WRONG_COUNT", value => scalar(@authid) };
106
        push @errors, { code => "WRONG_COUNT", value => scalar(@authid) };
90
    }
107
    } elsif( $authid[0] eq $authid[1] ) {
91
    else {
108
        push @errors, { code => 'DESTRUCTIVE_MERGE' };
109
    } else {
92
        my $recordObj1 = Koha::MetadataRecord::Authority->get_from_authid($authid[0]);
110
        my $recordObj1 = Koha::MetadataRecord::Authority->get_from_authid($authid[0]);
93
        Koha::Exceptions::ObjectNotFound->throw( "No authority record found for authid $authid[0]\n" ) if !$recordObj1;
111
        Koha::Exceptions::ObjectNotFound->throw( "No authority record found for authid $authid[0]\n" ) if !$recordObj1;
94
112
Lines 104-111 else { Link Here
104
122
105
            my $framework;
123
            my $framework;
106
            if ( $recordObj1->authtypecode ne $recordObj2->authtypecode && $mergereference ne 'breeding' ) {
124
            if ( $recordObj1->authtypecode ne $recordObj2->authtypecode && $mergereference ne 'breeding' ) {
107
                $framework = $input->param('frameworkcode')
125
                $framework = $input->param('frameworkcode');
108
                  or push @errors, { code => 'FRAMEWORK_NOT_SELECTED' };
109
            }
126
            }
110
            else {
127
            else {
111
                $framework = $recordObj1->authtypecode;
128
                $framework = $recordObj1->authtypecode;
Lines 167-183 else { Link Here
167
                title2          => $recordObj2->authorized_heading,
184
                title2          => $recordObj2->authorized_heading,
168
            );
185
            );
169
            if ( $recordObj1->authtypecode ne $recordObj2->authtypecode ) {
186
            if ( $recordObj1->authtypecode ne $recordObj2->authtypecode ) {
170
                my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } );
187
                my $authority_types = Koha::Authority::Types->search( { authtypecode => { '!=' => '' } }, { order_by => ['authtypecode'] } );
171
                my @frameworkselect;
172
                while ( my $authority_type = $authority_types->next ) {
173
                    my %row = (
174
                        value => $authority_type->authtypecode,
175
                        frameworktext => $authority_type->authtypetext,
176
                    );
177
                    push @frameworkselect, \%row;
178
                }
179
                $template->param(
188
                $template->param(
180
                    frameworkselect => \@frameworkselect,
189
                    frameworkselect => $authority_types->unblessed,
181
                    frameworkcode1  => $recordObj1->authtypecode,
190
                    frameworkcode1  => $recordObj1->authtypecode,
182
                    frameworkcode2  => $recordObj2->authtypecode,
191
                    frameworkcode2  => $recordObj2->authtypecode,
183
                );
192
                );
Lines 186-207 else { Link Here
186
    }
195
    }
187
}
196
}
188
197
189
my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']});
190
$template->param( authority_types => $authority_types );
191
192
if (@errors) {
198
if (@errors) {
193
194
    # Errors
195
    $template->param( errors => \@errors );
199
    $template->param( errors => \@errors );
196
}
200
}
197
198
output_html_with_http_headers $input, $cookie, $template->output;
201
output_html_with_http_headers $input, $cookie, $template->output;
199
exit;
200
201
=head1 FUNCTIONS
202
203
=cut
204
205
# ------------------------
206
# Functions
207
# ------------------------
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt (-36 / +23 lines)
Lines 54-84 function changeFramework(fw) { Link Here
54
54
55
55
56
<h1>Merging records</h1>
56
<h1>Merging records</h1>
57
[% IF ( result ) %]
57
58
    [% IF ( errors ) %]
58
[% IF ( errors ) %]
59
59
60
    [% FOREACH error IN errors %]
60
    [% FOREACH error IN errors %]
61
        <div class="dialog alert">
61
        <div class="dialog alert">
62
62
            [% IF error.code == 'WRONG_COUNT' %]
63
                [% IF error.code == 'CANNOT_MOVE' %]
63
                Number of records provided for merging: [% error.value %]. Currently only 2 records can be merged at a time.
64
                    The following items could not be moved from the old record to the new one: [% error.value %]
64
            [% ELSIF error.code == 'DESTRUCTIVE_MERGE' %]
65
                [% ELSIF error.code == 'FRAMEWORK_NOT_SELECTED' %]
65
                You cannot merge a record with itself. Please select two different authorities.
66
                    No framework has been selected. Please select a framework for merging.
66
            [% ELSIF error.code == 'WRONG_FRAMEWORK' %]
67
                [% ELSE %]
67
                The Default framework cannot be used, or the framework does not exist. Please select another framework for merging.
68
                    [% error %]
68
            [% ELSIF error.code == 'EMPTY_MARC' %]
69
                [% END %]
69
                Sorry, but we did not find any MARC tags in the reference record.
70
70
            [% ELSE %]
71
            <br />Therefore, the record to be merged has not been deleted.</div>
71
                [% error %]
72
            [% END %]
73
        </div>
72
    [% END %]
74
    [% END %]
73
75
74
    [% ELSE %]
76
[% ELSIF ( result ) %]
77
75
        <script type="text/javascript">window.location.href="/cgi-bin/koha/authorities/detail.pl?authid=[% recordid1 %]"</script>
78
        <script type="text/javascript">window.location.href="/cgi-bin/koha/authorities/detail.pl?authid=[% recordid1 %]"</script>
76
        <p>The merging was successful. <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% recordid1 %]">Click here to see the merged record.</a></p>
79
        <p>The merging was successful. <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% recordid1 %]">Click here to see the merged record.</a></p>
77
    [% END %]
78
80
79
[% ELSE %]
81
[% ELSIF ( choosereference ) %]
80
82
81
[% IF ( choosereference ) %]
82
<p>Please choose which record will be the reference for the merge. The record chosen as reference will be kept, and the other will be deleted.</p>
83
<p>Please choose which record will be the reference for the merge. The record chosen as reference will be kept, and the other will be deleted.</p>
83
<form id="mergeform" action="/cgi-bin/koha/authorities/merge.pl" method="post">
84
<form id="mergeform" action="/cgi-bin/koha/authorities/merge.pl" method="post">
84
    <fieldset class="rows">
85
    <fieldset class="rows">
Lines 92-102 function changeFramework(fw) { Link Here
92
                      <select name="frameworkcode" id="frameworkcode">
93
                      <select name="frameworkcode" id="frameworkcode">
93
                                      [% FOREACH frameworkcodeloo IN frameworkselect %]
94
                                      [% FOREACH frameworkcodeloo IN frameworkselect %]
94
                                          [% IF frameworkcodeloo.authtypecode == frameworkcode1 %]
95
                                          [% IF frameworkcodeloo.authtypecode == frameworkcode1 %]
95
                                              <option value="[% frameworkcodeloo.value %]" selected="selected">
96
                                              <option value="[% frameworkcodeloo.authtypecode %]" selected="selected">
96
                                          [% ELSE %]
97
                                          [% ELSE %]
97
                                              <option value="[% frameworkcodeloo.value %]">
98
                                              <option value="[% frameworkcodeloo.authtypecode %]">
98
                                          [% END %]
99
                                          [% END %]
99
                                           [% frameworkcodeloo.frameworktext %]
100
                                           [% frameworkcodeloo.authtypetext %]
100
                                           </option>
101
                                           </option>
101
                                      [% END %]
102
                                      [% END %]
102
                      </select></li>
103
                      </select></li>
Lines 108-128 function changeFramework(fw) { Link Here
108
    <fieldset class="action"><input type="submit" value="Next" /></fieldset>
109
    <fieldset class="action"><input type="submit" value="Next" /></fieldset>
109
    </fieldset>
110
    </fieldset>
110
</form>
111
</form>
112
111
[% ELSE %]
113
[% ELSE %]
112
[% IF ( errors ) %]
114
113
    <div class="dialog alert">
114
    [% FOREACH error IN errors %]
115
        <p>
116
                [% IF error.code == 'WRONG_COUNT' %]
117
                    Number of records provided for merging: [% error.value %]. Currently only 2 records can be merged at a time.
118
                [% ELSE %]
119
                    [% error %]
120
                [% END %]
121
122
            </p>
123
    [% END %]
124
    </div>
125
[% ELSE %]
126
<form id="mergeform" action="/cgi-bin/koha/authorities/merge.pl" method="post" onsubmit="return mergeformsubmit()">
115
<form id="mergeform" action="/cgi-bin/koha/authorities/merge.pl" method="post" onsubmit="return mergeformsubmit()">
127
116
128
<div class="yui-g">
117
<div class="yui-g">
Lines 141-148 function changeFramework(fw) { Link Here
141
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
130
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
142
</div>
131
</div>
143
</form>
132
</form>
144
[% END %]
133
145
[% END %]
146
[% END %]
134
[% END %]
147
135
148
</div>
136
</div>
149
- 

Return to bug 17380