Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ProcessMaker/Http/Controllers/Api/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions ProcessMaker/Traits/TaskControllerIndexMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down