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

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

Return to bug 17015