vendor/pimcore/pimcore/bundles/CoreBundle/Migrations/Version20211103055110.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. /**
  19.  * @internal
  20.  */
  21. class Version20211103055110 extends AbstractMigration
  22. {
  23.     public function up(Schema $schema): void
  24.     {
  25.         $db \Pimcore\Db::get();
  26.         $classes $db->fetchFirstColumn('SELECT id FROM classes');
  27.         foreach ($classes as $class) {
  28.             $objectDatastoreTableRelation 'object_relations_' $class;
  29.             if ($schema->hasTable($objectDatastoreTableRelation)) {
  30.                 $this->addSql(
  31.                     "UPDATE $objectDatastoreTableRelation SET `type` = 'object' WHERE `type` = NULL OR `type` =''"
  32.                 );
  33.                 $this->addSql(
  34.                     "ALTER TABLE $objectDatastoreTableRelation CHANGE COLUMN
  35.                         `type` `type` ENUM('object', 'asset', 'document') NOT NULL;"
  36.                 );
  37.             }
  38.         }
  39.     }
  40.     public function down(Schema $schema): void
  41.     {
  42.         $db \Pimcore\Db::get();
  43.         $classes $db->fetchAssociative('SELECT id FROM classes');
  44.         foreach ($classes as $class) {
  45.             $objectDatastoreTableRelation 'object_relations_' $class;
  46.             if ($schema->hasTable($objectDatastoreTableRelation)) {
  47.                 $this->addSql(
  48.                     "ALTER TABLE $objectDatastoreTableRelation CHANGE COLUMN
  49.                         `type` `type` VARCHAR(50) NOT NULL DEFAULT '';"
  50.                 );
  51.             }
  52.         }
  53.     }
  54. }