Skip to content

Commit 0046098

Browse files
authored
Merge pull request #47 from 21TORR/task-log-model-filter
Add option to hide internal tasks in task log model
2 parents 0f45dfa + 2bab547 commit 0046098

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
3.1.0
2+
=====
3+
4+
* (feature) Add option to hide internal tasks in task log model.
5+
6+
17
3.0.0
28
=====
39

src/Model/TaskLogModel.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
use Psr\Log\LoggerInterface;
1010
use Torr\TaskManager\Entity\TaskLog;
1111
use Torr\TaskManager\Entity\TaskRun;
12+
use Torr\TaskManager\Task\DispatchAfterRunTask\DispatchAfterRunTask;
1213
use Torr\TaskManager\Task\Task;
1314

1415
final class TaskLogModel
1516
{
17+
public const bool SHOW_ALL_TASKS = true;
18+
public const bool HIDE_INTERNAL_TASKS = false;
19+
1620
/** @var EntityRepository<TaskLog> */
1721
private EntityRepository $repository;
1822

@@ -61,17 +65,28 @@ public function getLogForTask (Task $task) : TaskLog
6165
*
6266
* @return TaskLog[]
6367
*/
64-
public function getMostRecentEntries (int $limit = 100) : array
68+
public function getMostRecentEntries (
69+
int $limit = 100,
70+
bool $showAll = self::SHOW_ALL_TASKS,
71+
) : array
6572
{
66-
$query = $this->repository->createQueryBuilder("task")
73+
$builder = $this->repository->createQueryBuilder("task")
6774
->select("task, run")
6875
->leftJoin("task.runs", "run")
6976
->addOrderBy("task.timeQueued", "DESC")
70-
->setMaxResults($limit)
71-
->getQuery();
77+
->setMaxResults($limit);
78+
79+
if (self::HIDE_INTERNAL_TASKS === $showAll)
80+
{
81+
$builder
82+
->andWhere("task.taskClass NOT IN (:internalTasks)")
83+
->setParameter("internalTasks", [
84+
DispatchAfterRunTask::class,
85+
]);
86+
}
7287

7388
/** @var TaskLog[] */
74-
return (new Paginator($query))
89+
return (new Paginator($builder->getQuery()))
7590
->getQuery()
7691
->getResult();
7792
}

0 commit comments

Comments
 (0)