From 830803ac2d5794ef5f096d11b4585ded8cff8f32 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 24 Jul 2019 12:54:59 +0000 Subject: [PATCH] Create command to set the privacy policy for existing customers. #233 --- .../SetCustomerPrivacyPolicyCommand.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/Command/SetCustomerPrivacyPolicyCommand.php diff --git a/src/Command/SetCustomerPrivacyPolicyCommand.php b/src/Command/SetCustomerPrivacyPolicyCommand.php new file mode 100644 index 00000000..8e2f468f --- /dev/null +++ b/src/Command/SetCustomerPrivacyPolicyCommand.php @@ -0,0 +1,81 @@ +em = $om; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('customer:setprivacypolicy') + ->setDescription('Set customer private policy.') + ->addArgument('third_party_policy_id', InputArgument::REQUIRED, 'third_party_policy_id') + ->addArgument('mobile_policy_id', InputArgument::REQUIRED, 'mobile_policy_id') + ->addArgument('promo_policy_id', InputArgument::REQUIRED, 'promo_policy_id' ) + ->setHelp('Set customer private policy. Order of ids: third party mobile promo'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $third_party_policy_id = $input->getArgument('third_party_policy_id'); + $mobile_policy_id = $input->getArgument('mobile_policy_id'); + $promo_policy_id = $input->getArgument('promo_policy_id'); + + // get third party policy + $third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $third_party_policy_id]); + + // get customers on third party + $third_party_customers = $this->em->getRepository(Customer::class)->findBy(['priv_third_party' => true]); + foreach ($third_party_customers as $cust) + { + $cust->setPrivacyPolicyThirdParty($third_party_policy); + } + + // get promo policy + $promo_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $promo_policy_id]); + + // get customers on promo + $promo_customers = $this->em->getRepository(Customer::class)->findBy(['priv_promo' => true]); + foreach ($promo_customers as $cust) + { + $cust->setPrivacyPolicyPromo($promo_policy); + } + + $this->em->flush(); + + // get mobile policy + $mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $mobile_policy_id]); + + // get mobile sessions + $mobile_sessions = $this->em->getRepository(MobileSession::class)->findAll(); + foreach ($mobile_sessions as $session) + { + $cust = $session->getCustomer(); + if (!(is_null($cust))) + { + $cust->setPrivacyPolicyMobile($mobile_policy); + } + } + + $this->em->flush(); + } +}