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

(-)a/C4/Calendar.pm (-8 / +30 lines)
Lines 690-703 sub copy_to_branch { Link Here
690
    my $today = sprintf ISO_DATE_FORMAT, $y,$m,$d;
690
    my $today = sprintf ISO_DATE_FORMAT, $y,$m,$d;
691
691
692
    my $wdh = $self->get_week_days_holidays;
692
    my $wdh = $self->get_week_days_holidays;
693
    $target_calendar->insert_week_day_holiday( weekday => $_, %{ $wdh->{$_} } )
693
    my $target_wdh = $target_calendar->get_week_days_holidays;
694
      foreach keys %$wdh;
694
    foreach my $key (keys %$wdh) {
695
    $target_calendar->insert_day_month_holiday(%$_)
695
        unless (grep { $_ eq $key } keys %$target_wdh) {
696
      foreach values %{ $self->get_day_month_holidays };
696
            $target_calendar->insert_week_day_holiday( weekday => $key, %{ $wdh->{$key} } )
697
    $target_calendar->insert_exception_holiday(%$_)
697
        }
698
      foreach grep { $_->{date} gt $today } values %{ $self->get_exception_holidays };
698
    }
699
    $target_calendar->insert_single_holiday(%$_)
699
700
      foreach grep { $_->{date} gt $today } values %{ $self->get_single_holidays };
700
    my $dmh = $self->get_day_month_holidays;
701
    my $target_dmh = $target_calendar->get_day_month_holidays;
702
    foreach my $values (values %$dmh) {
703
        unless (grep { $_->{day} eq $values->{day} && $_->{month} eq $values->{month} } values %$target_dmh) {
704
            $target_calendar->insert_day_month_holiday(%{ $values });
705
        }
706
    }
707
708
    my $exception_holidays = $self->get_exception_holidays;
709
    my $target_exceptions = $target_calendar->get_exception_holidays;
710
    foreach my $values ( grep {$_->{date} gt $today} values %{ $exception_holidays }) {
711
        unless ( grep { $_->{date} eq $values->{date} } values %$target_exceptions) {
712
            $target_calendar->insert_exception_holiday(%{ $values });
713
        }
714
    }
715
716
    my $single_holidays = $self->get_single_holidays;
717
    my $target_singles = $target_calendar->get_single_holidays;
718
    foreach my $values ( grep {$_->{date} gt $today} values %{ $single_holidays }) {
719
        unless ( grep { $_->{date} eq $values->{date} } values %$target_singles){
720
            $target_calendar->insert_single_holiday(%{ $values });
721
        }
722
    }
701
723
702
    return 1;
724
    return 1;
703
}
725
}
(-)a/t/db_dependent/Holidays.t (-15 / +14 lines)
Lines 204-210 sub _add_exception { Link Here
204
$schema->storage->txn_rollback;
204
$schema->storage->txn_rollback;
205
205
206
subtest 'copy_to_branch' => sub {
206
subtest 'copy_to_branch' => sub {
207
    
207
208
    plan tests => 8;
208
    plan tests => 8;
209
209
210
    $schema->storage->txn_begin;
210
    $schema->storage->txn_begin;
Lines 281-292 subtest 'copy_to_branch' => sub { Link Here
281
281
282
    #Select all rows with same values from database
282
    #Select all rows with same values from database
283
    my $dbh = C4::Context->dbh;
283
    my $dbh = C4::Context->dbh;
284
    my $get_repeatable_holidays = "SELECT a.* FROM repeatable_holidays a 
284
    my $get_repeatable_holidays = "SELECT a.* FROM repeatable_holidays a
285
        JOIN (SELECT branchcode, weekday, day, month, COUNT(*) 
285
        JOIN (SELECT branchcode, weekday, day, month, COUNT(*)
286
        FROM repeatable_holidays 
286
        FROM repeatable_holidays
287
        GROUP BY branchcode, weekday, day, month HAVING count(*) > 1) b 
287
        GROUP BY branchcode, weekday, day, month HAVING count(*) > 1) b
288
        ON a.branchcode = b.branchcode 
288
        ON a.branchcode = b.branchcode
289
        AND ( a.weekday = b.weekday OR (a.day = b.day AND a.month = b.month)) 
289
        AND ( a.weekday = b.weekday OR (a.day = b.day AND a.month = b.month))
290
        ORDER BY a.branchcode;";
290
        ORDER BY a.branchcode;";
291
    my $sth  = $dbh->prepare($get_repeatable_holidays);
291
    my $sth  = $dbh->prepare($get_repeatable_holidays);
292
    $sth->execute;
292
    $sth->execute;
Lines 295-308 subtest 'copy_to_branch' => sub { Link Here
295
    while(my $row = $sth->fetchrow_hashref){
295
    while(my $row = $sth->fetchrow_hashref){
296
        push @repeatable_holidays, $row
296
        push @repeatable_holidays, $row
297
    }
297
    }
298
    
298
299
    is( scalar(@repeatable_holidays), 0, "None of the repeatable holidays were doubled");
299
    is( scalar(@repeatable_holidays), 0, "None of the repeatable holidays were doubled");
300
300
301
    my $get_special_holidays = "SELECT a.* FROM special_holidays a 
301
    my $get_special_holidays = "SELECT a.* FROM special_holidays a
302
    JOIN (SELECT branchcode, day, month, year, isexception, COUNT(*) 
302
    JOIN (SELECT branchcode, day, month, year, isexception, COUNT(*)
303
    FROM special_holidays 
303
    FROM special_holidays
304
    GROUP BY branchcode, day, month, year, isexception HAVING count(*) > 1) b 
304
    GROUP BY branchcode, day, month, year, isexception HAVING count(*) > 1) b
305
    ON a.branchcode = b.branchcode 
305
    ON a.branchcode = b.branchcode
306
    AND a.day = b.day AND a.month = b.month AND a.year = b.year AND a.isexception = b.isexception
306
    AND a.day = b.day AND a.month = b.month AND a.year = b.year AND a.isexception = b.isexception
307
    ORDER BY a.branchcode;";
307
    ORDER BY a.branchcode;";
308
    $sth  = $dbh->prepare($get_special_holidays);
308
    $sth  = $dbh->prepare($get_special_holidays);
Lines 317-320 subtest 'copy_to_branch' => sub { Link Here
317
317
318
    $schema->storage->txn_rollback;
318
    $schema->storage->txn_rollback;
319
319
320
}
320
};
321
- 

Return to bug 19475