src/Controller/CronJobsController.php line 227

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\ActionLoggerService;
  4. use App\Services\AlertService;
  5. use App\Services\BetterService;
  6. use App\Services\BookingCatalogService;
  7. use App\Services\EventService;
  8. use App\Services\EventSynchroniserService;
  9. use App\Services\GeographicService;
  10. use App\Services\NewslettersService;
  11. use App\Services\NotificationAlertService;
  12. use App\Services\OssService;
  13. use App\Services\SplunkService;
  14. use App\Services\WorldlinkService;
  15. use DateTime;
  16. use Exception;
  17. use FOS\RestBundle\Controller\Annotations\Get;
  18. use Psr\Cache\CacheItemPoolInterface;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Component\HttpFoundation\RedirectResponse;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. class CronJobsController extends AbstractController
  26. {
  27.     /** @var AlertService $alertService */
  28.     protected $alertService;
  29.     /** @var EventSynchroniserService $eventSynchroniserService */
  30.     protected $eventSynchroniserService;
  31.     /** @var OssService $ossService */
  32.     protected $ossService;
  33.     /** @var GeographicService $geographicService */
  34.     protected $geographicService;
  35.     /** @var CacheItemPoolInterface $cache */
  36.     protected $cache;
  37.     /** @var EventService $eventService */
  38.     protected $eventService;
  39.     /** @var WorldlinkService $worldlinkService */
  40.     protected $worldlinkService;
  41.     /** @var SplunkService $splunkService */
  42.     protected $splunkService;
  43.     /** @var BetterService $betterService */
  44.     protected $betterService;
  45.     /** @var NewslettersService $newslettersService */
  46.     protected $newslettersService;
  47.     /** @var  NotificationAlertService $notificationAlertService */
  48.     private $notificationAlertService;
  49.     /** @var  ActionLoggerService $actionLoggerService */
  50.     private $actionLoggerService;
  51.     /** @var BookingCatalogService $bookingCatalogService */
  52.     private $bookingCatalogService;
  53.     /**
  54.      * CronJobsController constructor.
  55.      *
  56.      * @param AlertService $alertService
  57.      * @param NotificationAlertService $notificationAlertService
  58.      * @param ActionLoggerService $actionLoggerService
  59.      * @param EventSynchroniserService $eventSynchroniserService
  60.      * @param OssService $ossService
  61.      * @param BookingCatalogService $bookingCatalogService
  62.      * @param GeographicService $geographicService
  63.      * @param CacheItemPoolInterface $cache
  64.      * @param EventService $eventService
  65.      * @param WorldlinkService $worldlinkService
  66.      * @param SplunkService $splunkService
  67.      * @param BetterService $betterService
  68.      * @param NewslettersService $newslettersService
  69.      */
  70.     public function __construct(
  71.         AlertService $alertService,
  72.         NotificationAlertService $notificationAlertService,
  73.         ActionLoggerService $actionLoggerService,
  74.         EventSynchroniserService $eventSynchroniserService,
  75.         OssService $ossService,
  76.         BookingCatalogService $bookingCatalogService,
  77.         GeographicService $geographicService,
  78.         CacheItemPoolInterface $cache,
  79.         EventService $eventService,
  80.         WorldlinkService $worldlinkService,
  81.         SplunkService $splunkService,
  82.         BetterService $betterService,
  83.         NewslettersService $newslettersService
  84.     )
  85.     {
  86.         $this->alertService $alertService;
  87.         $this->actionLoggerService $actionLoggerService;
  88.         $this->notificationAlertService $notificationAlertService;
  89.         $this->eventSynchroniserService $eventSynchroniserService;
  90.         $this->ossService $ossService;
  91.         $this->geographicService $geographicService;
  92.         $this->bookingCatalogService $bookingCatalogService;
  93.         $this->cache $cache;
  94.         $this->eventService $eventService;
  95.         $this->worldlinkService $worldlinkService;
  96.         $this->splunkService $splunkService;
  97.         $this->betterService $betterService;
  98.         $this->newslettersService $newslettersService;
  99.     }
  100.     /**
  101.      * @Route("/cron/update_all_events", name="cron_update_events", methods={"GET"})
  102.      * @return JsonResponse
  103.      */
  104.     public function createUpdateAllEventsAction()
  105.     {
  106.         try {
  107.             $this->eventSynchroniserService->updateEvents();
  108.             //to update the cache of events
  109.             $this->bookingCatalogService->getBookableEvents(true);
  110.             $this->actionLoggerService->logAction("CRON_EVENTS_ALL_UPDATED""EVENT");
  111.             return $this->json("Events updated");
  112.         } catch (Exception $e) {
  113.             return $this->json("Error to update events: " $e->getMessage(), 500);
  114.         }
  115.     }
  116.     /**
  117.      * @Route("/cron/neos/update_event/{eventNo}", name="cron_update_event_by_no", methods={"GET"})
  118.      * @param string $eventNo
  119.      * @return JsonResponse
  120.      */
  121.     public function updateEventFromNEOSAction(string $eventNo)
  122.     {
  123.         try {
  124.             $this->eventSynchroniserService->updateFromEventNo($eventNo);
  125.             //to update the cache of events
  126.             $this->bookingCatalogService->getBookableEvents(true);
  127.             $this->actionLoggerService->logAction("CRON_EVENTS_EVENT_UPDATED_FROM_NEOS""EVENT"$eventNo);
  128.             return $this->json("Event updated: " $eventNo);
  129.         } catch (Exception $e) {
  130.             return $this->json("Error to update events: " $e->getMessage(), 500);
  131.         }
  132.     }
  133.     /**
  134.      * @Route("/cron/update_all_events_categories", name="cron_update_events_categories", methods={"GET"})
  135.      * @return JsonResponse
  136.      */
  137.     public function updateEventCategoriesAction()
  138.     {
  139.         try {
  140.             $this->eventSynchroniserService->updateEventCategories();
  141.             $this->actionLoggerService->logAction("CRON_EVENTS_CATEGORIES_UPDATED""EVENT");
  142.             return $this->json("Event categories updated");
  143.         } catch (Exception $e) {
  144.             return $this->json("Error to update events categories: " $e->getMessage(), 500);
  145.         }
  146.     }
  147.     /**
  148.      * @Route("/cron/update_all_distances", name="cron_update_distances", methods={"GET"})
  149.      * @return JsonResponse
  150.      */
  151.     public function updateLocationsDistancesAction()
  152.     {
  153.         try {
  154.             $this->geographicService->updateDistancesBetweenLocations();
  155.             $this->actionLoggerService->logAction("CRON_DISTANCES_UPDATED""OSS");
  156.             return $this->json("Distance updated");
  157.         } catch (Exception $e) {
  158.             return $this->json("Error to update distance: " $e->getMessage(), 500);
  159.         }
  160.     }
  161.     /**
  162.      * @Route("/cron/update_all_oss", name="cron_update_oss", methods={"GET"})
  163.      * @return JsonResponse
  164.      */
  165.     public function updateAllOssAction()
  166.     {
  167.         try {
  168.             $this->ossService->updateOssUni();
  169.             //to update the cache of events
  170.             $this->bookingCatalogService->getBookableOssUni(truetrue);
  171.             $this->actionLoggerService->logAction("CRON_OSS_ALL_UPDATED""OSS");
  172.             return $this->json("All OSS updated");
  173.         } catch (Exception $e) {
  174.             return $this->json("Error to update oss: " $e->getMessage(), 500);
  175.         }
  176.     }
  177.     /**
  178.      * @Route("/cron/update_booking_oss_origins", name="cron_update_booking_oss_origins", methods={"GET"})
  179.      * @return JsonResponse
  180.      */
  181.     public function updateBookingOssOriginsAction()
  182.     {
  183.         try {
  184.             //to update the cache of events
  185.             $this->bookingCatalogService->getBookableOssUni(truetrue);
  186.             $this->actionLoggerService->logAction("CRON_OSS_USED_FOR_BOOKING_UPDATED""OSS");
  187.             return $this->json("OSS used for Booking origins updated in cache");
  188.         } catch (Exception $e) {
  189.             $this->actionLoggerService->logException($e"Problem during the update of oss origins for bookings (updateBookingOssOriginsAction)");
  190.             return $this->json("Error to update oss origins for bookings: " $e->getMessage(), 500);
  191.         }
  192.     }
  193.     /**
  194.      * @Route("/cron/update_booking_event_origins", name="cron_update_booking_event_origins", methods={"GET"})
  195.      * @return JsonResponse
  196.      */
  197.     public function updateBookingEventOriginsAction()
  198.     {
  199.         try {
  200.             //to update the cache of events
  201.             $this->bookingCatalogService->getBookableEvents(true);
  202.             $this->actionLoggerService->logAction("CRON_EVENTS_USED_FOR_BOOKING_UPDATED""EVENT");
  203.             return $this->json("Events used for Booking origins updated in cache");
  204.         } catch (Exception $e) {
  205.             $this->actionLoggerService->logAction("CRON_EVENTS_USED_FOR_BOOKING_UPDATED""EVENT");
  206.             $this->actionLoggerService->logException($e"Problem during the update of events origins for bookings (updateBookingEventOriginsAction)");
  207.             return $this->json("Error to update events origins for bookings: " $e->getMessage(), 500);
  208.         }
  209.     }
  210.     /**
  211.      * @Get("/cron/process_mails_tweets_events", name="cron_process-mails-tweets-events", methods={"GET"})
  212.      * @return JsonResponse
  213.      */
  214.     public function sendMailsAndTweets()
  215.     {
  216.         //We have to use this kind of lock as to send mail we need to call entra and that could be long.
  217.         $keyCache "cronSendMailsAndTweets";
  218.         if ($this->cache->hasItem($keyCache)) {
  219.             $this->actionLoggerService->logAction("CRON_TWEETS_AND_MAILS_PROCESSED_ON_GOING_STOPPED""MAIL");
  220.             return $this->json("Tweets and mails are not updated as process is on going"500);
  221.         }
  222.         $item $this->cache->getItem($keyCache);
  223.         $item->set("ONGOING");
  224.         $this->cache->save($item);
  225.         try {
  226.             $this->notificationAlertService->sendMailAndTweetForFollowers();
  227.             $this->actionLoggerService->logAction("CRON_TWEETS_AND_MAILS_PROCESSED""MAIL");
  228.             $this->cache->deleteItem($keyCache);
  229.             return $this->json("Tweets and mails successfully sent");
  230.         } catch (Exception $e) {
  231.             $this->actionLoggerService->logException($e"sendMailsAndTweets error");
  232.             $this->cache->deleteItem($keyCache);
  233.             return $this->json("Error to send tweets  and mails: " $e->getMessage(), 500);
  234.         }
  235.     }
  236.     /**
  237.      * @Route("/intern/events/create_update_all_events", name="create_update_all_events", options={"expose"=true}, methods={"GET"})
  238.      * @return Response
  239.      */
  240.     public function createUpdateAllEventsFromAdminAction()
  241.     {
  242.         $this->eventSynchroniserService->updateEvents();
  243.         return new Response(null);
  244.     }
  245.     /**
  246.      * Update events and go back to event list
  247.      * @Route("/intern/events/create_update_all_events_from_admin", name="create_update_alls_events_from_admin", options={"expose"=true}, methods={"GET"})
  248.      *
  249.      * @return Response
  250.      */
  251.     public function createUpdateAllEventsFromAdminAndRedirectAction()
  252.     {
  253.         $this->eventSynchroniserService->updateEvents();
  254.         $this->bookingCatalogService->getBookableEvents(true);
  255.         /** @noinspection PhpRouteMissingInspection */
  256.         return $this->redirectToRoute('admin_app_event_list');
  257.     }
  258.     /**
  259.      * @Route("/intern/events/create_update_events_categories", name="create_update_events_categories", options={"expose"=true}, methods={"GET"})
  260.      * @Security("is_granted('ROLE_ADMINISTRATOR')")
  261.      * @return Response
  262.      */
  263.     public function createUpdateAllEventCategoriesAction()
  264.     {
  265.         $this->eventSynchroniserService->updateEventCategories();
  266.         /** @noinspection PhpRouteMissingInspection */
  267.         return $this->redirectToRoute('admin_app_event_list');
  268.     }
  269.     /**
  270.      * @Route("/intern/locations/update_distances", name="update_locations_distances", options={"expose"=true}, methods={"GET"})
  271.      * @return Response
  272.      */
  273.     public function updateLocationsDistancesFromAdminAction()
  274.     {
  275.         $this->geographicService->updateDistancesBetweenLocations();
  276.         /** @noinspection PhpRouteMissingInspection */
  277.         return $this->redirectToRoute('admin_app_location_list');
  278.     }
  279.     /**
  280.      * @Route("/intern/oss-partners/create_update_all_oss_partners", name="create_update_all_oss_partners", options={"expose"=true}, methods={"GET"})
  281.      * @return Response
  282.      */
  283.     public function createUpdateAllOssPartnersAction()
  284.     {
  285.         $this->ossService->updateOssUni();
  286.         return new Response(null);
  287.     }
  288.     /**
  289.      * @Route("/intern/oss-partners/create_update_all_oss_partners_from_admin", name="create_update_all_oss_partners_from_admin", options={"expose"=true}, methods={"GET"})
  290.      * @return Response
  291.      */
  292.     public function createUpdateAllOssPartnersFromAdminAction()
  293.     {
  294.         $this->ossService->updateOssUni();
  295.         /** @noinspection PhpRouteMissingInspection */
  296.         return $this->redirectToRoute('admin_app_osspartner_list');
  297.     }
  298.     /**
  299.      * @Route("/intern/oss-partners/create_update_oss_partner_from_admin/{ossPartnerId}", name="create_update_oss_from_admin", options={"expose"=true}, methods={"GET"})
  300.      * @param string $ossPartnerId the OSS Partner Id in NEOS that should be updated.
  301.      * @return Response
  302.      */
  303.     public function createUpdateOssPartnerFromAdminAction(string $ossPartnerId)
  304.     {
  305.         $ossPartner $this->ossService->updateOssPartner($ossPartnerId);
  306.         if ($ossPartner != null) {
  307.             /** @noinspection PhpRouteMissingInspection */
  308.             return $this->redirectToRoute('admin_app_osspartner_edit', ['id' => $ossPartner->getId()]);
  309.         } else {
  310.             /** @noinspection PhpRouteMissingInspection */
  311.             return $this->redirectToRoute('admin_app_osspartner_list');
  312.         }
  313.     }
  314.     /**
  315.      * Update events and go back to event list
  316.      * @Route("/intern/event/create_update_event_from_admin/{eventNo}", name="create_update_event_from_admin", options={"expose"=true}, methods={"GET"})
  317.      * @Security("is_granted('ROLE_ADMIN_EVENTS_ADMINISTRATOR')")
  318.      * @param string $eventNo the eventNo to be refreshed
  319.      * @return Response
  320.      */
  321.     public function createUpdateEventFromAdminAction(string $eventNo)
  322.     {
  323.         $event $this->eventSynchroniserService->updateFromEventNo($eventNo);
  324.         if ($event != null) {
  325.             /** @noinspection PhpRouteMissingInspection */
  326.             return $this->redirectToRoute('admin_app_event_edit', ['id' => $event->getId()]);
  327.         } else {
  328.             /** @noinspection PhpRouteMissingInspection */
  329.             return $this->redirectToRoute('admin_app_event_list');
  330.         }
  331.     }
  332.     /**
  333.      * @Get("/cron/process_worldfeed_reporting_mails", name="process_worldfeed_reporting_mails", methods={"GET"})
  334.      * @return JsonResponse
  335.      */
  336.     public function sendWorldfeedReports()
  337.     {
  338.         // Get all worldfeed where endDate = now
  339.         $worldfeeds $this->eventService->getAllWorldfeedByEndDate(new DateTime('-1 day'));
  340.         foreach ($worldfeeds as $worldfeed) {
  341.             $this->eventService->searchSpecificStatsWorldFeedInLocalDb($worldfeed->transmissionNo);
  342.         }
  343.         return $this->json("Worldfeed reports has been successfully sent");
  344.     }
  345.     /**
  346.      * @Get("/cron/process_worldlink_reporting_mails", name="process_worldlink_reporting_mails", methods={"GET"})
  347.      * @return JsonResponse
  348.      */
  349.     public function sendWorldlinkReports()
  350.     {
  351.         // Get all worldlink where endDate = now
  352.         $worldlinks $this->worldlinkService->getAllWorldlinkByEndDate(new DateTime('-1 day'));
  353.         foreach ($worldlinks as $worldlink) {
  354.             $this->splunkService->searchSpecificStatsWorldLinkSplunk($worldlink->getBetterId());
  355.         }
  356.         return $this->json("Worldlink reports has been successfully sent");
  357.     }
  358.     /**
  359.      * @Route("/cron/newsletter/campaign/update-last-campaign-status", name="cron_newsletter_update_last_campaign_status", options={"expose" = true })
  360.      * @return JsonResponse
  361.      */
  362.     public function updateLastCampaignStatusInDBAction()
  363.     {
  364.         try {
  365.             $newsletters $this->newslettersService->getLastCreatedNewsletters();
  366.             $objectIdDone = [];
  367.             foreach ($newsletters as $newsletter) {
  368.                 if (!in_array($newsletter->getObjectId(), $objectIdDone)) {
  369.                     $this->newslettersService->updateNewslettersStatus('events'$newsletter->getObjectId());
  370.                     array_push($objectIdDone$newsletter->getObjectId());
  371.                 }
  372.             }
  373.             return $this->json('ok');
  374.         } catch (Exception $e) {
  375.             return $this->json('ko');
  376.         }
  377.     }
  378.     /**
  379.      * @Route("/cron/newsletter/campaign/update-sending-campaign-status", name="cron_newsletter_update_sending_campaign_status", options={"expose" = true })
  380.      * @return JsonResponse
  381.      */
  382.     public function updateSendingCampaignStatusInDBAction()
  383.     {
  384.         $res $this->newslettersService->updateSendingCampaignStatusInDB();
  385.         return new JsonResponse(array(
  386.             'message' => $res->getMessage(),
  387.             'status' => $res->getStatus(),
  388.             'data' => $res->getData(),
  389.         ));
  390.     }
  391.     /**
  392.      * @Get("/cron/process_worldlink_cleaning", name="process_worldlink_cleaning", methods={"GET"})
  393.      * @return JsonResponse
  394.      */
  395.     public function worldlinkCleaning()
  396.     {
  397.         $pastWorldlinks $this->worldlinkService->getPublishedPastWorldlink();
  398.         $pastWorldlinkRemovedSuccessfully = [];
  399.         foreach ($pastWorldlinks as $pastWorldlink) {
  400.             $betterMedia $this->betterService->getItemBetterMedia($pastWorldlink->getBetterId());
  401.             if (!empty($betterMedia)) {
  402.                 $this->betterService->deleteMediaFromBetter($pastWorldlink->getBetterId());
  403.                 $pastWorldlinkRemovedSuccessfully[] = $pastWorldlink;
  404.             }
  405.             $this->worldlinkService->updateBetterStatusWorldLink($pastWorldlink);
  406.         }
  407.         return $this->json("Past Worldlinks have been removed from Better");
  408.     }
  409. }