Create command to set the privacy policy for existing customers. #233
This commit is contained in:
parent
b657ae95d5
commit
830803ac2d
1 changed files with 81 additions and 0 deletions
81
src/Command/SetCustomerPrivacyPolicyCommand.php
Normal file
81
src/Command/SetCustomerPrivacyPolicyCommand.php
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
|
||||||
|
use App\Entity\Customer;
|
||||||
|
use App\Entity\PrivacyPolicy;
|
||||||
|
use App\Entity\MobileSession;
|
||||||
|
|
||||||
|
class SetCustomerPrivacyPolicyCommand extends Command
|
||||||
|
{
|
||||||
|
private $em;
|
||||||
|
|
||||||
|
public function __construct(ObjectManager $om)
|
||||||
|
{
|
||||||
|
$this->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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue