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