webcron/src/Repository/Run.php

30 lines
926 B
PHP
Raw Normal View History

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)) {
$runsSql .= ' AND exitcode NOT in ';
$exitcodes = [];
2021-05-27 11:46:30 +02:00
foreach($excludedexitcodes as $key => $exitcode) {
$exitcodes[] = ':code' . $key;
2021-05-27 11:46:30 +02:00
$params[':code' . $key] = $exitcode;
}
$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;
}
}