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();
}
|