Bug 42310: (QA follow-up) Clean up stale references to dropped calendar tables

- cleanup_database.pl: rewrite DeleteSpecialHolidays to purge the new
  library_single_closures and library_closure_exceptions tables via their
  Koha::Objects classes (was querying the dropped special_holidays table).
- kohastructure.sql: fix the comment header above library_repeating_closures
  that still referred to repeatable_holidays.
- C4::Overdues: drop the dead GetSpecialHolidays / GetRepeatableHolidays /
  GetWdayFromItemnumber routines (unreferenced, exported nowhere) that still
  queried the dropped special_holidays / repeatable_holidays tables, along
  with the now-unused Date::Calc and Date::Manip imports.

Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Tomás Cohen Arazi 2026-09-15 11:27:36 -03:00 committed by Pedro Amorim
parent 51fd136eb1
commit 76d156d4fc
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
3 changed files with 10 additions and 135 deletions

View File

@ -37,8 +37,6 @@ BEGIN {
); );
} }
use Date::Calc qw( Today );
use Date::Manip qw( UnixDate );
use List::MoreUtils qw( uniq ); use List::MoreUtils qw( uniq );
use POSIX qw( ceil floor ); use POSIX qw( ceil floor );
use Locale::Currency::Format 1.28 qw( currency_format FMT_SYMBOL ); use Locale::Currency::Format 1.28 qw( currency_format FMT_SYMBOL );
@ -370,131 +368,6 @@ sub get_chargeable_units {
} }
} }
=head2 GetSpecialHolidays
&GetSpecialHolidays($date_dues,$itemnumber);
return number of special days between date of the day and date due
C<$date_dues> is the envisaged date of book return.
C<$itemnumber> is the book's item number.
=cut
sub GetSpecialHolidays {
my ( $date_dues, $itemnumber ) = @_;
# calcul the today date
my $today = join "-", &Today();
# return the holdingbranch
my $iteminfo = GetIssuesIteminfo($itemnumber);
# use sql request to find all date between date_due and today
my $dbh = C4::Context->dbh;
my $query = qq|SELECT DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d') as date
FROM `special_holidays`
WHERE DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d') >= ?
AND DATE_FORMAT(concat(year,'-',month,'-',day),'%Y-%m-%d') <= ?
AND branchcode=?
|;
my @result = GetWdayFromItemnumber($itemnumber);
my @result_date;
my $wday;
my $dateinsec;
my $sth = $dbh->prepare($query);
$sth->execute( $date_dues, $today, $iteminfo->{'branchcode'} )
; # FIXME: just use NOW() in SQL instead of passing in $today
while ( my $special_date = $sth->fetchrow_hashref ) {
push( @result_date, $special_date );
}
my $specialdaycount = scalar(@result_date);
for ( my $i = 0 ; $i < scalar(@result_date) ; $i++ ) {
$dateinsec = UnixDate( $result_date[$i]->{'date'}, "%o" );
( undef, undef, undef, undef, undef, undef, $wday, undef, undef ) = localtime($dateinsec);
for ( my $j = 0 ; $j < scalar(@result) ; $j++ ) {
if ( $wday == ( $result[$j]->{'weekday'} ) ) {
$specialdaycount--;
}
}
}
return $specialdaycount;
}
=head2 GetRepeatableHolidays
&GetRepeatableHolidays($date_dues, $itemnumber, $difference,);
return number of day closed between date of the day and date due
C<$date_dues> is the envisaged date of book return.
C<$itemnumber> is item number.
C<$difference> numbers of between day date of the day and date due
=cut
sub GetRepeatableHolidays {
my ( $date_dues, $itemnumber, $difference ) = @_;
my $dateinsec = UnixDate( $date_dues, "%o" );
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime($dateinsec);
my @result = GetWdayFromItemnumber($itemnumber);
my @dayclosedcount;
my $j;
for ( my $i = 0 ; $i < scalar(@result) ; $i++ ) {
my $k = $wday;
for ( $j = 0 ; $j < $difference ; $j++ ) {
if ( $result[$i]->{'weekday'} == $k ) {
push( @dayclosedcount, $k );
}
$k++;
( $k = 0 ) if ( $k eq 7 );
}
}
return scalar(@dayclosedcount);
}
=head2 GetWayFromItemnumber
&Getwdayfromitemnumber($itemnumber);
return the different week day from repeatable_holidays table
C<$itemnumber> is item number.
=cut
=head2 GetWdayFromItemnumber
Missing POD for GetWdayFromItemnumber.
=cut
sub GetWdayFromItemnumber {
my ($itemnumber) = @_;
my $iteminfo = GetIssuesIteminfo($itemnumber);
my @result;
my $query = qq|SELECT weekday
FROM repeatable_holidays
WHERE branchcode=?
|;
my $sth = C4::Context->dbh->prepare($query);
$sth->execute( $iteminfo->{'branchcode'} );
while ( my $weekday = $sth->fetchrow_hashref ) {
push( @result, $weekday );
}
return @result;
}
=head2 GetIssuesIteminfo =head2 GetIssuesIteminfo
&GetIssuesIteminfo($itemnumber); &GetIssuesIteminfo($itemnumber);

View File

@ -5770,7 +5770,7 @@ CREATE TABLE `record_sources` (
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
-- Table structure for table `repeatable_holidays` -- Table structure for table `library_repeating_closures`
-- --
DROP TABLE IF EXISTS `library_repeating_closures`; DROP TABLE IF EXISTS `library_repeating_closures`;

View File

@ -48,6 +48,8 @@ use Koha::BackgroundJobs;
use Koha::Database; use Koha::Database;
use Koha::DateUtils qw( dt_from_string ); use Koha::DateUtils qw( dt_from_string );
use Koha::Item::Transfers; use Koha::Item::Transfers;
use Koha::Library::Calendar::Exceptions;
use Koha::Library::Calendar::SingleClosures;
use Koha::Old::Biblioitems; use Koha::Old::Biblioitems;
use Koha::Old::Biblios; use Koha::Old::Biblios;
use Koha::Old::Checkouts; use Koha::Old::Checkouts;
@ -1015,13 +1017,13 @@ sub PurgeCreatorBatches {
sub DeleteSpecialHolidays { sub DeleteSpecialHolidays {
my ($days) = @_; my ($days) = @_;
my $sth = $dbh->prepare( my $dtf = Koha::Database->new->schema->storage->datetime_parser;
q{ my $cutoff = $dtf->format_date( dt_from_string->subtract( days => $days ) );
DELETE FROM special_holidays
WHERE DATE( CONCAT( year, '-', month, '-', day ) ) < DATE_SUB( CAST(NOW() AS DATE), INTERVAL ? DAY ); my $count = 0;
} $count += Koha::Library::Calendar::SingleClosures->search( { date => { '<' => $cutoff } } )->delete + 0;
); $count += Koha::Library::Calendar::Exceptions->search( { date => { '<' => $cutoff } } )->delete + 0;
my $count = $sth->execute($days) + 0;
print "Removed $count unique holidays\n" if $verbose; print "Removed $count unique holidays\n" if $verbose;
} }