vendor/pimcore/pimcore/bundles/CoreBundle/Migrations/Version20211117173000.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\Model\DataObject;
  19. final class Version20211117173000 extends AbstractMigration
  20. {
  21.     /**
  22.      * {@inheritDoc}
  23.      */
  24.     public function getDescription(): string
  25.     {
  26.         return 'Updates class definition files';
  27.     }
  28.     public function up(Schema $schema): void
  29.     {
  30.         try {
  31.             $list = new DataObject\ClassDefinition\Listing();
  32.             foreach ($list->getClasses() as $class) {
  33.                 $this->write(sprintf('Saving class: %s'$class->getName()));
  34.                 $class->save();
  35.             }
  36.             $list = new DataObject\Objectbrick\Definition\Listing();
  37.             foreach ($list->load() as $brickDefinition) {
  38.                 $this->write(sprintf('Saving object brick: %s'$brickDefinition->getKey()));
  39.                 $brickDefinition->save();
  40.             }
  41.             $list = new DataObject\Fieldcollection\Definition\Listing();
  42.             foreach ($list->load() as $fc) {
  43.                 $this->write(sprintf('Saving field collection: %s'$fc->getKey()));
  44.                 $fc->save();
  45.             }
  46.             $list = new DataObject\ClassDefinition\CustomLayout\Listing();
  47.             foreach ($list->getLayoutDefinitions() as $layout) {
  48.                 $this->write(sprintf('Saving custom layout: %s'$layout->getName()));
  49.                 $layout->save();
  50.             }
  51.         } catch (DataObject\Exception\DefinitionWriteException $e) {
  52.             $this->write(
  53.                 'Could not write class definition file. Please set PIMCORE_CLASS_DEFINITION_WRITABLE env.' "\n" .
  54.                 sprintf(
  55.                     'If you have already migrated the definitions, you can skip this migration via "php bin/console doctrine:migrations:version --add %s"',
  56.                     __CLASS__
  57.                 )
  58.             );
  59.             throw $e;
  60.         }
  61.     }
  62.     public function down(Schema $schema): void
  63.     {
  64.         $this->write(sprintf('Please restore your class definition files in %s and run bin/console pimcore:deployment:classes-rebuild manually.'PIMCORE_CLASS_DEFINITION_DIRECTORY));
  65.     }
  66. }