84 lines
2.5 KiB
PHP
84 lines
2.5 KiB
PHP
<?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 Symfony\Component\Dotenv\Dotenv;
|
|
|
|
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.')
|
|
->setHelp('Set customer private policy.');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
// get the policy ids from .env
|
|
$dotenv = new Dotenv();
|
|
$dotenv->loadEnv(__DIR__.'/../../.env');
|
|
|
|
$policy_promo_id = $_ENV['POLICY_PROMO'];
|
|
$policy_third_party_id = $_ENV['POLICY_THIRD_PARTY'];
|
|
$policy_mobile_id = $_ENV['POLICY_MOBILE'];
|
|
|
|
// get third party policy
|
|
$third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->find($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($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($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();
|
|
}
|
|
}
|