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

Return to bug 30255