em = $em; $this->policy_promo_id = $policy_promo; $this->policy_third_party_id = $policy_third_party; $this->policy_mobile_id = $policy_mobile; parent::__construct(); } protected function configure() { $this->setName('customer:setprivacypolicy') ->setDescription('Set customer private policy.') ->setHelp('Set customer private policy.'); } protected function execute(InputInterface $input, OutputInterface $output) { // get third party policy $third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->find($this->policy_third_party_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)->find($this->policy_promo_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)->find($this->policy_mobile_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(); return 0; } }