migrations/Version20220624114823.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use App\Entity\User;
  5. use Doctrine\DBAL\Connection;
  6. use Doctrine\DBAL\Schema\Schema;
  7. use Doctrine\Migrations\AbstractMigration;
  8. use Psr\Log\LoggerInterface;
  9. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  10. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  11. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher;
  12. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  13. /**
  14.  * Auto-generated Migration: Please modify to your needs!
  15.  */
  16. final class Version20220624114823 extends AbstractMigration implements ContainerAwareInterface
  17. {
  18.     use ContainerAwareTrait;
  19.     public function getDescription(): string
  20.     {
  21.         return 'Создание админа';
  22.     }
  23.     public function up(Schema $schema): void
  24.     {
  25.         $user = new User();
  26.         $user->setEmail('admin@profsof.pro');
  27.         $user->setRoles(['ROLE_ADMIN']);
  28.         $user->setPassword($this->container->get(UserPasswordHasher::class)->hashPassword($user'123456'));
  29.         $result $this->connection->executeQuery('select max(id) from "user" where true');
  30.         $id $result->fetchNumeric()[0] ? $result->fetchNumeric()[0] + 1;
  31.         $this->addSql('INSERT INTO "user" (id, email, roles, password) VALUES (' $id ', \'' $user->getEmail() . '\', \'["ROLE_ADMIN"]\', \'' $user->getPassword() . '\');');
  32.     }
  33.     public function down(Schema $schema): void
  34.     {
  35.     }
  36. }