migrations/Version20240327055601.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20240327055601 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return "TDP-2230 - tour destination slug değişimi";
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // backup table
  18.         $this->addSql("CREATE TABLE __seo_page_tour_destination COMMENT = 'Created for TDP-2230' SELECT * FROM seo_page WHERE type = 'TOUR_DESTINATION';");
  19.         // redirects
  20.         $this->addSql("INSERT IGNORE INTO seo_page (slug, type, redirect, status, redirect_code)
  21.             SELECT sp.slug,
  22.                    'REDIRECT',
  23.                    REPLACE(sp.slug, '-yurtdisi-', '-'),
  24.                    sp.status,
  25.                    301
  26.             FROM  seo_page sp
  27.             WHERE sp.type = 'TOUR_DESTINATION'
  28.               AND sp.status = 1
  29.               AND sp.slug LIKE '%-yurtdisi-%';
  30.         ");
  31.         // seo-page slug update
  32.         $this->addSql("UPDATE IGNORE seo_page sp
  33.             SET sp.slug = REPLACE(sp.slug, '-yurtdisi-', '-')
  34.             WHERE sp.type = 'TOUR_DESTINATION'
  35.               AND sp.slug LIKE '%-yurtdisi-%';
  36.         ");
  37.     }
  38.     public function down(Schema $schema): void
  39.     {
  40.         // restore seo-page slug
  41.         $this->addSql("UPDATE seo_page sp
  42.             INNER JOIN __seo_page_tour_destination b on b.id = sp.id
  43.             SET sp.slug = b.slug;
  44.         ");
  45.         // remove redirects
  46.         $this->addSql("DELETE IGNORE
  47.             FROM seo_page
  48.             WHERE slug IN (SELECT slug FROM __seo_page_tour_destination);
  49.         ");
  50.         // remove temp table
  51.         $this->addSql("DROP TABLE IF EXISTS __seo_page_tour_destination");
  52.     }
  53. }