Snippets

Joshua WIlkeson Why is this command remove the jointable from the wrong users?

Created by Joshua WIlkeson
<?php

namespace DirectoryPlatform\AppBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller as Controller;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

class RemoveDirectoriesCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this->setName('directory-platform:remove-directories');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {

        $this->getContainer()->get('doctrine')->getManager()->getRepository('AppBundle:User')->removePlan();
        $users = $this->getContainer()->get('doctrine')->getManager()->getRepository('AppBundle:User')->removeDirectories();
        foreach ($users as $user) {
          foreach ($user->getCounties() as $county) {
            $county->removeUser($user);
            $em = $this->getContainer()->get('doctrine')->getManager();
            $em->persist($county);
            $em->flush();
          }
        }
    }
}
    public function removePlan()
    {
        $qb = $this->createQueryBuilder('user');
        return $qb->update()
            ->set('user.plan', '0')
            ->andWhere('user.upgradedUntil < CURRENT_TIMESTAMP()')
            ->getQuery()
            ->execute();
    }

    public function removeDirectories()
    {
        $qb = $this->createQueryBuilder('user');
        return $qb->andWhere('user.plan = 0')
            ->getQuery()
            ->execute();

    }

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.