BUGFIX: sometimes I was still using IDs
This commit is contained in:
parent
47c698faf4
commit
d0974325f5
|
@ -21,27 +21,30 @@ class JobController extends AbstractController
|
|||
return $this->render('job/index.html.twig', ['jobs' => $jobs]);
|
||||
}
|
||||
|
||||
public function jobAction(Request $request, ManagerRegistry $doctrine, $id, $all = false): Response
|
||||
public function jobAction(Request $request, ManagerRegistry $doctrine, int $id, mixed $all = false): Response
|
||||
{
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
$runRepo = $doctrine->getRepository(Run::class);
|
||||
|
||||
if($request->getMethod() == 'GET') {
|
||||
$job = $jobRepo->parseJob($id);
|
||||
$runs = $runRepo->getRunsForJob($id, $all != 'all');
|
||||
$job = $jobRepo->find($id);
|
||||
$jobRepo->parseJob($job);
|
||||
$runs = $runRepo->getRunsForJob($job, $all != 'all');
|
||||
return $this->render('job/view.html.twig', ['job' => $job, 'runs' => $runs, 'allruns' => $all == 'all']);
|
||||
} elseif($request->getMethod() == 'DELETE') {
|
||||
$success = $jobRepo->deleteJob($id);
|
||||
$this->addFlash('success', $success['message']);
|
||||
return new JsonResponse(['return_path' => $this->GenerateUrl('job_index')]);
|
||||
}
|
||||
return new JsonResponse(['success'=>false, 'message' => 'Your request is invalid'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
public function editAction(Request $request, ManagerRegistry $doctrine, $id)
|
||||
public function editAction(Request $request, ManagerRegistry $doctrine, int $id): Response
|
||||
{
|
||||
if($request->getMethod() == 'GET') {
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
$job = $jobRepo->parseJob($id, true);
|
||||
$job = $jobRepo->find($id);
|
||||
$jobRepo->parseJob($job, true);
|
||||
return $this->render('job/edit.html.twig', ['job' => $job]);
|
||||
} elseif($request->getMethod() == 'POST') {
|
||||
$allValues = $request->request->all();
|
||||
|
@ -56,9 +59,10 @@ class JobController extends AbstractController
|
|||
$this->addFlash('success', $joboutput['message']);
|
||||
return new RedirectResponse($this->GenerateUrl('job_index'));
|
||||
}
|
||||
return new JsonResponse(['success'=>false, 'message' => 'Your request is invalid'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
public function addAction(Request $request, ManagerRegistry $doctrine)
|
||||
public function addAction(Request $request, ManagerRegistry $doctrine): Response
|
||||
{
|
||||
if($request->getMethod() == 'GET') {
|
||||
return $this->render('job/add.html.twig', ['data' => []]);
|
||||
|
@ -78,11 +82,13 @@ class JobController extends AbstractController
|
|||
}
|
||||
}
|
||||
|
||||
public function runNowAction(Request $request, ManagerRegistry $doctrine, int $id) {
|
||||
public function runNowAction(Request $request, ManagerRegistry $doctrine, int $id): JsonResponse
|
||||
{
|
||||
if($request->getMethod() == 'GET') {
|
||||
$jobRepo = $doctrine->getRepository(Job::class);
|
||||
$job = $jobRepo->find($id);
|
||||
return new JsonResponse($jobRepo->runNow($job));
|
||||
}
|
||||
return new JsonResponse(['success'=>false, 'message' => 'Your request is invalid'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
}
|
|
@ -154,13 +154,13 @@ class Job
|
|||
{
|
||||
$names = is_array($name) ? $name : explode('.', $name);
|
||||
$current = $names[0];
|
||||
if(is_array($data[$current]) && isset($names[1])) {
|
||||
if(!isset($data[$current])) {
|
||||
return false;
|
||||
} elseif(is_array($data[$current]) && isset($names[1])) {
|
||||
unset($names[0]);
|
||||
$this->removeDataItem($data[$current], array_values($names));
|
||||
} elseif(!isset($data[$current])) {
|
||||
return false;
|
||||
} else {
|
||||
unset($data[$names[0]]);
|
||||
if(isset($data[$names[0]])) unset($data[$names[0]]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -78,18 +78,18 @@ class Run
|
|||
}
|
||||
|
||||
/**
|
||||
* @return CollectionAlias
|
||||
* @return Job
|
||||
*/
|
||||
public function getJob(): CollectionAlias
|
||||
public function getJob(): Job
|
||||
{
|
||||
return $this->job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionAlias $job
|
||||
* @param Job $job
|
||||
* @return Run
|
||||
*/
|
||||
public function setJob(CollectionAlias $job): Run
|
||||
public function setJob(Job $job): Run
|
||||
{
|
||||
$this->job = $job;
|
||||
return $this;
|
||||
|
|
|
@ -88,9 +88,9 @@ class JobRepository extends EntityRepository
|
|||
$job->setData('service', $jobData['service'] ?? '');
|
||||
$job->setData('norun', $job->getLastrun() !== null && $job->getNextrun() > $job->getLastrun());
|
||||
$job->setData('running', $job->getRunning() != 0);
|
||||
$failedruns = $runRepo->getRunsForJob($job->getId(), true, $jobData['fail-days']);
|
||||
$failedruns = $runRepo->getRunsForJob($job, true, $jobData['fail-days']);
|
||||
$failed = count($failedruns);
|
||||
$all = count($runRepo->getRunsForJob($job->getId(), false, $jobData['fail-days']));
|
||||
$all = count($runRepo->getRunsForJob($job, false, $jobData['fail-days']));
|
||||
$job->setData('lastfail', $failedruns[0] ?? NULL);
|
||||
$job->setData('needschecking', $all > 0 && (($failed / $all) * 100) > $jobData['fail-pct']);
|
||||
if(!empty($jobData['containertype']) && $jobData['containertype'] != 'none') {
|
||||
|
@ -457,7 +457,7 @@ class JobRepository extends EntityRepository
|
|||
// saving to database
|
||||
$em->getConnection()->close();
|
||||
$runRepo = $em->getRepository(Run::class);
|
||||
$runRepo->addRun($job->getId(), $result['exitcode'], floor($starttime), $runtime, $result['output'], $flags);
|
||||
$runRepo->addRun($job, $result['exitcode'], floor($starttime), $runtime, $result['output'], $flags);
|
||||
if (!$manual){
|
||||
// setting nextrun to next run
|
||||
$nextrun = $job->getNextrun();
|
||||
|
|
|
@ -15,10 +15,9 @@ class RunRepository extends EntityRepository
|
|||
const SUCCESS = 'S';
|
||||
const MANUAL = 'M';
|
||||
|
||||
public function getRunsForJob(int $id, bool $onlyfailed = false, int $maxage = NULL, bool $ordered = true): array
|
||||
public function getRunsForJob(Job $job, bool $onlyfailed = false, int $maxage = NULL, bool $ordered = true): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('run');
|
||||
$job = $this->getEntityManager()->getRepository(Job::class)->find($id);
|
||||
$runs = $qb
|
||||
->where('run.job = :job')
|
||||
->setParameter(':job', $job);
|
||||
|
@ -90,7 +89,7 @@ class RunRepository extends EntityRepository
|
|||
}
|
||||
} else {
|
||||
foreach($jobids as $jobid) {
|
||||
$job = $em->find($jobid);
|
||||
$job = $jobRepo->find($jobid);
|
||||
$jobRepo->parseJob($job);
|
||||
$allJobs[] = $job;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue