diff --git a/ProcessMaker/Http/Controllers/Api/TaskController.php b/ProcessMaker/Http/Controllers/Api/TaskController.php index 27ed5a81d0..e9ea13f025 100644 --- a/ProcessMaker/Http/Controllers/Api/TaskController.php +++ b/ProcessMaker/Http/Controllers/Api/TaskController.php @@ -130,6 +130,12 @@ public function index(Request $request, $getTotal = false, User $user = null) // Apply filter overdue $query->overdue($request->input('overdue')); + // If we should manually add pagination to the + // query in advance (also used by saved search) + if ($this->isPaginationEnabled()) { + $query->paginate($request->input('per_page', 10)); + } + try { $response = $query->get(); } catch (QueryException $e) { @@ -263,15 +269,15 @@ private function handleQueryException($e) { $regex = '~Column not found: 1054 Unknown column \'(.*?)\' in \'where clause\'~'; preg_match($regex, $e->getMessage(), $m); - + $message = __('PMQL Is Invalid.'); - + if (count($m) > 1) { $message .= ' ' . __('Column not found: ') . '"' . $m[1] . '"'; } - + \Log::error($e->getMessage()); - + return response([ 'message' => $message, ], 422); diff --git a/ProcessMaker/Traits/TaskControllerIndexMethods.php b/ProcessMaker/Traits/TaskControllerIndexMethods.php index 81990fd4a9..5196dd2836 100644 --- a/ProcessMaker/Traits/TaskControllerIndexMethods.php +++ b/ProcessMaker/Traits/TaskControllerIndexMethods.php @@ -15,6 +15,36 @@ trait TaskControllerIndexMethods { + /** + * Manually enable paginated results from the + * index method() + * + * @return void + */ + public function enableIndexPagination(): void + { + static::$paginate = true; + } + + /** + * Determine if pagination was manually set for the + * index() method results + * + * @return bool + */ + public function isPaginationEnabled(): bool + { + return static::$paginate === true; + } + + /** + * Used by saved search to paginate the results + * from the index() method + * + * @var bool + */ + protected static bool $paginate = false; + private function indexBaseQuery($request) { $query = ProcessRequestToken::with(['processRequest', 'user', 'draft']);