# 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
+=head2 Class methods
-=cut
-
-=head2 search_limited
+=head3 search_limited
my $background_jobs = Koha::BackgroundJobs->search_limited( $params, $attributes );
sub search_limited {
my ( $self, $params, $attributes ) = @_;
- # Assume permission if context has no user
- my $can_manage_background_jobs = 1;
-
+ my $can_manage_background_jobs;
my $logged_in_user;
my $userenv = C4::Context->userenv;
if ( $userenv and $userenv->{number} ) {
{ parameters => 'manage_background_jobs' } );
}
- return $can_manage_background_jobs
- ? $self->search( $params, $attributes )
- : $self->search( { borrowernumber => $logged_in_user->borrowernumber } )
- ->search( $params, $attributes );
+ return $self->search( $params, $attributes ) if $can_manage_background_jobs;
+ my $id = $logged_in_user ? $logged_in_user->borrowernumber : undef;
+ return $self->search({ borrowernumber => $id })->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