68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Catalyst\APIBundle\Entity\User as APIUser;
|
|
|
|
use App\Entity\Rider;
|
|
|
|
use DateTime;
|
|
|
|
class CreateRiderAPIUserCommand extends Command
|
|
{
|
|
protected $em;
|
|
|
|
public function __construct(EntityManagerInterface $em)
|
|
{
|
|
$this->em = $em;
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this->setName('api:user-create-for-rider')
|
|
->setDescription('Create API users for existing riders.')
|
|
->setHelp('Creates API users for existing riders.');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
error_log('Creating api users...');
|
|
// get all existing riders
|
|
$riders = $this->em->getRepository(Rider::class)->findAll();
|
|
|
|
foreach ($riders as $rider)
|
|
{
|
|
// create api user for each rider
|
|
// no need to generate the keys.
|
|
// Secret and API keys are generated in constructor
|
|
$api_user = new APIUser();
|
|
|
|
// set name to rider's last name + first name
|
|
$rider_name = $rider->getLastName() . '_' . $rider->getFirstName();
|
|
$api_user->setName($rider_name);
|
|
|
|
// set rider to api_user
|
|
$api_user->setRider($rider);
|
|
|
|
// set meta
|
|
$meta = ['rider_id' => $rider->getID()];
|
|
$api_user->setMetaData($meta);
|
|
|
|
$this->em->persist($api_user);
|
|
}
|
|
|
|
$this->em->flush();
|
|
|
|
return 0;
|
|
}
|
|
}
|