Scope economic transfer queue jobs by creator
This commit is contained in:
@@ -752,13 +752,14 @@ class orderInvoicesRoute
|
||||
['limit' => $limit, 'offset' => $offset] = $this->parseCollectedInvoiceQueuePagination();
|
||||
|
||||
$queue = new economic_transfer_queue();
|
||||
$jobs = $queue->listJobs(
|
||||
$jobs = $queue->listJobsForCreatedBy(
|
||||
$statuses,
|
||||
$limit,
|
||||
$offset,
|
||||
economic_transfer_queue::TYPE_COLLECTED_INVOICE_EXPORT
|
||||
economic_transfer_queue::TYPE_COLLECTED_INVOICE_EXPORT,
|
||||
(int)$user->id
|
||||
);
|
||||
$total_jobs = $this->countCollectedInvoiceQueueJobs($queue, $statuses);
|
||||
$total_jobs = $this->countCollectedInvoiceQueueJobs($queue, $statuses, (int)$user->id);
|
||||
$has_more = ($offset + count($jobs)) < $total_jobs;
|
||||
|
||||
$response->success([
|
||||
@@ -785,7 +786,7 @@ class orderInvoicesRoute
|
||||
$this->ensureEconomicTransferQueueIsAvailable();
|
||||
|
||||
$job_id = $this->requireCollectedInvoiceQueueJobId();
|
||||
$job = $this->requireCollectedInvoiceQueueJobById($job_id);
|
||||
$job = $this->requireCollectedInvoiceQueueJobById($job_id, (int)$user->id);
|
||||
|
||||
$response->success($this->withCollectedInvoiceQueueDetailsSummary($job));
|
||||
},
|
||||
@@ -827,14 +828,14 @@ class orderInvoicesRoute
|
||||
$this->ensureEconomicTransferQueueIsAvailable();
|
||||
|
||||
$job_id = $this->requireCollectedInvoiceQueueJobId();
|
||||
$job = $this->requireCollectedInvoiceQueueJobById($job_id, true);
|
||||
$job = $this->requireCollectedInvoiceQueueJobById($job_id, (int)$user->id, true);
|
||||
if ((int)($job['attempts'] ?? 0) >= (int)($job['max_attempts'] ?? 1)) {
|
||||
$response->error('Collected invoice queue job reached max retry attempts', 409);
|
||||
}
|
||||
|
||||
try {
|
||||
$queue = new economic_transfer_queue();
|
||||
$retried = $queue->retryJob($job_id);
|
||||
$retried = $queue->retryJobForUser($job_id, (int)$user->id);
|
||||
} catch (\Throwable $e) {
|
||||
$message = trim((string)$e->getMessage());
|
||||
$status_code = $this->resolveCollectedInvoiceQueueRetryErrorStatus($message);
|
||||
@@ -861,7 +862,7 @@ class orderInvoicesRoute
|
||||
$this->ensureEconomicTransferQueueIsAvailable();
|
||||
|
||||
$job_id = $this->requireCollectedInvoiceQueueJobId();
|
||||
$job = $this->requireCollectedInvoiceQueueJobById($job_id);
|
||||
$job = $this->requireCollectedInvoiceQueueJobById($job_id, (int)$user->id);
|
||||
$status = strtoupper((string)($job['status'] ?? ''));
|
||||
if (!in_array($status, [
|
||||
economic_transfer_queue::STATUS_COMPLETED,
|
||||
@@ -2153,12 +2154,12 @@ class orderInvoicesRoute
|
||||
return (int)$job_id;
|
||||
}
|
||||
|
||||
private function requireCollectedInvoiceQueueJobById(int $job_id, bool $mustBeFailed = false): array
|
||||
private function requireCollectedInvoiceQueueJobById(int $job_id, int $created_by, bool $mustBeFailed = false): array
|
||||
{
|
||||
global $response;
|
||||
|
||||
$queue = new economic_transfer_queue();
|
||||
$job = $queue->getJobById($job_id);
|
||||
$job = $queue->getJobByIdForUser($job_id, $created_by);
|
||||
if ($job === null || ($job['transfer_type'] ?? null) !== economic_transfer_queue::TYPE_COLLECTED_INVOICE_EXPORT) {
|
||||
$response->error('Collected invoice queue job not found', 404);
|
||||
}
|
||||
@@ -2263,19 +2264,26 @@ class orderInvoicesRoute
|
||||
];
|
||||
}
|
||||
|
||||
private function countCollectedInvoiceQueueJobs(economic_transfer_queue $queue, array $statuses): int
|
||||
private function countCollectedInvoiceQueueJobs(economic_transfer_queue $queue, array $statuses, int $created_by): int
|
||||
{
|
||||
global $db;
|
||||
|
||||
if (method_exists($queue, 'countJobs')) {
|
||||
return max(0, (int)$queue->countJobs(
|
||||
$created_by = max(0, $created_by);
|
||||
if ($created_by < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (method_exists($queue, 'countJobsForCreatedBy')) {
|
||||
return max(0, (int)$queue->countJobsForCreatedBy(
|
||||
$statuses,
|
||||
economic_transfer_queue::TYPE_COLLECTED_INVOICE_EXPORT
|
||||
economic_transfer_queue::TYPE_COLLECTED_INVOICE_EXPORT,
|
||||
$created_by
|
||||
));
|
||||
}
|
||||
|
||||
$conditions = [
|
||||
"transfer_type = '" . $db->escape_string(economic_transfer_queue::TYPE_COLLECTED_INVOICE_EXPORT) . "'",
|
||||
'created_by = ' . $created_by,
|
||||
];
|
||||
|
||||
if ($statuses !== []) {
|
||||
|
||||
Reference in New Issue
Block a user