<?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 Version20240327055601 extends AbstractMigration
{
public function getDescription(): string
{
return "TDP-2230 - tour destination slug değişimi";
}
public function up(Schema $schema): void
{
// backup table
$this->addSql("CREATE TABLE __seo_page_tour_destination COMMENT = 'Created for TDP-2230' SELECT * FROM seo_page WHERE type = 'TOUR_DESTINATION';");
// redirects
$this->addSql("INSERT IGNORE INTO seo_page (slug, type, redirect, status, redirect_code)
SELECT sp.slug,
'REDIRECT',
REPLACE(sp.slug, '-yurtdisi-', '-'),
sp.status,
301
FROM seo_page sp
WHERE sp.type = 'TOUR_DESTINATION'
AND sp.status = 1
AND sp.slug LIKE '%-yurtdisi-%';
");
// seo-page slug update
$this->addSql("UPDATE IGNORE seo_page sp
SET sp.slug = REPLACE(sp.slug, '-yurtdisi-', '-')
WHERE sp.type = 'TOUR_DESTINATION'
AND sp.slug LIKE '%-yurtdisi-%';
");
}
public function down(Schema $schema): void
{
// restore seo-page slug
$this->addSql("UPDATE seo_page sp
INNER JOIN __seo_page_tour_destination b on b.id = sp.id
SET sp.slug = b.slug;
");
// remove redirects
$this->addSql("DELETE IGNORE
FROM seo_page
WHERE slug IN (SELECT slug FROM __seo_page_tour_destination);
");
// remove temp table
$this->addSql("DROP TABLE IF EXISTS __seo_page_tour_destination");
}
}