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

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

Return to bug 30255