src/Helper/BDDHelper.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Helper;
  3. use App\Entity\TMA\TMALog;
  4. use App\Entity\TMA\WPError;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. class BDDHelper
  7. {
  8.     public $entityManager;
  9.     public function __construct(EntityManagerInterface $entityManager = null)
  10.     {
  11.         $this->entityManager = $entityManager;
  12.     }
  13.     /**
  14.      * @param $url
  15.      * @param $duration
  16.      * @param $info
  17.      * @return void
  18.      */
  19.     public function addTMALog($url, $duration, $info, $status = 0)
  20.     {
  21.         $tmaLog = new TMALog();
  22.         $tmaLog->setLogDate(new \DateTime());
  23.         $tmaLog->setUrl($url);
  24.         $tmaLog->setInfo($info);
  25.         $tmaLog->setStatus($status);
  26.         $tmaLog->setDuration($duration);
  27.         $this->entityManager->persist($tmaLog);
  28.         $this->entityManager->flush();
  29.     }
  30.     public function addTMAWpErrorLog($url, $error, $type, $filename, $fileline, $status = 0)
  31.     {
  32.         $errorLog = $this->entityManager->getRepository(WPError::class)->findOneBy(['error' => $error, 'url' => $url]);
  33.         $now = new \DateTime();
  34.         $dateHisto = '';
  35.         if($errorLog) {
  36.             $count = (int) $errorLog->getCountError();
  37.             $errorLog->setCountError($count + 1);
  38.             $errorLog->setStatus(WPError::STATUS_TODO);
  39.             $errorLog->setLogDate($now);
  40.             $dateHisto = $errorLog->getDateHisto().'#';
  41.         } else {
  42.             $errorLog = new WPError();
  43.             $errorLog->setLogDate($now);
  44.             $errorLog->setCountError(1);
  45.             $errorLog->setUrl($url);
  46.             $errorLog->setError($error);
  47.             $errorLog->setLineerror($filename.' : '.$fileline);
  48.             $errorLog->setType($type);
  49.             $errorLog->setStatus($status);
  50.         }
  51.         $dateHisto .= $now->format('d/m/Y H:i:s');
  52.         $errorLog->setDateHisto($dateHisto);
  53.         $this->entityManager->persist($errorLog);
  54.         $this->entityManager->flush();
  55.     }
  56. }