<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use App\Entity\User;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220624114823 extends AbstractMigration implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function getDescription(): string
{
return 'Создание админа';
}
public function up(Schema $schema): void
{
$user = new User();
$user->setEmail('admin@profsof.pro');
$user->setRoles(['ROLE_ADMIN']);
$user->setPassword($this->container->get(UserPasswordHasher::class)->hashPassword($user, '123456'));
$result = $this->connection->executeQuery('select max(id) from "user" where true');
$id = $result->fetchNumeric()[0] ? $result->fetchNumeric()[0] + 1 : 1;
$this->addSql('INSERT INTO "user" (id, email, roles, password) VALUES (' . $id . ', \'' . $user->getEmail() . '\', \'["ROLE_ADMIN"]\', \'' . $user->getPassword() . '\');');
}
public function down(Schema $schema): void
{
}
}