PartKeepr\CronLoggerBundle\Services\CronLoggerService::markCronRun PHP Method

markCronRun() public method

Marks a specific cronjob as ran.
public markCronRun ( string $cronjob ) : CronLogger
$cronjob string The name of the cronjob
return PartKeepr\CronLoggerBundle\Entity\CronLogger The cron logger entity
    public function markCronRun($cronjob)
    {
        $dql = "SELECT c FROM PartKeepr\\CronLoggerBundle\\Entity\\CronLogger c WHERE c.cronjob = :cronjob";
        $query = $this->entityManager->createQuery($dql);
        $query->setParameter('cronjob', $cronjob);
        try {
            $result = $query->getSingleResult();
        } catch (\Exception $e) {
            $result = new CronLogger();
            $result->setCronjob($cronjob);
            $this->entityManager->persist($result);
        }
        $result->setLastRunDate(new \DateTime());
        $this->entityManager->flush();
        return $result;
    }