You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.1 KiB
77 lines
2.1 KiB
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use Doctrine\DBAL\Connection;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class PopulateDBEmojiAvailableCommand extends Command
|
|
{
|
|
|
|
protected static $defaultName = 'app:popDBEmojiAvai';
|
|
|
|
private Connection $connection;
|
|
|
|
public function __construct(Connection $connection)
|
|
{
|
|
parent::__construct();
|
|
$this->connection = $connection;
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setDescription('Populate the database.');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
try {
|
|
|
|
// On supprime la table si elle existe déjà
|
|
$this->connection->executeStatement('DROP TABLE IF EXISTS stock_emoji');
|
|
|
|
// On crée la table
|
|
$this->connection->executeStatement('
|
|
CREATE TABLE stock_emoji (
|
|
id INT PRIMARY KEY,
|
|
code VARCHAR(255) NOT NULL
|
|
)
|
|
');
|
|
|
|
// On peuple la table
|
|
$this->connection->executeStatement("INSERT INTO stock_emoji (id, code) VALUES
|
|
(1,'🤖'),
|
|
(2,'😺'),
|
|
(3,'🧠'),
|
|
(4,'👻'),
|
|
(5,'🧟'),
|
|
(6,'🐶'),
|
|
(7,'👽'),
|
|
(8,'🧛'),
|
|
(9,'🎃'),
|
|
(10,'🐸'),
|
|
(11,'⚡'),
|
|
(12,'💀'),
|
|
(13,'🔥'),
|
|
(14,'🧙'),
|
|
(15,'🌪️'),
|
|
(16,'😎'),
|
|
(17,'😁'),
|
|
(18,'🌟'),
|
|
(19,'😈')
|
|
");
|
|
|
|
$output->writeln('Base de données peuplée.');
|
|
} catch (\Exception $e) {
|
|
$output->writeln('<error>Erreur : ' . $e->getMessage() . '</error>');
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|