src/Command/SendMannedAlertsCommand.php line 202

Open in your IDE?
  1. <?php
  2. namespace App\Command;
  3. use Datetime;
  4. use Pimcore\Db;
  5. use GuzzleHttp\Client;
  6. use Pimcore\Log\Simple;
  7. use App\Service\RedisCache;
  8. use App\Model\LocationModel;
  9. use GuzzleHttp\Psr7\Request;
  10. use App\Service\EmailService;
  11. use Pimcore\Model\DataObject;
  12. use App\Model\EwsNotificationModel;
  13. use App\Service\NCMWeatherAPIService;
  14. use App\Service\MeteomaticsWeatherService;
  15. use Symfony\Component\Console\Command\Command;
  16. use Symfony\Component\Templating\EngineInterface;
  17. use Symfony\Component\Console\Input\InputArgument;
  18. use Symfony\Component\Console\Input\InputInterface;
  19. use Symfony\Component\Console\Output\OutputInterface;
  20. use App\C2IntegrationBundle\Service\C2Service;
  21. use App\Service\RichService;
  22. use Symfony\Contracts\HttpClient\HttpClientInterface;
  23. class SendMannedAlertsCommand extends Command
  24. {
  25.     protected static $defaultName 'app:get-manned-alerts';
  26.     const HOURS 24;
  27.     var $emailService null;
  28.     private $templating;
  29.     private $nCMWeatherAPIService;
  30.     private $redisCache;
  31.     private $locationModel;
  32.     private $ewsNotificationModel;
  33.     private $c2Service;
  34.     private $richService;
  35.     private $httpClient;
  36.     public function __construct(EngineInterface $templatingRedisCache $redisCacheRichService $richServiceHttpClientInterface $httpClient)
  37.     {
  38.         parent::__construct();
  39.         $this->templating $templating;
  40.         $this->nCMWeatherAPIService = new NCMWeatherAPIService($redisCache,$httpClient);
  41.         $this->redisCache $redisCache;
  42.         $this->locationModel = new LocationModel();
  43.         $this->ewsNotificationModel = new EwsNotificationModel();
  44.         $this->c2Service = new C2Service();
  45.         $this->richService $richService;
  46.     }
  47.     protected function configure()
  48.     {
  49.         $this->setDescription('Retrieve manned alerts by location');
  50.     }
  51.     protected function execute(InputInterface $inputOutputInterface $output)
  52.     {   date_default_timezone_set(TIMEZONE);
  53.         $this->emailService = new EmailService();
  54.         $mateoMaticsService = new MeteomaticsWeatherService($this->redisCache);
  55.         $db DB::get();
  56.         $localities = [];
  57.         $loopCount 5;
  58.         $distincLocalities $db->fetchAll("SELECT GROUP_CONCAT(DISTINCT addressValue) as localities FROM `object_collection_AddressComponents_location` WHERE `addressKey` = 'locality'");
  59.         if ($distincLocalities) {
  60.             $localities explode(","$distincLocalities[0]['localities']);
  61.         }
  62.         // Fetching alerts 
  63.         $alerts $this->nCMWeatherAPIService->getAlerts();
  64.         if ($alerts) {
  65.             foreach ($alerts as $alert) {
  66.                 try {
  67.                     // Create update alert
  68.                     $mannedAlert $this->createUpdateAlertNotification($alert$output);
  69.                     if (!$mannedAlert) {
  70.                         $output->writeln('Nothing updated on notification = ' $alert['id']);
  71.                         continue;
  72.                     }
  73.                     if ($_ENV['SEND_EMAIL_NOTIFICATION'] == "false") {
  74.                         $output->writeln('Email is not allowed on this environment');
  75.                         continue;
  76.                     }
  77.                     if (!$mannedAlert->getIsSent()) {
  78.                         $mannedAlertSubscription = new DataObject\MannedAlertSubscription\Listing();
  79.                         $mannedAlertSubscription->setOrderKey("o_creationDate");
  80.                         $mannedAlertSubscription->setOrder("desc");
  81.                         foreach ($mannedAlertSubscription as $subscription) {
  82.                             if ($subscription->getIsPublic() == false) {
  83.                                 # code...
  84.                                 // $subscriptionRegion = $subscription->getIsPublic() ?? false;
  85.                                 $subscriptionRegion =  false;
  86.                                 if ($subscription->getRegion()) {
  87.                                     if ($subscription->getRegion()->getRegionId() == $alert['regionID']) {
  88.                                         $subscriptionRegion true;
  89.                                     }
  90.                                 }
  91.     
  92.                                 // $alertType = $subscription->getIsPublic() ?? false;
  93.                                 $alertType =  false;
  94.                                 if ($subscription->getAlertType()) {
  95.                                     foreach ($subscription->getAlertType() as $alertType) {
  96.                                         if ($alertType->getAlertTypeId() == $alert['alertType']) {
  97.                                             $alertType true;
  98.                                             break;
  99.                                         }
  100.                                     }
  101.                                 }
  102.     
  103.                                 // $alertGovernorate = $subscription->getIsPublic() ?? false;
  104.                                 $alertGovernorate =  false;
  105.                                 $alertGovernoratesIds array_column($alert['governorates'], 'id');
  106.                                 if ($subscription->getGovernorate()) {
  107.                                     foreach ($subscription->getGovernorate() as $governorate) {
  108.                                         if (in_array($governorate->getGovernoteId(), $alertGovernoratesIds)) {
  109.                                             $alertGovernorate true;
  110.                                             break;
  111.                                         }
  112.                                     }
  113.                                 }
  114.     
  115.                                 // $phenomena = $subscription->getIsPublic() ?? false;
  116.                                 $phenomena false;
  117.                                 $phenomenaIds array_column($alert['alertHazards'], 'id');
  118.                                 if ($subscription->getPhenomena()) {
  119.                                     foreach ($subscription->getPhenomena() as $phenomenas) {
  120.                                         if (in_array($phenomenas->getPhenomenaListId(), $phenomenaIds)) {
  121.                                             $phenomena true;
  122.                                             break;
  123.                                         }
  124.                                     }
  125.                                 }
  126.     
  127.     
  128.                                 if ($subscriptionRegion && $alertType && $alertGovernorate && $phenomena) {
  129.                                     // if (!empty($subscription->getEmail())) {
  130.                                     //     $user_name = explode('@', $subscription->getEmail());
  131.                                     //     $email = $this->sendEmailNotification($user_name[0], $alert, $subscription->getEmail(), $actualUser = false);
  132.     
  133.                                     //     // continue;
  134.                                     // }
  135.                                     if (!empty($subscription->getCreator())) {
  136.                                         $user $subscription->getCreator();
  137.     
  138.                                         if ($user->getSevereWeatherAlert()) {
  139.                                             $email $this->sendEmailNotification($user$alertnull true);
  140.                                         }
  141.                                     }
  142.                                 }
  143.                             }
  144.                         }
  145.                         // if (in_array($alert['regionEn'], $localities)) {
  146.                         //     // SELECT olqre.name as region,olqge.name as governate,olqwfc.name as municipality FROM object_region ore LEFT JOIN object_governorate ogo ON ore.oo_id = ogo.regionId__id LEFT JOIN object_weather_forecasting_city owfc ON owfc.MappedGovernorateId__id = ogo.oo_id LEFT JOIN object_localized_query_region_en olqre ON ore.oo_id = olqre.ooo_id LEFT JOIN object_localized_query_governorate_en olqge ON ogo.oo_id = olqge.ooo_id LEFT JOIN object_localized_query_weather_forecasting_city_en olqwfc ON owfc.oo_id = olqwfc.ooo_id
  147.                         //     // Fetching user fall in found localities
  148.                         //     $selectedLocalities = $this->ewsNotificationModel->getEwsNotificationByByRegionName($alert['regionEn']);
  149.                         //     if ($selectedLocalities) {
  150.                         //         $totalIterations = count($selectedLocalities);
  151.                         //         $iterations = 0;
  152.                         //         foreach ($selectedLocalities as $locality) {
  153.                         //             $locality = \Pimcore\Model\DataObject::getById($locality['o_id']);
  154.                         //             $users = $locality->getUser();
  155.                         //             // $email = $this->sendEmailNotification($users, $alert);
  156.                         //             // Increment the iteration count
  157.                         //             $iterations++;
  158.                         //             // Check if 5 iterations have passed
  159.                         //             if ($iterations % $loopCount === 0 && $iterations !== $totalIterations) {
  160.                         //                 // If 5 iterations have passed and it's not the last iteration, sleep for 65 seconds
  161.                         //                 sleep(65);
  162.                         //             }
  163.                         //         }
  164.                         //     }
  165.                         // }
  166.                     }
  167.                     $mannedAlert->setIsSent(true);
  168.                     $mannedAlert->save();
  169.                 } catch (\Exception $ex) {
  170.                     p_r($ex->getMessage());
  171.                 }
  172.             }
  173.         }
  174.         return 0;
  175.     }
  176.     private function sendEmailNotification($users$alert$email null$actualUser)
  177.     {
  178.         $mailSent null;
  179.         if ($alert) {
  180.             $governatesArr $alert['governorates'];
  181.             $governates = [];
  182.             if ($governatesArr) {
  183.                 foreach ($governatesArr as $gov) {
  184.                     $governates[] = $gov['nameEn'];
  185.                 }
  186.             }
  187.             $alertHazardsArr $alert['alertHazards'];
  188.             $alertHazards = [];
  189.             $alertHazards_ar = [];
  190.             if ($alertHazardsArr) {
  191.                 foreach ($alertHazardsArr as $alertHazard) {
  192.                     $alertHazards[] = $alertHazard['descriptionEn'];
  193.                     $alertHazards_ar[] = ['nameAr' =>$alertHazard['descriptionAr']];
  194.                 }
  195.             }
  196.             $alertActionsArr $alert['alertActions'];
  197.             $alertActions = [];
  198.             if ($alertActionsArr) {
  199.                 foreach ($alertActionsArr as $alertAction) {
  200.                     $alertActions[] = $alertAction['descriptionEn'];
  201.                 }
  202.             }
  203.             $data $alert;
  204.             $data['sender'] = 'National Center for Meteorology';
  205.             // $subject =$alert['searchEwsIdAr'] ??'Severe Weather Alert - ' . $alert['regionEn'];
  206.             $subject $alert['alertStatusAr'] . ' - ' $alert['regionAR'];
  207.             //sending an email document (pimcore document)
  208.             $emailAlertTemplate '/email/alert_notification';
  209.             if ($users) {
  210.                 $data['name'] = $email $users $users->getName();
  211.                 // extra param js
  212.                 $alertObj \Pimcore\Model\DataObject\AlertType::getByAlertTypeId($alert['alertType'], true);
  213.                 $alertName $alertObj->getColor() ? $alertObj->getColor() : '';
  214.                 $alert['user_name'] = $email $users $users->getName();
  215.                 $alert['host'] = API_BASE_URL;
  216.                 $alert['alertColor'] = $alertName;
  217.                 $backgroundColor '#fcb82526';
  218.                 $borderColor '#000000';
  219.                 $textColor '#000000';
  220.                 if (isset($alert['alertColor']) && !empty(trim($alert['alertColor']))) {
  221.                     $alertColorLower strtolower(trim($alert['alertColor']));
  222.                     if ($alertColorLower === 'red') {
  223.                         $backgroundColor '#f6000017';
  224.                         $borderColor '#F60000';
  225.                         $textColor '#F60000';
  226.                     } elseif ($alertColorLower === 'orange') {
  227.                         $backgroundColor '#ff66001f';
  228.                         $borderColor '#FF6600';
  229.                         $textColor '#FF6600';
  230.                     } elseif ($alertColorLower === 'yellow') {
  231.                         $backgroundColor '#fcb82526';
  232.                         $borderColor '#FCB825';
  233.                         $textColor '#FCB825';
  234.                     }
  235.                 }
  236.                 $alert['backgroundColor'] = $backgroundColor;
  237.                 $alert['borderColor'] = $borderColor;
  238.                 $alert['textColor'] = $textColor;
  239.                 $currentDate = new \DateTime($alert['fromDate']);
  240.                 $searchIdAr'النظام Ø§Ù„الي Ù„لإنذار Ø§Ù„مبكر | '.$currentDate->format('dmY').'-'.$alert['id'].' | '.$alert['alertTypeAr'].' | '.$alert['alertStatusAr'];
  241.                 $alert['searchEwsIdAr'] = $searchIdAr;
  242.                 $alert['alertHazard'] = $alertHazards_ar;
  243.                 $alert['last_modified_date'] =  $alert['lastModified'];
  244.                
  245.                 $alert['tokenURL'] = null// for now this is null but we have to develop unsubscribe functionality for this as well 
  246.                 if ($actualUser) {
  247.                     // general un subscribe function
  248.                     $token \App\Lib\Utility::getUnSubscribeToken($users->getId());
  249.                     $alert['tokenURL'] = BASE_URL '/unsubscribe/email?token=' $token;
  250.                 }
  251.               
  252.               
  253.               
  254.                 
  255.                 $alert['mannedAlertDatailUrl'] = "https://ncm.gov.sa/Ar/alert/Pages/MapDetail.aspx?AlertId=".$alert['id'];
  256.                 $html $this->templating->render('web2print/_manned_alert_notification_ar.html.twig'$alert);
  257.                 $mannedAlert \Pimcore\Model\DataObject\MannedAlertNotification::getByAlertId($alert['id'], true);
  258.                 $purpose MANNED_ALERT_MESSAGE;
  259.                 if ($email) {
  260.                     $mailSent $this->c2Service->sendDefaultEmail($_ENV['EWS_MAIL_TEMPLATE'], $mannedAlert->getId(), $email$html$subject$purpose);
  261.                 } else {
  262.                     $mailSent $this->c2Service->sendNotificationEmail($_ENV['EWS_MAIL_TEMPLATE'], $mannedAlert->getId(), $users->getId(), $html$subject$purpose);
  263.                 }
  264.                 if ($users->getPhoneNo() && strlen($users->getPhoneNo()) == 9) {
  265.                     $messageSMS sprintf(SMS_MESSAGE["MANNED_ALERT"], strtoupper($alertName) . " alert raised in " $alert['regionAR'] . ' for ' $alert['alertStatusAr'] . " event");
  266.                     $this->richService->sendSms(SAUDI_CALL_CODE.$users->getPhoneNo(), $messageSMS);
  267.                 }
  268.                 // $html = $this->templating->render('web2print/_manned_alert_notification_ar.html.twig', $alert);
  269.                 // $response['message_en'] = $html;
  270.                 // $email = $users->getEmail();
  271.                 // $param = ['user' => $users, 'message' => $html, 'url' => null];
  272.                 // $mailSent = $this->emailService->sendMail($param, $email, $emailAlertTemplate, $subject);
  273.             }
  274.             // if ($users) {
  275.             //     foreach ($users as $user) {
  276.             //         $data['name'] = $user->getName();
  277.             //         $html = $this->templating->render('web2print/_manned_alert_notification_ar.html.twig', $data);
  278.             //         $currentUser = $user->getObject();
  279.             //         $data = $user->getData();
  280.             //         if (isset($data['get_severe_alert']) && $data['get_severe_alert']) {
  281.             //             $email = $currentUser->getEmail();
  282.             //             $param = ['user' => $currentUser, 'message' => $html, 'url' => null];
  283.             //             $mailSent = $this->emailService->sendMail($param, $email, $emailAlertTemplate, $subject);
  284.             //         }
  285.             //     }
  286.             // }
  287.         }
  288.         return $mailSent;
  289.     }
  290.     private function createUpdateAlertNotification($alert$output)
  291.     {
  292.         // Generate the hash for the current alert data
  293.         $alertHash md5(json_encode($alert));
  294.         // Retrieve the existing MannedAlertNotification object by alert ID
  295.         $mannedAlert \Pimcore\Model\DataObject\MannedAlertNotification::getByAlertId($alert['id'], true);
  296.         // Check if the alert already exists
  297.         if ($mannedAlert) {
  298.             // Compare the old hash with the new hash
  299.             if ($mannedAlert->getHash() === $alertHash) {
  300.                 // If the hashes match, the alert has not changed; ignore it
  301.                 return null;
  302.             }
  303.         } else {
  304.             // If the alert does not exist, create a new MannedAlertNotification object
  305.             $mannedAlert = new DataObject\MannedAlertNotification();
  306.             $mannedAlert->setKey($alert['id']);
  307.             $date date('Y-m-d'strtotime($alert['fromDate']));
  308.             $mannedAlert->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/Notification/' $date));
  309.             $mannedAlert->setPublished(TRUE);
  310.         }
  311.         // Update the MannedAlertNotification object with the new alert data
  312.         $mannedAlert->setAlertId($alert['id']);
  313.         $mannedAlert->setTitle($alert['title']);
  314.         $mannedAlert->setAlertType($this->getAlertType($alert['alertType'], $alert['alertTypeAr'], $alert['alertTypeEn']));
  315.         $fromDate \Carbon\Carbon::createFromFormat('m/d/Y h:i:s A'$alert['fromDate']);
  316.         $toDate \Carbon\Carbon::createFromFormat('m/d/Y h:i:s A'$alert['toDate']);
  317.         $lastModified \Carbon\Carbon::createFromFormat('m/d/Y h:i:s A'$alert['lastModified']);
  318.         $mannedAlert->setFromDate($fromDate);
  319.         $mannedAlert->setToDate($toDate);
  320.         $mannedAlert->setLastModifiedDate($lastModified);
  321.         $mannedAlert->setAlertStatusCategory($this->getAlertStatusCategory($alert['alertStatusCategory']));
  322.         $mannedAlert->setAlertStatus($this->getAlertStatus($alert['alertStatusID'], $alert['alertStatusAr'], $alert['alertStatusEn']));
  323.         $alertHazardArr = [];
  324.         if ($alert['alertHazards']) {
  325.             foreach ($alert['alertHazards'] as $alertHazard) {
  326.                 $alertHazardArr[] = $this->getAlertHazard($alertHazard['id'], $alertHazard['descriptionAr'], $alertHazard['descriptionEn']);
  327.             }
  328.             $mannedAlert->setAlertHazards(array_filter($alertHazardArr));
  329.         }
  330.         $mannedAlert->setRegion($this->getRegion($alert['regionID'], $alert['regionAR'], $alert['regionEn']));
  331.         $alertGovernorateArr = [];
  332.         if ($alert['governorates']) {
  333.             foreach ($alert['governorates'] as $alertGovernorate) {
  334.                 $alertGovernorateArr[] = $this->getGovernorates($alertGovernorate['id'], $alertGovernorate['nameAr'], $alertGovernorate['nameEn'], $alertGovernorate['longitude'], $alertGovernorate['latitude']);
  335.             }
  336.             $mannedAlert->setGovernorates(array_filter($alertGovernorateArr));
  337.         }
  338.         $mannedAlert->setOtherLocation($alert['otherLocationsEn'], 'en');
  339.         $mannedAlert->setOtherLocation($alert['otherLocationsAr'], 'ar');
  340.         $mannedAlert->settweetID($alert['tweetID']);
  341.         $alertAlertActionArr = [];
  342.         if ($alert['alertActions']) {
  343.             foreach ($alert['alertActions'] as $alertAlertAction) {
  344.                 $alertAlertActionArr[] = $this->getAlertAction($alertAlertAction['id'], $alertAlertAction['descriptionAr'], $alertAlertAction['descriptionEn']);
  345.             }
  346.             $mannedAlert->setAlertAction(array_filter($alertAlertActionArr));
  347.         }
  348.         // Set the hash for the alert
  349.         $mannedAlert->setHash($alertHash);
  350.         $mannedAlert->setRawText(json_encode($alert));
  351.         $mannedAlert->setIsSent(false);
  352.         // Save the updated MannedAlertNotification object
  353.         $mannedAlert->save();
  354.         return $mannedAlert;
  355.     }
  356.     private function getAlertType($id$nameAr$nameEn)
  357.     {
  358.         $alertType \Pimcore\Model\DataObject\AlertType::getByAlertTypeId($idtrue);
  359.         if (!$alertType) {
  360.             $alertType = new \Pimcore\Model\DataObject\AlertType();
  361.             $alertType->setKey($id);
  362.             $alertType->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertType'));
  363.             $alertType->setAlertTypeId($id);
  364.             $alertType->setName($nameAr"en");
  365.             $alertType->setName($nameEn"ar");
  366.             $alertType->setPublished(true);
  367.             $alertType->save();
  368.         }
  369.         return $alertType;
  370.     }
  371.     private function getAlertStatusCategory($name)
  372.     {
  373.         $alertStatusCategory \Pimcore\Model\DataObject\AlertStatusCategory::getByName($nametrue);
  374.         if (!$alertStatusCategory) {
  375.             $alertStatusCategory = new \Pimcore\Model\DataObject\AlertStatusCategory();
  376.             $alertStatusCategory->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertStatusCategory'));
  377.             $alertStatusCategory->setKey($name);
  378.             $alertStatusCategory->setName($name);
  379.             $alertStatusCategory->setPublished(true);
  380.             $alertStatusCategory->save();
  381.         }
  382.         return $alertStatusCategory;
  383.     }
  384.     private function getAlertStatus($id$nameAr$nameEn)
  385.     {
  386.         $alertStatus \Pimcore\Model\DataObject\AlertStatus::getByAlertStatusId($idtrue);
  387.         if (!$alertStatus) {
  388.             $alertStatus = new \Pimcore\Model\DataObject\AlertStatus();
  389.             $alertStatus->setKey($id);
  390.             $alertStatus->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertStatus'));
  391.             $alertStatus->setAlertStatusId($id);
  392.             $alertStatus->setName($nameAr'ar');
  393.             $alertStatus->setName($nameEn'en');
  394.             $alertStatus->setPublished(true);
  395.             $alertStatus->save();
  396.         }
  397.         return $alertStatus;
  398.     }
  399.     private function getAlertHazard($id$descriptionAr$descriptionEn)
  400.     {
  401.         $alertHazard \Pimcore\Model\DataObject\AlertHazard::getByAlertHazardId($idtrue);
  402.         if (!$alertHazard) {
  403.             $alertHazard = new \Pimcore\Model\DataObject\AlertHazard();
  404.             $alertHazard->setKey($id);
  405.             $alertHazard->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertHazard'));
  406.             $alertHazard->setAlertHazardId($id);
  407.             $alertHazard->setName($descriptionAr"ar");
  408.             $alertHazard->setName($descriptionEn"en");
  409.             $alertHazard->setPublished(true);
  410.             $alertHazard->save();
  411.         } else {
  412.             $alertHazard->setName($descriptionAr"ar");
  413.             $alertHazard->setName($descriptionEn"en");
  414.             $alertHazard->save();
  415.         }
  416.         return $alertHazard;
  417.     }
  418.     private function getRegion($id$nameAr$nameEn)
  419.     {
  420.         $region \Pimcore\Model\DataObject\Region::getByRegionId($idtrue);
  421.         if (!$region) {
  422.             $region = new \Pimcore\Model\DataObject\Region();
  423.             $region->setKey($id);
  424.             $region->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/Region'));
  425.             $region->setRegionId($id);
  426.             $region->setName($nameAr'ar');
  427.             $region->setName($nameEn'en');
  428.             $region->setPublished(true);
  429.             $region->save();
  430.         }
  431.         return $region;
  432.     }
  433.     private function getGovernorates($id$nameAr$nameEn$longitude$latitude)
  434.     {
  435.         $governorate \Pimcore\Model\DataObject\Governorate::getByGovernoteId($idtrue);
  436.         if (!$governorate) {
  437.             $governorate = new \Pimcore\Model\DataObject\Governorate();
  438.             $governorate->setKey($id);
  439.             $governorate->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/Governorate'));
  440.             $governorate->setGovernoteId($id);
  441.             $governorate->setName($nameAr"ar");
  442.             $governorate->setName($nameEn"en");
  443.             $governorate->setLongitude($longitude);
  444.             $governorate->setLatitude($latitude);
  445.             $governorate->setPublished(true);
  446.             $governorate->save();
  447.         }
  448.         return $governorate;
  449.     }
  450.     private function getAlertAction($id$descriptionAr$descriptionEn)
  451.     {
  452.         $alertAction \Pimcore\Model\DataObject\AlertAction::getByAlertActionId($idtrue);
  453.         if (!$alertAction) {
  454.             $alertAction = new \Pimcore\Model\DataObject\AlertAction();
  455.             $alertAction->setKey($id);
  456.             $alertAction->setParent(\Pimcore\Model\DataObject\Service::createFolderByPath('/MannedAlert/Master/AlertAction'));
  457.             $alertAction->setAlertActionId($id);
  458.             $alertAction->setName($descriptionAr"ar");
  459.             $alertAction->setName($descriptionEn"en");
  460.             $alertAction->setPublished(true);
  461.             $alertAction->save();
  462.         }
  463.         return $alertAction;
  464.     }
  465. }