Bugzilla – Attachment 140595 Details for
Bug 30982
Use the REST API for background job list view
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30982: Add Koha::BackgroundJobs->filter_by_current
Bug-30982-Add-KohaBackgroundJobs-filterbycurrent.patch (text/plain), 3.46 KB, created by
Martin Renvoize (ashimema)
on 2022-09-13 14:57:24 UTC
(
hide
)
Description:
Bug 30982: Add Koha::BackgroundJobs->filter_by_current
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-09-13 14:57:24 UTC
Size:
3.46 KB
patch
obsolete
>From 503e41c4d80800fc87dc6acbe316cba1e37831ce Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 12 Sep 2022 12:01:45 -0300 >Subject: [PATCH] Bug 30982: Add Koha::BackgroundJobs->filter_by_current > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/BackgroundJobs.pm | 28 ++++++++++++++++++---- > t/db_dependent/Koha/BackgroundJobs.t | 35 ++++++++++++++++++++++++++-- > 2 files changed, 57 insertions(+), 6 deletions(-) > >diff --git a/Koha/BackgroundJobs.pm b/Koha/BackgroundJobs.pm >index 194123020d..dc88bc8c37 100644 >--- a/Koha/BackgroundJobs.pm >+++ b/Koha/BackgroundJobs.pm >@@ -16,18 +16,18 @@ package Koha::BackgroundJobs; > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use base qw(Koha::Objects); >+ > use Koha::BackgroundJob; > >+use base qw(Koha::Objects); >+ > =head1 NAME > > Koha::BackgroundJobs - Koha BackgroundJob Object set class > > =head1 API > >-=head2 Class Methods >- >-=cut >+=head2 Class methods > > =head2 search_limited > >@@ -57,6 +57,26 @@ sub search_limited { > ->search( $params, $attributes ); > } > >+=head3 filter_by_current >+ >+ my $current_jobs = $jobs->filter_by_current; >+ >+Returns a new resultset, filtering out finished jobs. >+ >+=cut >+ >+sub filter_by_current { >+ my ($self) = @_; >+ >+ return $self->search( >+ { >+ status => { not_in => [ 'cancelled', 'failed', 'finished' ] } >+ } >+ ); >+} >+ >+=head2 Internal methods >+ > =head3 _type > > =cut >diff --git a/t/db_dependent/Koha/BackgroundJobs.t b/t/db_dependent/Koha/BackgroundJobs.t >index 0f5bede989..5d1dc1c58a 100755 >--- a/t/db_dependent/Koha/BackgroundJobs.t >+++ b/t/db_dependent/Koha/BackgroundJobs.t >@@ -19,9 +19,11 @@ > > use Modern::Perl; > >-use Test::More tests => 12; >+use Test::More tests => 13; > use Test::MockModule; > >+use List::MoreUtils qw(any); >+ > use Koha::Database; > use Koha::BackgroundJobs; > use Koha::DateUtils qw( dt_from_string ); >@@ -31,7 +33,8 @@ use t::lib::Mocks; > use t::lib::Dates; > use t::lib::Koha::BackgroundJob::BatchTest; > >-my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+my $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; > > t::lib::Mocks::mock_userenv; >@@ -91,3 +94,31 @@ is_deeply( > is_deeply( $new_job->additional_report(), {} ); > > $schema->storage->txn_rollback; >+ >+subtest 'filter_by_current() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $job_new = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'new' } } ); >+ my $job_cancelled = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'cancelled' } } ); >+ my $job_failed = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'failed' } } ); >+ my $job_finished = $builder->build_object( { class => 'Koha::BackgroundJobs', value => { status => 'finished' } } ); >+ >+ my $rs = Koha::BackgroundJobs->search( >+ { >+ id => [ $job_new->id, $job_cancelled->id, $job_failed->id, $job_finished->id ] >+ } >+ ); >+ >+ is( $rs->count, 4, '4 jobs in resultset' ); >+ ok( any {$_->status eq 'new'} @{$rs->as_list}, "There is a 'new' job" ); >+ >+ $rs = $rs->filter_by_current; >+ >+ is( $rs->count, 1, 'Only 1 job in filtered resultset' ); >+ is( $rs->next->status, 'new', "The only job in resultset is 'new'" ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.20.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 30982
:
136245
|
136246
|
136670
|
136671
|
136672
|
136707
|
136708
|
136715
|
138114
|
139636
|
139637
|
139638
|
139639
|
139640
|
139641
|
140488
|
140489
|
140490
|
140491
|
140492
|
140493
|
140494
|
140495
|
140496
|
140497
|
140498
|
140589
|
140590
|
140591
|
140592
|
140593
|
140594
|
140595
|
140596
|
140597
|
140598
|
140599
|
140789
|
140884
|
140885
|
140886
|
140887
|
140888
|
140889
|
140890
|
140891
|
140892
|
140893
|
140894
|
140895
|
140896
|
140897
|
142859