Use the env vars for the policy in the command. Improve the queries for privacy policy. #235

This commit is contained in:
Korina Cordero 2019-07-25 03:19:20 +00:00
parent c8cb0baec0
commit 3c460b86c9
2 changed files with 15 additions and 12 deletions

View file

@ -7,6 +7,8 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Dotenv\Dotenv;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager;
use App\Entity\Customer; use App\Entity\Customer;
@ -28,20 +30,21 @@ class SetCustomerPrivacyPolicyCommand extends Command
{ {
$this->setName('customer:setprivacypolicy') $this->setName('customer:setprivacypolicy')
->setDescription('Set customer private policy.') ->setDescription('Set customer private policy.')
->addArgument('third_party_policy_id', InputArgument::REQUIRED, 'third_party_policy_id') ->setHelp('Set customer private policy.');
->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) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$third_party_policy_id = $input->getArgument('third_party_policy_id'); // get the policy ids from .env
$mobile_policy_id = $input->getArgument('mobile_policy_id'); $dotenv = new Dotenv();
$promo_policy_id = $input->getArgument('promo_policy_id'); $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 // get third party policy
$third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $third_party_policy_id]); $third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_third_party_id);
// get customers on third party // get customers on third party
$third_party_customers = $this->em->getRepository(Customer::class)->findBy(['priv_third_party' => true]); $third_party_customers = $this->em->getRepository(Customer::class)->findBy(['priv_third_party' => true]);
@ -51,7 +54,7 @@ class SetCustomerPrivacyPolicyCommand extends Command
} }
// get promo policy // get promo policy
$promo_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $promo_policy_id]); $promo_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_promo_id);
// get customers on promo // get customers on promo
$promo_customers = $this->em->getRepository(Customer::class)->findBy(['priv_promo' => true]); $promo_customers = $this->em->getRepository(Customer::class)->findBy(['priv_promo' => true]);
@ -63,7 +66,7 @@ class SetCustomerPrivacyPolicyCommand extends Command
$this->em->flush(); $this->em->flush();
// get mobile policy // get mobile policy
$mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $mobile_policy_id]); $mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->find($policy_mobile_id);
// get mobile sessions // get mobile sessions
$mobile_sessions = $this->em->getRepository(MobileSession::class)->findAll(); $mobile_sessions = $this->em->getRepository(MobileSession::class)->findAll();

View file

@ -1816,7 +1816,7 @@ class APIController extends Controller
if ($priv_promo) if ($priv_promo)
{ {
// find the promo policy // find the promo policy
$policy = $em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $policy_promo_id]); $policy = $em->getRepository(PrivacyPolicy::class)->find($policy_promo_id);
// set policy id // set policy id
if ($policy != null) if ($policy != null)
@ -1828,7 +1828,7 @@ class APIController extends Controller
if ($priv_third_party) if ($priv_third_party)
{ {
// find the third party policy // find the third party policy
$policy = $em->getRepository(PrivacyPolicy::class)->findOneBy(['id' => $policy_third_party_id]); $policy = $em->getRepository(PrivacyPolicy::class)->find($policy_third_party_id);
// set policy id // set policy id
if ($policy != null) if ($policy != null)