src/Command/SendMannedAlertsCommand.php line 210

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