Bugzilla – Attachment 171386 Details for
Bug 37905
Correctly fix the "last hour" filter on the job list
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Revert "Bug 36217: Fix background jobs page's include_last_hour filter"
Revert-Bug-36217-Fix-background-jobs-pages-include.patch (text/plain), 8.09 KB, created by
Jonathan Druart
on 2024-09-12 12:53:51 UTC
(
hide
)
Description:
Revert "Bug 36217: Fix background jobs page's include_last_hour filter"
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2024-09-12 12:53:51 UTC
Size:
8.09 KB
patch
obsolete
>From 356471c5ae037c98ffbabeadb58c2a73b90c63e7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 12 Sep 2024 14:27:02 +0200 >Subject: [PATCH] Revert "Bug 36217: Fix background jobs page's > include_last_hour filter" > >This reverts commit f5c839348091d129bb7100af2c9e64e486d0ea1d. > >https://bugs.koha-community.org/show_bug.cgi?id=37905 >--- > Koha/BackgroundJobs.pm | 14 ----- > Koha/REST/V1/BackgroundJobs.pm | 8 +-- > api/v1/swagger/paths/jobs.yaml | 5 -- > .../prog/en/modules/admin/background_jobs.tt | 37 ++++++++---- > t/db_dependent/Koha/BackgroundJobs.t | 60 +------------------ > 5 files changed, 27 insertions(+), 97 deletions(-) > >diff --git a/Koha/BackgroundJobs.pm b/Koha/BackgroundJobs.pm >index 1370fcb13cd..48afbf68fa8 100644 >--- a/Koha/BackgroundJobs.pm >+++ b/Koha/BackgroundJobs.pm >@@ -72,20 +72,6 @@ sub filter_by_current { > ); > } > >-=head3 filter_by_last_hour >- >- my $current_jobs = $jobs->filter_by_last_hour; >- >-Returns a new resultset, filtering out jobs that were enqueued more than an hour ago. >- >-=cut >- >-sub filter_by_last_hour { >- my ($self) = @_; >- >- return $self->search( { enqueued_on => { '>', \"NOW() - INTERVAL 1 HOUR" } } ); >-} >- > =head2 Internal methods > > =head3 _type >diff --git a/Koha/REST/V1/BackgroundJobs.pm b/Koha/REST/V1/BackgroundJobs.pm >index a55e1055416..87d715e8808 100644 >--- a/Koha/REST/V1/BackgroundJobs.pm >+++ b/Koha/REST/V1/BackgroundJobs.pm >@@ -38,10 +38,8 @@ sub list { > > return try { > >- my $only_current = $c->param('only_current'); >- my $only_last_hour = $c->param('only_last_hour'); >+ my $only_current = $c->param('only_current'); > $c->req->params->remove('only_current'); >- $c->req->params->remove('only_last_hour'); > > my $bj_rs = Koha::BackgroundJobs->new; > >@@ -49,10 +47,6 @@ sub list { > $bj_rs = $bj_rs->filter_by_current; > } > >- if ($only_last_hour) { >- $bj_rs = $bj_rs->filter_by_last_hour; >- } >- > return $c->render( > status => 200, > openapi => $c->objects->search($bj_rs) >diff --git a/api/v1/swagger/paths/jobs.yaml b/api/v1/swagger/paths/jobs.yaml >index a0442895624..7edd87dad22 100644 >--- a/api/v1/swagger/paths/jobs.yaml >+++ b/api/v1/swagger/paths/jobs.yaml >@@ -14,11 +14,6 @@ > required: false > type: boolean > description: Only include current jobs >- - name: only_last_hour >- in: query >- required: false >- type: boolean >- description: Only include jobs started in the last hour > - $ref: "../swagger.yaml#/parameters/match" > - $ref: "../swagger.yaml#/parameters/order_by" > - $ref: "../swagger.yaml#/parameters/page" >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >index b4d7f13b9ac..fb92ebd0e1e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt >@@ -259,21 +259,29 @@ > $("#job_details").show(); > [% END %] > >- let query_filters = function(){ >- if ( $("#only_current").is(":checked") && !$("#include_last_hour").is(":checked") ) { >- return 'only_current=1&only_last_hour=0'; >- } else if ( $("#include_last_hour").is(":checked") && !$("#only_current").is(":checked")) { >- return 'only_current=0&only_last_hour=1'; >- } else if ( $("#only_current").is(":checked") && $("#include_last_hour").is(":checked") ) { >- return 'only_current=1&only_last_hour=1'; >+ let additional_filters = { >+ enqueued_on: function(){ >+ let now = new Date(); >+ if ( $("#include_last_hour").is(":checked") ) { >+ now.setHours(now.getHours() - 1); >+ return { ">": now.toISOString() }; >+ } else { >+ return { "<": now.toISOString() }; >+ } >+ } >+ }; >+ >+ let only_current_filter = function(){ >+ if ( $("#only_current").is(":checked") ) { >+ return 'only_current=1'; > } else { >- return 'only_current=0&only_last_hour=0'; >+ return 'only_current=0'; > } > } > > let jobs_table = $("#table_jobs").kohaTable({ > "ajax": { >- "url": "/api/v1/jobs?" + query_filters(), >+ "url": "/api/v1/jobs?" + only_current_filter() > }, > "order": [[ 1, "desc" ]], > "columns": [ >@@ -342,10 +350,15 @@ > "orderable": false > } > ] >- }, null, 1); >+ }, null, 1, additional_filters); >+ >+ $("#include_last_hour").on("change", function(){ >+ jobs_table.DataTable().draw(); >+ return false; >+ }); > >- $("#only_current, #include_last_hour").on("change", function(){ >- jobs_table.DataTable().ajax.url("/api/v1/jobs?" + query_filters()).load(); >+ $("#only_current").on("change", function(){ >+ jobs_table.DataTable().ajax.url("/api/v1/jobs?" + only_current_filter()).load(); > return false; > }); > }); >diff --git a/t/db_dependent/Koha/BackgroundJobs.t b/t/db_dependent/Koha/BackgroundJobs.t >index 58b34d544d7..c8089d4488b 100755 >--- a/t/db_dependent/Koha/BackgroundJobs.t >+++ b/t/db_dependent/Koha/BackgroundJobs.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 16; >+use Test::More tests => 14; > use Test::MockModule; > > use List::MoreUtils qw(any); >@@ -123,64 +123,6 @@ subtest 'filter_by_current() tests' => sub { > $schema->storage->txn_rollback; > }; > >-subtest 'filter_by_last_hour() tests' => sub { >- >- plan tests => 2; >- >- $schema->storage->txn_begin; >- >- my $job_now = >- $builder->build_object( { class => 'Koha::BackgroundJobs', value => { enqueued_on => dt_from_string } } ); >- my $job_old = $builder->build_object( >- { class => 'Koha::BackgroundJobs', value => { enqueued_on => dt_from_string->subtract( hours => 2 ) } } ); >- my $rs = Koha::BackgroundJobs->search( { id => [ $job_now->id, $job_old->id ] } ); >- >- is( $rs->count, 2, '2 jobs in resultset' ); >- >- $rs = $rs->filter_by_last_hour; >- >- is( $rs->count, 1, 'Only 1 job in filtered resultset' ); >- >- $schema->storage->txn_rollback; >-}; >- >-subtest 'filter_by_last_hour() and filter_by_current() tests' => sub { >- >- plan tests => 3; >- >- $schema->storage->txn_begin; >- >- my $job_new_now = $builder->build_object( >- { class => 'Koha::BackgroundJobs', value => { status => 'new', enqueued_on => dt_from_string } } ); >- my $job_new_old = $builder->build_object( >- { >- class => 'Koha::BackgroundJobs', >- value => { status => 'new', enqueued_on => dt_from_string->subtract( hours => 2 ) } >- } >- ); >- my $job_cancelled = $builder->build_object( >- { class => 'Koha::BackgroundJobs', value => { status => 'cancelled', enqueued_on => dt_from_string } } ); >- my $job_failed = $builder->build_object( >- { class => 'Koha::BackgroundJobs', value => { status => 'failed', enqueued_on => dt_from_string } } ); >- my $job_finished = $builder->build_object( >- { class => 'Koha::BackgroundJobs', value => { status => 'finished', enqueued_on => dt_from_string } } ); >- >- my $rs = Koha::BackgroundJobs->search( >- { id => [ $job_new_now->id, $job_new_old->id, $job_cancelled->id, $job_failed->id, $job_finished->id ] } ); >- >- is( $rs->count, 5, '5 jobs in resultset' ); >- >- $rs = $rs->filter_by_last_hour; >- >- is( $rs->count, 4, '4 jobs in last hour' ); >- >- $rs = $rs->filter_by_current; >- >- is( $rs->count, 1, 'Only 1 current job in last hour' ); >- >- $schema->storage->txn_rollback; >-}; >- > subtest 'search_limited' => sub { > plan tests => 3; > >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37905
:
171386
|
171387
|
171388
|
171404
|
171405
|
171759
|
171760
|
171761
|
172902
|
172903
|
172904