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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt (-3 / +1 lines)
Lines 171-179 Link Here
171
                </ol>
171
                </ol>
172
            </fieldset>
172
            </fieldset>
173
            <fieldset class="brief" id="modify_all_hint" style="display: none;">
173
            <fieldset class="brief" id="modify_all_hint" style="display: none;">
174
                <div class="hint">
174
                <div class="hint"> This will perform the modifications directly, without a confirmation step. </div>
175
                    This will perform the modifications directly, without a confirmation step.
176
                </div>
177
            </fieldset>
175
            </fieldset>
178
            <fieldset class="action">
176
            <fieldset class="action">
179
                <input type="hidden" name="op" value="cud-list" />
177
                <input type="hidden" name="op" value="cud-list" />
(-)a/tools/batch_delete_records.pl (-26 / +33 lines)
Lines 60-81 my $enqueue_job = sub { Link Here
60
60
61
    try {
61
    try {
62
        my $params = {
62
        my $params = {
63
            record_ids  => $record_ids,
63
            record_ids => $record_ids,
64
        };
64
        };
65
65
66
        my $job_id =
66
        my $job_id =
67
          $recordtype eq 'biblio'
67
            $recordtype eq 'biblio'
68
          ? Koha::BackgroundJob::BatchDeleteBiblio->new->enqueue($params)
68
            ? Koha::BackgroundJob::BatchDeleteBiblio->new->enqueue($params)
69
          : Koha::BackgroundJob::BatchDeleteAuthority->new->enqueue($params);
69
            : Koha::BackgroundJob::BatchDeleteAuthority->new->enqueue($params);
70
70
71
        $template->param(
71
        $template->param(
72
            op => 'enqueued',
72
            op     => 'enqueued',
73
            job_id => $job_id,
73
            job_id => $job_id,
74
        );
74
        );
75
    } catch {
75
    } catch {
76
        push @messages, {
76
        push @messages, {
77
            type => 'error',
77
            type  => 'error',
78
            code => 'cannot_enqueue_job',
78
            code  => 'cannot_enqueue_job',
79
            error => $_,
79
            error => $_,
80
        };
80
        };
81
        $template->param( view => 'errors' );
81
        $template->param( view => 'errors' );
Lines 83-88 my $enqueue_job = sub { Link Here
83
};
83
};
84
84
85
if ( $op eq 'form' ) {
85
if ( $op eq 'form' ) {
86
86
    # Display the form
87
    # Display the form
87
    $template->param(
88
    $template->param(
88
        op    => 'form',
89
        op    => 'form',
Lines 94-99 if ( $op eq 'form' ) { Link Here
94
        )
95
        )
95
    );
96
    );
96
} elsif ( $op eq 'cud-list' || $op eq 'delete_all' ) {
97
} elsif ( $op eq 'cud-list' || $op eq 'delete_all' ) {
98
97
    # List all records to process
99
    # List all records to process
98
    my @record_ids;
100
    my @record_ids;
99
    if ( my $bib_list = $input->param('bib_list') ) {
101
    if ( my $bib_list = $input->param('bib_list') ) {
Lines 102-107 if ( $op eq 'form' ) { Link Here
102
        @record_ids = split /\//, $bib_list;
104
        @record_ids = split /\//, $bib_list;
103
        $recordtype = 'biblio';
105
        $recordtype = 'biblio';
104
    } elsif ( my $uploadfile = $input->param('uploadfile') ) {
106
    } elsif ( my $uploadfile = $input->param('uploadfile') ) {
107
105
        # A file of id is given
108
        # A file of id is given
106
        binmode $uploadfile, ':encoding(UTF-8)';
109
        binmode $uploadfile, ':encoding(UTF-8)';
107
        while ( my $content = <$uploadfile> ) {
110
        while ( my $content = <$uploadfile> ) {
Lines 117-146 if ( $op eq 'form' ) { Link Here
117
            push @record_ids, $biblionumber;
120
            push @record_ids, $biblionumber;
118
        }
121
        }
119
    } else {
122
    } else {
123
120
        # The user enters manually the list of id
124
        # The user enters manually the list of id
121
        push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') );
125
        push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') );
122
    }
126
    }
123
    if ( $op eq 'delete_all' ) {
127
    if ( $op eq 'delete_all' ) {
124
        $enqueue_job->(\@record_ids, $recordtype);
128
        $enqueue_job->( \@record_ids, $recordtype );
125
    }
129
    } else {
126
    else {
127
        for my $record_id ( uniq @record_ids ) {
130
        for my $record_id ( uniq @record_ids ) {
128
            if ( $recordtype eq 'biblio' ) {
131
            if ( $recordtype eq 'biblio' ) {
132
129
                # Retrieve biblio information
133
                # Retrieve biblio information
130
                my $biblio_object = Koha::Biblios->find( $record_id );
134
                my $biblio_object = Koha::Biblios->find($record_id);
131
                unless ( $biblio_object ) {
135
                unless ($biblio_object) {
132
                    push @messages, {
136
                    push @messages, {
133
                        type => 'warning',
137
                        type         => 'warning',
134
                        code => 'biblio_not_exists',
138
                        code         => 'biblio_not_exists',
135
                        biblionumber => $record_id,
139
                        biblionumber => $record_id,
136
                    };
140
                    };
137
                    next;
141
                    next;
138
                }
142
                }
139
                my $biblio = $biblio_object->unblessed;
143
                my $biblio = $biblio_object->unblessed;
140
                my $record = $biblio_object->metadata->record;
144
                my $record = $biblio_object->metadata->record;
141
                $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')];
145
                $biblio->{itemnumbers} =
142
                $biblio->{holds_count} = $biblio_object->holds->count;
146
                    [ Koha::Items->search( { biblionumber => $record_id } )->get_column('itemnumber') ];
143
                $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
147
                $biblio->{holds_count}         = $biblio_object->holds->count;
148
                $biblio->{issues_count}        = C4::Biblio::CountItemsIssued($record_id);
144
                $biblio->{subscriptions_count} = $biblio_object->subscriptions->count;
149
                $biblio->{subscriptions_count} = $biblio_object->subscriptions->count;
145
150
146
                # Respect skip_open_orders
151
                # Respect skip_open_orders
Lines 151-184 if ( $op eq 'form' ) { Link Here
151
156
152
                push @records, $biblio;
157
                push @records, $biblio;
153
            } else {
158
            } else {
159
154
                # Retrieve authority information
160
                # Retrieve authority information
155
                my $authority = C4::AuthoritiesMarc::GetAuthority( $record_id );
161
                my $authority = C4::AuthoritiesMarc::GetAuthority($record_id);
156
                unless ( $authority ) {
162
                unless ($authority) {
157
                    push @messages, {
163
                    push @messages, {
158
                        type => 'warning',
164
                        type   => 'warning',
159
                        code => 'authority_not_exists',
165
                        code   => 'authority_not_exists',
160
                        authid => $record_id,
166
                        authid => $record_id,
161
                    };
167
                    };
162
                    next;
168
                    next;
163
                }
169
                }
164
170
165
                $authority = {
171
                $authority = {
166
                    authid => $record_id,
172
                    authid      => $record_id,
167
                    summary => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ),
173
                    summary     => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ),
168
                    count_usage => Koha::Authorities->get_usage_count({ authid => $record_id }),
174
                    count_usage => Koha::Authorities->get_usage_count( { authid => $record_id } ),
169
                };
175
                };
170
                push @records, $authority;
176
                push @records, $authority;
171
            }
177
            }
172
            $template->param(
178
            $template->param(
173
                records => \@records,
179
                records => \@records,
174
                op => 'list',
180
                op      => 'list',
175
            );
181
            );
176
        }
182
        }
177
    }
183
    }
178
} elsif ( $op eq 'cud-delete' ) {
184
} elsif ( $op eq 'cud-delete' ) {
185
179
    # We want to delete selected records!
186
    # We want to delete selected records!
180
    my @record_ids = $input->multi_param('record_id');
187
    my @record_ids = $input->multi_param('record_id');
181
    $enqueue_job->(\@record_ids, $recordtype);
188
    $enqueue_job->( \@record_ids, $recordtype );
182
}
189
}
183
190
184
$template->param(
191
$template->param(
(-)a/tools/batch_record_modification.pl (-25 / +25 lines)
Lines 55-65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
55
    }
55
    }
56
);
56
);
57
57
58
59
my $enqueue_job = sub {
58
my $enqueue_job = sub {
60
    my ( $record_ids, $recordtype ) = @_;
59
    my ( $record_ids, $recordtype ) = @_;
61
    try {
60
    try {
62
        my $patron = Koha::Patrons->find( $loggedinuser );
61
        my $patron = Koha::Patrons->find($loggedinuser);
63
        my $params = {
62
        my $params = {
64
            mmtid           => $mmtid,
63
            mmtid           => $mmtid,
65
            record_ids      => $record_ids,
64
            record_ids      => $record_ids,
Lines 71-88 my $enqueue_job = sub { Link Here
71
        };
70
        };
72
71
73
        my $job_id =
72
        my $job_id =
74
          $recordtype eq 'biblio'
73
            $recordtype eq 'biblio'
75
          ? Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue($params)
74
            ? Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue($params)
76
          : Koha::BackgroundJob::BatchUpdateAuthority->new->enqueue($params);
75
            : Koha::BackgroundJob::BatchUpdateAuthority->new->enqueue($params);
77
76
78
        $template->param(
77
        $template->param(
79
            view => 'enqueued',
78
            view   => 'enqueued',
80
            job_id => $job_id,
79
            job_id => $job_id,
81
        );
80
        );
82
    } catch {
81
    } catch {
83
        push @messages, {
82
        push @messages, {
84
            type => 'error',
83
            type  => 'error',
85
            code => 'cannot_enqueue_job',
84
            code  => 'cannot_enqueue_job',
86
            error => $_,
85
            error => $_,
87
        };
86
        };
88
        $template->param( view => 'errors' );
87
        $template->param( view => 'errors' );
Lines 126-132 if ( $op eq 'form' ) { Link Here
126
            ]
125
            ]
127
        )
126
        )
128
    );
127
    );
