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

(-)a/Koha/DiscreteCalendar.pm (+41 lines)
Lines 175-180 sub add_new_branch { Link Here
175
            branchcode => $copyBranch
175
            branchcode => $copyBranch
176
    });
176
    });
177
177
178
    unless ($branch_rs->count) {
179
        $copyBranch = Koha::Libraries->next->branchcode;
180
        $branch_rs = $schema->resultset('DiscreteCalendar')->search({
181
            branchcode => $copyBranch
182
        });
183
    }
184
185
    $schema->{AutoCommit} = 0;
186
    $schema->storage->txn_begin;
187
178
    while (my $row = $branch_rs->next()) {
188
    while (my $row = $branch_rs->next()) {
179
        $schema->resultset('DiscreteCalendar')->create({
189
        $schema->resultset('DiscreteCalendar')->create({
180
            date         => $row->date(),
190
            date         => $row->date(),
Lines 186-193 sub add_new_branch { Link Here
186
        });
196
        });
187
    }
197
    }
188
198
199
    eval { $schema->storage->txn_commit; };
200
201
    if ($@) {
202
        $schema->storage->rollback;
203
    }
204
205
    $schema->{AutoCommit} = 1;
189
}
206
}
190
207
208
=head2 delete_branch
209
210
    Koha::DiscreteCalendar->delete_branch($branchcode)
211
212
This method will delete every discrete_calendar entry for a given branch
213
C<$branchcode> is the code of the branch we want to remove from the table
214
215
=cut
216
217
sub delete_branch {
218
    my ( $classname, $branchcode ) = @_;
219
220
    my $schema = Koha::Database->new->schema;
221
222
    my $branch_rs = $schema->resultset('DiscreteCalendar')->search({
223
            branchcode => $branchcode
224
    });
225
226
    if ($branch_rs->count) {
227
        $branch_rs->delete;
228
    }
229
}
230
231
191
=head2 get_date_info
232
=head2 get_date_info
192
233
193
    my $date = $calendar->get_date_info;
234
    my $date = $calendar->get_date_info;
(-)a/admin/branches.pl (-1 / +3 lines)
Lines 148-153 if ( $op eq 'add_form' ) { Link Here
148
                        }
148
                        }
149
                    }
149
                    }
150
150
151
                    Koha::DiscreteCalendar->add_new_branch(undef, $branchcode);
152
151
                    push @messages, { type => 'message', code => 'success_on_insert' };
153
                    push @messages, { type => 'message', code => 'success_on_insert' };
152
                }
154
                }
153
            );
155
            );
Lines 193-198 if ( $op eq 'add_form' ) { Link Here
193
    if ( $@ or not $deleted ) {
195
    if ( $@ or not $deleted ) {
194
        push @messages, { type => 'alert', code => 'error_on_delete' };
196
        push @messages, { type => 'alert', code => 'error_on_delete' };
195
    } else {
197
    } else {
198
        Koha::DiscreteCalendar->delete_branch($branchcode);
196
        push @messages, { type => 'message', code => 'success_on_delete' };
199
        push @messages, { type => 'message', code => 'success_on_delete' };
197
    }
200
    }
198
    $op = 'list';
201
    $op = 'list';
199
- 

Return to bug 17015