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

(-)a/Koha/Objects.pm (-2 / +5 lines)
Lines 257-263 sub update { Link Here
257
257
258
my $filtered_objects = $objects->filter_by_last_update
258
my $filtered_objects = $objects->filter_by_last_update
259
259
260
days exclusive
260
days exclusive by default (will be inclusive if days_inclusive is passed and set)
261
from inclusive
261
from inclusive
262
to   inclusive
262
to   inclusive
263
263
Lines 266-271 to inclusive Link Here
266
sub filter_by_last_update {
266
sub filter_by_last_update {
267
    my ( $self, $params ) = @_;
267
    my ( $self, $params ) = @_;
268
    my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp';
268
    my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp';
269
    my $days_inclusive = $params->{days_inclusive} || 0;
269
    my $conditions;
270
    my $conditions;
270
    Koha::Exceptions::MissingParameter->throw(
271
    Koha::Exceptions::MissingParameter->throw(
271
        "Missing mandatory parameter: days or from or to")
272
        "Missing mandatory parameter: days or from or to")
Lines 275-281 sub filter_by_last_update { Link Here
275
276
276
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
277
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
277
    if ( exists $params->{days} ) {
278
    if ( exists $params->{days} ) {
278
        $conditions->{'<'} = $dtf->format_date( dt_from_string->subtract( days => $params->{days} ) );
279
        my $dt = Koha::DateUtils::dt_from_string();
280
        my $operator = $days_inclusive ? '<=' : '<';
281
        $conditions->{$operator} = $dtf->format_date( $dt->subtract( days => $params->{days} ) );
279
    }
282
    }
280
    if ( exists $params->{from} ) {
283
    if ( exists $params->{from} ) {
281
        my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from});
284
        my $from = ref($params->{from}) ? $params->{from} : dt_from_string($params->{from});
(-)a/Koha/Patrons.pm (-6 / +8 lines)
Lines 243-254 sub delete { Link Here
243
243
244
sub filter_by_dateexpiry {
244
sub filter_by_dateexpiry {
245
    my ( $class, $params ) = @_;
245
    my ( $class, $params ) = @_;
246
    my $days = $params->{days} || 0;
246
247
    my $parser = Koha::Database->new->schema->storage->datetime_parser;
247
    return $class->filter_by_last_update(
248
    my $dt = dt_from_string()->subtract( days => $days );
248
        {
249
    return $class->search({
249
            timestamp_column_name => 'dateexpiry',
250
        dateexpiry => { '<=' => $parser->format_datetime($dt) },
250
            days                  => $params->{days} || 0,
251
    });
251
            days_inclusive        => 1,
252
        }
253
    );
252
}
254
}
253
255
254
=head3 search_unsubscribed
256
=head3 search_unsubscribed
(-)a/t/db_dependent/Koha/Objects.t (-1 / +12 lines)
Lines 1102-1115 subtest "filter_by_last_update" => sub { Link Here
1102
    is( $count, 3, '3 patrons have been updated before the last 2 days (exclusive)' );
1102
    is( $count, 3, '3 patrons have been updated before the last 2 days (exclusive)' );
1103
1103
1104
    $count = $patrons->filter_by_last_update(
1104
    $count = $patrons->filter_by_last_update(
1105
        { timestamp_column_name => 'updated_on', days => 2, days_inclusive => 1 } )->count;
1106
    is( $count, 4, '4 patrons have been updated before the last 2 days (inclusive)' );
1107
1108
    $count = $patrons->filter_by_last_update(
1105
        { timestamp_column_name => 'updated_on', days => 1 } )->count;
1109
        { timestamp_column_name => 'updated_on', days => 1 } )->count;
1106
    is( $count, 4, '4 patrons have been updated before yesterday (exclusive)' );
1110
    is( $count, 4, '4 patrons have been updated before yesterday (exclusive)' );
1107
1111
1108
    $count = $patrons->filter_by_last_update(
1112
    $count = $patrons->filter_by_last_update(
1113
        { timestamp_column_name => 'updated_on', days => 1, days_inclusive => 1 } )->count;
1114
    is( $count, 5, '5 patrons have been updated before yesterday (inclusive)' );
1115
1116
    $count = $patrons->filter_by_last_update(
1109
        { timestamp_column_name => 'updated_on', days => 0 } )->count;
1117
        { timestamp_column_name => 'updated_on', days => 0 } )->count;
1110
    is( $count, 5, '5 patrons have been updated before today (exclusive)' );
1118
    is( $count, 5, '5 patrons have been updated before today (exclusive)' );
1111
1119
1112
    $count = $patrons->filter_by_last_update(
1120
    $count = $patrons->filter_by_last_update(
1121
        { timestamp_column_name => 'updated_on', days => 0, days_inclusive => 1 } )->count;
1122
    is( $count, 6, '6 patrons have been updated before today (inclusive)' );
1123
1124
    $count = $patrons->filter_by_last_update(
1113
        { timestamp_column_name => 'updated_on', from => $now } )->count;
1125
        { timestamp_column_name => 'updated_on', from => $now } )->count;
1114
    is( $count, 1, '1 patron has been updated "from today" (inclusive)' );
1126
    is( $count, 1, '1 patron has been updated "from today" (inclusive)' );
1115
1127
1116
- 

Return to bug 21549