src/Controller/BaseSite/Cronjobs/ShopWatcherCronjobsController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller\BaseSite\Cronjobs;
  3. use App\Entity\Shop\Log\TrafficLog;
  4. use App\Repository\BaseSite\DomainRepository;
  5. use App\Repository\Shop\Log\TrafficLogRepository;
  6. use App\Repository\Shop\Shop\ShopRepository;
  7. use App\Service\Util\ArvanCDN;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class ShopWatcherCronjobsController extends AbstractController
  13. {
  14.     #[Route('/base-site/cronjobs/shop-watcher/activity'name'app_base_site_cronjobs_shop_watcher_activity')]
  15.     public function app_base_site_cronjobs_shop_watcher_activity(ShopRepository $shopRepositoryEntityManagerInterface $entityManagerTrafficLogRepository $trafficLogRepository): JsonResponse
  16.     {
  17.         foreach ($shopRepository->findAll() as $shopObject) {
  18.             if (!$shopObject->isActive()) {
  19.                 $shopObject->setActive(0);
  20.             }
  21.             if ($shopObject->getExpiredAt() < new \DateTime('now')) {
  22.                 $shopObject->setActive(0);
  23.             }
  24.         }
  25.         $entityManager->flush();
  26.         return  $this->json(['res' => true]);
  27.     }
  28. }