vendor/pimcore/pimcore/bundles/CoreBundle/Migrations/Version20221028115803.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\ClassDefinition\Listing;
  19. final class Version20221028115803 extends AbstractMigration
  20. {
  21.     public function getDescription(): string
  22.     {
  23.         return 'Regenerate definition files of classes with field collections';
  24.     }
  25.     public function up(Schema $schema): void
  26.     {
  27.         $this->regenerateClassesWithFieldCollections();
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $this->regenerateClassesWithFieldCollections();
  32.     }
  33.     /**
  34.      * @throws \Exception
  35.      */
  36.     private function regenerateClassesWithFieldCollections()
  37.     {
  38.         $listing = new Listing();
  39.         foreach ($listing->getClasses() as $class) {
  40.             $fds $class->getFieldDefinitions();
  41.             foreach ($fds as $fd) {
  42.                 if ($fd instanceof \Pimcore\Model\DataObject\ClassDefinition\Data\Fieldcollections) {
  43.                     $this->write(sprintf('Saving php files for class: %s'$class->getName()));
  44.                     $class->generateClassFiles(true);
  45.                     continue 2;
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }