GenerateTokensCommand.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of Packagist.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. * Nils Adermann <naderman@naderman.de>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Packagist\WebBundle\Command;
  12. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  13. use Symfony\Bridge\Doctrine\RegistryInterface;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Input\InputOption;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. use Symfony\Component\HttpKernel\KernelInterface;
  18. use Symfony\Component\Finder\Finder;
  19. /**
  20. * @author Jordi Boggiano <j.boggiano@seld.be>
  21. */
  22. class GenerateTokensCommand extends ContainerAwareCommand
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function configure()
  28. {
  29. $this
  30. ->setName('packagist:tokens:generate')
  31. ->setDescription('Generates all missing user tokens')
  32. ;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. protected function execute(InputInterface $input, OutputInterface $output)
  38. {
  39. $doctrine = $this->getContainer()->get('doctrine');
  40. $userRepo = $doctrine->getRepository('PackagistWebBundle:User');
  41. $users = $userRepo->findUsersMissingApiToken();
  42. foreach ($users as $user) {
  43. $user->regenerateApiToken();
  44. }
  45. $doctrine->getEntityManager()->flush();
  46. }
  47. }