| Current Path : /var/www/v3.cesa.co.za/src/UserBundle/Command/ |
| Current File : /var/www/v3.cesa.co.za/src/UserBundle/Command/UserListCommand.php |
<?php
namespace App\UserBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use App\UserBundle\Entity\UserList;
/**
* SF Guard User Command
*
* @author Otto Saayman <otto@igotafrica.com>
* @package UserBundle
* @subpackage Controller
* @version 0.0.1
*/
class UserListCommand extends Command {
protected function configure() {
$this
->setName('iga:user:user_list')
->setDescription('Add IGA Core users')
->addArgument('username', InputArgument::REQUIRED, 'The username')
->addArgument('password', InputArgument::REQUIRED, 'The password')
->addArgument('first_name', InputArgument::REQUIRED, 'The first name')
->addArgument('last_name', InputArgument::REQUIRED, 'The last name')
;
}
protected function execute(InputInterface $input, OutputInterface $output) {
$username = $input->getArgument('username');
$password = $input->getArgument('password');
$firstNameString = $input->getArgument('first_name');
$lastNameString = $input->getArgument('last_name');
$em = $this->getContainer()->get('doctrine')->getManager();
$user = $this->getContainer()->get('user_list.manager')->findOneBy(array('username' => $username));
if (!is_object($user)) {
$user = new UserList();
}
$user->setUsername($username);
$factory = $this->getContainer()->get('security.encoder_factory');
$encoder = $factory->getEncoder($user);
$user->setSalt(microtime());
$encodedPassword = $encoder->encodePassword($password, $user->getSalt());
$user->setPassword($encodedPassword);
$user->setUserEMailAddress(null);
$user->setIsActive(true);
$user->setIsSuperAdmin(true);
$user->setFirstNameString($firstNameString);
$user->setLastNameString($lastNameString);
$user->setDeleted(false);
$em->persist($user);
$em->flush();
$output->writeln(sprintf('Set %s user with password %s', $username, $password));
}
}