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 / +7 lines)
Lines 129-136 Link Here
129
      </div> <!-- /.tab-content -->
129
      </div> <!-- /.tab-content -->
130
    </div>
130
    </div>
131
131
132
      <fieldset class="rows">
133
        <legend>Next step</legend>
134
        <ol>
135
          <li><label for="op_list">Select records to delete: </label><input type="radio" name="op" value="list" id="op_list" checked="checked" /></li>
136
          <li><label for="op_delete_all">Delete all: </label><input type="radio" name="op" value="delete_all" id="op_delete_all" /></li>
137
        </ol>
138
      </fieldset>
132
      <fieldset class="action">
139
      <fieldset class="action">
133
        <input type="hidden" name="op" value="list" />
134
        <input type="submit" class="btn btn-primary" value="Continue" />
140
        <input type="submit" class="btn btn-primary" value="Continue" />
135
        <a class="cancel" href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cancel</a>
141
        <a class="cancel" href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cancel</a>
136
      </fieldset>
142
      </fieldset>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt (-1 / +7 lines)
Lines 155-162 Link Here
155
                                    </li>
155
                                    </li>
156
                                </ol>
156
                                </ol>
157
                            </fieldset>
157
                            </fieldset>
158
                            <fieldset class="rows">
159
                                <legend>Next step</legend>
160
                                <ol>
161
                                    <li><label for="op_list">Select records to modify: </label><input type="radio" name="op" value="list" id="op_list" checked="checked" /></li>
162
                                    <li><label for="op_modify_all">Modify all: </label><input type="radio" name="op" value="modify_all" id="op_modify_all" /></li>
163
                                </ol>
164
                            </fieldset>
158
                            <fieldset class="action">
165
                            <fieldset class="action">
159
                                <input type="hidden" name="op" value="list" />
160
                                <input type="submit" class="btn btn-primary" value="Continue" />
166
                                <input type="submit" class="btn btn-primary" value="Continue" />
161
                                <a class="cancel" href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cancel</a>
167
                                <a class="cancel" href="/cgi-bin/koha/cataloguing/cataloging-home.pl">Cancel</a>
162
                            </fieldset>
168
                            </fieldset>
