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

(-)a/Koha/BackgroundJob.pm (-4 / +21 lines)
Lines 96-107 Return the job_id of the newly created job. Link Here
96
sub enqueue {
96
sub enqueue {
97
    my ( $self, $params ) = @_;
97
    my ( $self, $params ) = @_;
98
98
99
    my $job_type = $self->job_type;
99
    my $job_type    = $self->job_type;
100
    my $job_size = $params->{job_size};
100
    my $job_size    = $params->{job_size};
101
    my $job_args = $params->{job_args};
101
    my $job_args    = $params->{job_args};
102
    my $job_queue = $params->{job_queue} // 'default';
102
    my $job_context = $params->{job_context} // C4::Context->userenv;
103
    my $job_queue   = $params->{job_queue}  // 'default';
103
104
104
    my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef;
105
    my $borrowernumber = (C4::Context->userenv) ? C4::Context->userenv->{number} : undef;
106
    $job_context->{interface} = C4::Context->interface;
107
    my $json_context = encode_json $job_context;
105
    my $json_args = encode_json $job_args;
108
    my $json_args = encode_json $job_args;
106
109
107
    $self->set(
110
    $self->set(
Lines 111-116 sub enqueue { Link Here
111
            queue          => $job_queue,
114
            queue          => $job_queue,
112
            size           => $job_size,
115
            size           => $job_size,
113
            data           => $json_args,
116
            data           => $json_args,
117
            context        => $json_context,
114
            enqueued_on    => dt_from_string,
118
            enqueued_on    => dt_from_string,
115
            borrowernumber => $borrowernumber,
119
            borrowernumber => $borrowernumber,
116
        }
120
        }
Lines 162-167 sub process { Link Here
162
166
163
    $args ||= {};
167
    $args ||= {};
164
168
169
    my $context = decode_json($self->context);
170
    C4::Context->_new_userenv(-1);
171
    C4::Context->interface( $context->{interface} );
172
    C4::Context->set_userenv(
173
        $context->{number},       $context->{id},
174
        $context->{cardnumber},   $context->{firstname},
175
        $context->{surname},      $context->{branch},
176
        $context->{branchname},   $context->{flags},
177
        $context->{emailaddress}, undef,
178
        $context->{desk_id},      $context->{desk_name},
179
        $context->{register_id},  $context->{register_name}
180
    );
181
165
    return $derived_class->process( $args );
182
    return $derived_class->process( $args );
166
}
183
}
167
184
(-)a/misc/background_jobs_worker.pl (-16 / +1 lines)
Lines 121-141 sub process_job { Link Here
121
121
122
    die "fork failed!" unless defined $pid;
122
    die "fork failed!" unless defined $pid;
123
123
124
    my $patron = Koha::Patrons->find($job->borrowernumber);
124
    $job->process( $args );
125
    if ( $patron ) {
126
        C4::Context->_new_userenv(-1);
127
        C4::Context->interface('intranet');
128
        C4::Context->set_userenv(
129
            $patron->borrowernumber,      $patron->userid,
130
            $patron->cardnumber,          $patron->firstname,
131
            $patron->surname,            $patron->branchcode,
132
            $patron->library->branchname, $patron->flags
133
        );
134
        $job->process( $args );
135
        C4::Context->_unset_userenv(-1);
136
    } ese {
137
        $job->process( $args );
138
    }
139
125
140
    exit;
126
    exit;
141
}
127
}
142
- 

Return to bug 30889