<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231115024116 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$sql = 'SELECT `id` FROM `dtb_block` ORDER BY `id` DESC LIMIT 1';
$results = $this->connection->fetchAssociative($sql);
$lastId = (int) $results["id"] + 1;
$checkBlockSql = 'SELECT `id` FROM `dtb_block` WHERE block_name = "Contact Product"';
$isBlockExist = $this->connection->fetchAssociative($checkBlockSql);
$insert_block = "INSERT INTO dtb_block (id, device_type_id, block_name, file_name, use_controller, deletable, create_date, update_date, discriminator_type) VALUES ";
if (!$isBlockExist) {
$this->addSql($insert_block . "($lastId ,10, 'Contact Product', 'contact_product', 0, 1, '2023-11-15 09:00:00', '2023-11-15 09:00:00', 'block');");
}
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$sql = 'SELECT `id` FROM `dtb_block` WHERE block_name = "Contact Product"';
$results = $this->connection->fetchAssociative($sql);
if ($results) {
$this->addSql('DELETE FROM dtb_block_position WHERE block_id = ?',[(int)$results["id"]]);
$this->addSql('DELETE FROM dtb_block WHERE block_name = "Contact Product"');
}
}
}