(-)a/tools/batch_delete_records.pl (-62 / +73 lines)
Lines 50-55 my ($template, $loggedinuser, $cookie) = get_template_and_user({ Link Here
50
50
51
my @records;
51
my @records;
52
my @messages;
52
my @messages;
53
54
my $enqueue_job = sub {
55
    my ($record_ids, $recordtype) = @_;
56
57
    try {
58
        my $params = {
59
            record_ids  => $record_ids,
60
        };
61
62
        my $job_id =
63
          $recordtype eq 'biblio'
64
          ? Koha::BackgroundJob::BatchDeleteBiblio->new->enqueue($params)
65
          : Koha::BackgroundJob::BatchDeleteAuthority->new->enqueue($params);
66
67
        $template->param(
68
            op => 'enqueued',
69
            job_id => $job_id,
70
        );
71
    } catch {
72
        push @messages, {
73
            type => 'error',
74
            code => 'cannot_enqueue_job',
75
            error => $_,
76
        };
77
        $template->param( view => 'errors' );
78
    };
79
};
80
53
if ( $op eq 'form' ) {
81
if ( $op eq 'form' ) {
54
    # Display the form
82
    # Display the form
55
    $template->param(
83
    $template->param(
Lines 61-67 if ( $op eq 'form' ) { Link Here
61
            ]
89
            ]
62
        )
90
        )
63
    );
91
    );
64
} elsif ( $op eq 'list' ) {
92
} elsif ( $op eq 'list' || $op eq 'delete_all' ) {
65
    # List all records to process
93
    # List all records to process
66
    my @record_ids;
94
    my @record_ids;
67
    if ( my $bib_list = $input->param('bib_list') ) {
95
    if ( my $bib_list = $input->param('bib_list') ) {
Lines 88-162 if ( $op eq 'form' ) { Link Here
88
        push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') );
116
        push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') );
89
    }
117
    }
90
118
91
    for my $record_id ( uniq @record_ids ) {
119
    if ( $op eq 'delete_all' ) {
92
        if ( $recordtype eq 'biblio' ) {
120
        $enqueue_job->(\@record_ids, $recordtype);
93
            # Retrieve biblio information
121
    }
94
            my $biblio_object = Koha::Biblios->find( $record_id );
122
    else {
95
            unless ( $biblio_object ) {
123
        for my $record_id ( uniq @record_ids ) {
96
                push @messages, {
124
            if ( $recordtype eq 'biblio' ) {
97
                    type => 'warning',
125
                # Retrieve biblio information
98
                    code => 'biblio_not_exists',
126
                my $biblio_object = Koha::Biblios->find( $record_id );
99
                    biblionumber => $record_id,
127
                unless ( $biblio_object ) {
100
                };
128
                    push @messages, {
101
                next;
129
                        type => 'warning',
102
            }
130
                        code => 'biblio_not_exists',
103
            my $biblio = $biblio_object->unblessed;
131
                        biblionumber => $record_id,
104
            my $record = $biblio_object->metadata->record;
132
                    };
105
            $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')];
133
                    next;
106
            $biblio->{holds_count} = $biblio_object->holds->count;
134
                }
107
            $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
135
                my $biblio = $biblio_object->unblessed;
108
            $biblio->{subscriptions_count} = $biblio_object->subscriptions->count;
136
                my $record = $biblio_object->metadata->record;
109
            push @records, $biblio;
137
                $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')];
110
        } else {
138
                $biblio->{holds_count} = $biblio_object->holds->count;
111
            # Retrieve authority information
139
                $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
112
            my $authority = C4::AuthoritiesMarc::GetAuthority( $record_id );
140
                $biblio->{subscriptions_count} = $biblio_object->subscriptions->count;
113
            unless ( $authority ) {
141
                push @records, $biblio;
114
                push @messages, {
142
            } else {
115
                    type => 'warning',
143
                # Retrieve authority information
116
                    code => 'authority_not_exists',
144
                my $authority = C4::AuthoritiesMarc::GetAuthority( $record_id );
145
                unless ( $authority ) {
146
                    push @messages, {
147
                        type => 'warning',
148
                        code => 'authority_not_exists',
149
                        authid => $record_id,
150
                    };
151
                    next;
152
                }
153
154
                $authority = {
117
                    authid => $record_id,
155
                    authid => $record_id,
156
                    summary => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ),
157
                    count_usage => Koha::Authorities->get_usage_count({ authid => $record_id }),
118
                };
158
                };
119
                next;
159
                push @records, $authority;
120
            }
160
            }
121
122
            $authority = {
123
                authid => $record_id,
124
                summary => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ),
125
                count_usage => Koha::Authorities->get_usage_count({ authid => $record_id }),
126
            };
127
            push @records, $authority;
128
        }
161
        }
162
        $template->param(
163
            records => \@records,
164
            op => 'list',
165
        );
129
    }
166
    }
130
    $template->param(
131
        records => \@records,
132
        op => 'list',
133
    );
134
} elsif ( $op eq 'delete' ) {
167
} elsif ( $op eq 'delete' ) {
135
    # We want to delete selected records!
168
    # We want to delete selected records!
136
    my @record_ids = $input->multi_param('record_id');
169
    my @record_ids = $input->multi_param('record_id');
137
170
    $enqueue_job->(\@record_ids, $recordtype);
138
    try {
139
        my $params = {
140
            record_ids  => \@record_ids,
141
        };
142
143
        my $job_id =
144
          $recordtype eq 'biblio'
145
          ? Koha::BackgroundJob::BatchDeleteBiblio->new->enqueue($params)
146
          : Koha::BackgroundJob::BatchDeleteAuthority->new->enqueue($params);
147
148
        $template->param(
149
            op => 'enqueued',
150
            job_id => $job_id,
151
        );
152
    } catch {
153
        push @messages, {
154
            type => 'error',
155
            code => 'cannot_enqueue_job',
156
            error => $_,
157
        };
158
        $template->param( view => 'errors' );
159
    };
160
}
171
}
161
172
162
$template->param(
173
$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 'list' ) {
125
} elsif ( $op eq '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 'modify' ) {
193
} elsif ( $op eq '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