129
} elsif ( $op eq 'cud-list' || $op eq 'modify_all') {
128
} elsif ( $op eq 'cud-list' || $op eq 'modify_all' ) {
130
129
131
    # List all records to process
130
    # List all records to process
132
    my ( @records, @record_ids );
131
    my ( @records, @record_ids );
Lines 158-207 if ( $op eq 'form' ) { Link Here
158
    }
157
    }
159
158
160
    if ( $op eq 'modify_all' ) {
159
    if ( $op eq 'modify_all' ) {
161
        $enqueue_job->(\@record_ids, $recordtype);
160
        $enqueue_job->( \@record_ids, $recordtype );
162
    }
161
    } else {
163
    else {
164
        for my $record_id ( uniq @record_ids ) {
162
        for my $record_id ( uniq @record_ids ) {
165
            if ( $recordtype eq 'biblio' ) {
163
            if ( $recordtype eq 'biblio' ) {
164
166
                # Retrieve biblio information
165
                # Retrieve biblio information
167
                my $biblio = Koha::Biblios->find( $record_id );
166
                my $biblio = Koha::Biblios->find($record_id);
168
                unless ( $biblio ) {
167
                unless ($biblio) {
169
                    push @messages, {
168
                    push @messages, {
170
                        type => 'warning',
169
                        type         => 'warning',
171
                        code => 'biblio_not_exists',
170
                        code         => 'biblio_not_exists',
172
                        biblionumber => $record_id,
171
                        biblionumber => $record_id,
173
                    };
172
                    };
174
                    next;
173
                    next;
175
                }
174
                }
176
                push @records, $biblio;
175
                push @records, $biblio;
177
            } else {
176
            } else {
177
178
                # Retrieve authority information
178
                # Retrieve authority information
179
                my $authority = Koha::MetadataRecord::Authority->get_from_authid( $record_id );
179
                my $authority = Koha::MetadataRecord::Authority->get_from_authid($record_id);
180
                unless ( $authority ) {
180
                unless ($authority) {
181
                    push @messages, {
181
                    push @messages, {
182
                        type => 'warning',
182
                        type   => 'warning',
183
                        code => 'authority_not_exists',
183
                        code   => 'authority_not_exists',
184
                        authid => $record_id,
184
                        authid => $record_id,
185
                    };
185
                    };
186
                    next;
186
                    next;
187
                }
187
                }
188
188
189
                push @records, {
189
                push @records, {
190
                    authid => $record_id,
190
                    authid  => $record_id,
191
                    summary => C4::AuthoritiesMarc::BuildSummary( $authority->record, $record_id ),
191
                    summary => C4::AuthoritiesMarc::BuildSummary( $authority->record, $record_id ),
192
                };
192
                };
193
            }
193
            }
194
            $template->param(
194
            $template->param(
195
                records => \@records,
195
                records => \@records,
196
                mmtid => $mmtid,
196
                mmtid   => $mmtid,
197
                view => 'list',
197
                view    => 'list',
198
            );
198
            );
199
        }
199
        }
200
    }
200
    }
201
} elsif ( $op eq 'cud-modify' ) {
201
} elsif ( $op eq 'cud-modify' ) {
202
202
    # We want to modify selected records!
203
    # We want to modify selected records!
203
    my @record_ids = $input->multi_param('record_id');
204
    my @record_ids = $input->multi_param('record_id');
204
    $enqueue_job->(\@record_ids, $recordtype);
205
    $enqueue_job->( \@record_ids, $recordtype );
205
}
206
}
206
207
207
$template->param(
208
$template->param(
208
- 

Return to bug 30255