From 64be22f08ee02cc612776a30b13d2100bcfbc80f Mon Sep 17 00:00:00 2001 From: yuri Date: Thu, 17 Jan 2019 17:22:31 +0200 Subject: [PATCH] jobPopulateOptedOutPhoneNumbers --- application/Espo/Services/App.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/application/Espo/Services/App.php b/application/Espo/Services/App.php index 1c34ae0e9e..c920e4ad48 100644 --- a/application/Espo/Services/App.php +++ b/application/Espo/Services/App.php @@ -367,4 +367,25 @@ class App extends \Espo\Core\Services\Base } catch (\Exception $e) {} } } + + public function jobPopulateOptedOutPhoneNumbers() + { + $entityTypeList = ['Contact', 'Lead']; + + foreach ($entityTypeList as $entityType) { + $entityList = $this->getEntityManager()->getRepository($entityType)->where([ + 'doNotCall' => true, + 'phoneNumber!=' => null, + ])->select(['id', 'phoneNumber'])->find(); + foreach ($entityList as $entity) { + $phoneNumber = $entity->get('phoneNumber'); + if (!$phoneNumber) continue; + $phoneNumberEntity = $this->getEntityManager()->getRepository('PhoneNumber')->getByNumber($phoneNumber); + if (!$phoneNumberEntity) continue; + $phoneNumberEntity->set('optOut', true); + $this->getEntityManager()->saveEntity($phoneNumberEntity); + + } + } + } }