2021-05-27 11:46:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace JeroenED\Webcron\Repository;
|
|
|
|
|
|
|
|
|
|
|
|
use JeroenED\Framework\Repository;
|
|
|
|
|
|
|
|
class Run extends Repository
|
|
|
|
{
|
|
|
|
public function getRunsForJob(int $id, $excludedexitcodes = [], $ordered = true): array
|
|
|
|
{
|
|
|
|
$runsSql = "SELECT * FROM run WHERE job_id = :job";
|
|
|
|
$params = [':job' => $id];
|
|
|
|
if (!empty($excludedexitcodes)) {
|
2021-05-28 15:00:24 +02:00
|
|
|
$runsSql .= ' AND exitcode NOT in ';
|
|
|
|
$exitcodes = [];
|
2021-05-27 11:46:30 +02:00
|
|
|
foreach($excludedexitcodes as $key => $exitcode) {
|
2021-05-28 15:00:24 +02:00
|
|
|
$exitcodes[] = ':code' . $key;
|
2021-05-27 11:46:30 +02:00
|
|
|
$params[':code' . $key] = $exitcode;
|
|
|
|
}
|
2021-05-28 15:00:24 +02:00
|
|
|
$runsSql .= '(' . implode(',', $exitcodes) . ')';
|
2021-05-27 11:46:30 +02:00
|
|
|
}
|
|
|
|
if ($ordered) $runsSql .= ' ORDER by timestamp DESC';
|
|
|
|
$runsStmt = $this->dbcon->prepare($runsSql);
|
|
|
|
$runsRslt = $runsStmt->executeQuery($params);
|
|
|
|
$runs = $runsRslt->fetchAllAssociative();
|
|
|
|
return $runs;
|
|
|
|
}
|
|
|
|
}
|