vendor/pimcore/pimcore/bundles/CoreBundle/Migrations/Version20210324152822.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Bundle\CoreBundle\Migrations;
  16. use Doctrine\DBAL\Schema\Schema;
  17. use Doctrine\Migrations\AbstractMigration;
  18. use Pimcore\Db;
  19. /**
  20.  * @internal
  21.  */
  22. final class Version20210324152822 extends AbstractMigration
  23. {
  24.     /**
  25.      * @param Schema $schema
  26.      */
  27.     public function up(Schema $schema): void
  28.     {
  29.         $db Db::get();
  30.         $translationsTables $db->fetchAllAssociative("SHOW FULL TABLES WHERE `Tables_in_{$db->getDatabase()}` LIKE 'translations\_%' AND Table_type = 'BASE TABLE'");
  31.         foreach ($translationsTables as $table) {
  32.             $translationsTable current($table);
  33.             $translationsTableSchema $schema->getTable($translationsTable);
  34.             if ($translationsTableSchema->hasColumn('key')
  35.                 && $translationsTableSchema->hasColumn('language')
  36.                 && $translationsTableSchema->hasColumn('text')
  37.                 && !$translationsTableSchema->hasColumn('type')) {
  38.                 $this->addSql('ALTER TABLE `'.$translationsTable.'` ADD COLUMN `type` varchar(10) DEFAULT NULL AFTER `key`');
  39.             }
  40.         }
  41.     }
  42.     /**
  43.      * @param Schema $schema
  44.      */
  45.     public function down(Schema $schema): void
  46.     {
  47.         $db Db::get();
  48.         $translationsTables $db->fetchAllAssociative("SHOW FULL TABLES WHERE `Tables_in_{$db->getDatabase()}` LIKE 'translations\_%' AND Table_type = 'BASE TABLE'");
  49.         foreach ($translationsTables as $table) {
  50.             $translationsTable current($table);
  51.             $translationsTableSchema $schema->getTable($translationsTable);
  52.             if ($translationsTableSchema->hasColumn('key')
  53.                 && $translationsTableSchema->hasColumn('language')
  54.                 && $translationsTableSchema->hasColumn('text')
  55.                 && $translationsTableSchema->hasColumn('type')) {
  56.                 $this->addSql('ALTER TABLE `'.$translationsTable.'` DROP COLUMN `type`');
  57.             }
  58.         }
  59.     }
  60. }