src/Controller/DefaultController.php
protected function doDeepCopy(array $deepCopyList)
    {
        if (empty($deepCopyList)) {
            return;
        }

        $factory                     = DcGeneralFactory::deriveFromEnvironment($this->getEnvironment());
        $dataDefinition              = $this->getEnvironment()->getDataDefinition();
        $modelRelationshipDefinition = $dataDefinition->getModelRelationshipDefinition();
        $childConditions             = $modelRelationshipDefinition->getChildConditions($dataDefinition->getName());

        foreach ($deepCopyList as $deepCopy) {
            /** @var ModelInterface $origin */
            $origin = $deepCopy['origin'];
            /** @var ModelInterface $model */
            $model = $deepCopy['model'];

            $parentId = ModelId::fromModel($model);

            foreach ($childConditions as $childCondition) {
                // create new destination environment
                $destinationName = $childCondition->getDestinationName();
                $factory->setContainerName($destinationName);
                $destinationEnvironment    = $factory->createEnvironment();
                $destinationDataDefinition = $destinationEnvironment->getDataDefinition();
                $destinationViewDefinition = $destinationDataDefinition->getDefinition(
                    Contao2BackendViewDefinitionInterface::NAME
                );
                $destinationDataProvider   = $destinationEnvironment->getDataProvider();
                $destinationController     = $destinationEnvironment->getController();
                /** @var Contao2BackendViewDefinitionInterface $destinationViewDefinition */
                /** @var DefaultController $destinationController */
                $listingConfig             = $destinationViewDefinition->getListingConfig();
                $groupAndSortingCollection = $listingConfig->getGroupAndSortingDefinition();
                $groupAndSorting           = $groupAndSortingCollection->getDefault();

                // ***** fetch the children
                $filter = $childCondition->getFilter($origin);

                // apply parent-child condition
                $config = $destinationDataProvider->getEmptyConfig();
                $config->setFilter($filter);

                // apply sorting
                $sorting = [];
                foreach ($groupAndSorting as $information) {
                    /** @var GroupAndSortingInformationInterface $information */
                    $sorting[$information->getProperty()] = $information->getSortingMode();
                }
                $config->setSorting($sorting);

                // receive children
                $children = $destinationDataProvider->fetchAll($config);

                // ***** do the deep copy
                $actions = [];

                // build the copy actions
                foreach ($children as $childModel) {
                    $childModelId = ModelId::fromModel($childModel);

                    $actions[] = [
                        'model' => $childModel,
                        'item'  => new Item(ItemInterface::DEEP_COPY, $parentId, $childModelId)
                    ];
                }

                // do the deep copy
                $childrenModels = $destinationController->doActions($actions, null, null, $parentId);

                // ensure parent-child condition
                foreach ($childrenModels as $childrenModel) {
                    $childCondition->applyTo($model, $childrenModel);
                }
                $destinationDataProvider->saveEach($childrenModels);
            }
        }
    }
protected function doDeepCopy(array $deepCopyList)
    {
        if (empty($deepCopyList)) {
            return;
        }

        $factory                     = DcGeneralFactory::deriveFromEnvironment($this->getEnvironment());
        $dataDefinition              = $this->getEnvironment()->getDataDefinition();
        $modelRelationshipDefinition = $dataDefinition->getModelRelationshipDefinition();
        $childConditions             = $modelRelationshipDefinition->getChildConditions($dataDefinition->getName());

        foreach ($deepCopyList as $deepCopy) {
            /** @var ModelInterface $origin */
            $origin = $deepCopy['origin'];
            /** @var ModelInterface $model */
            $model = $deepCopy['model'];

            $parentId = ModelId::fromModel($model);

            foreach ($childConditions as $childCondition) {
                // create new destination environment
                $destinationName = $childCondition->getDestinationName();
                $factory->setContainerName($destinationName);
                $destinationEnvironment    = $factory->createEnvironment();
                $destinationDataDefinition = $destinationEnvironment->getDataDefinition();
                $destinationViewDefinition = $destinationDataDefinition->getDefinition(
                    Contao2BackendViewDefinitionInterface::NAME
                );
                $destinationDataProvider   = $destinationEnvironment->getDataProvider();
                $destinationController     = $destinationEnvironment->getController();
                /** @var Contao2BackendViewDefinitionInterface $destinationViewDefinition */
                /** @var DefaultController $destinationController */
                $listingConfig             = $destinationViewDefinition->getListingConfig();
                $groupAndSortingCollection = $listingConfig->getGroupAndSortingDefinition();
                $groupAndSorting           = $groupAndSortingCollection->getDefault();

                // ***** fetch the children
                $filter = $childCondition->getFilter($origin);

                // apply parent-child condition
                $config = $destinationDataProvider->getEmptyConfig();
                $config->setFilter($filter);

                // apply sorting
                $sorting = [];
                foreach ($groupAndSorting as $information) {
                    /** @var GroupAndSortingInformationInterface $information */
                    $sorting[$information->getProperty()] = $information->getSortingMode();
                }
                $config->setSorting($sorting);

                // receive children
                $children = $destinationDataProvider->fetchAll($config);

                // ***** do the deep copy
                $actions = [];

                // build the copy actions
                foreach ($children as $childModel) {
                    $childModelId = ModelId::fromModel($childModel);

                    $actions[] = [
                        'model' => $childModel,
                        'item'  => new Item(ItemInterface::DEEP_COPY, $parentId, $childModelId)
                    ];
                }

                // do the deep copy
                $childrenModels = $destinationController->doActions($actions, null, null, $parentId);

                // ensure parent-child condition
                foreach ($childrenModels as $childrenModel) {
                    $childCondition->applyTo($model, $childrenModel);
                }
                $destinationDataProvider->saveEach($childrenModels);
            }
        }
    }
protected function doDeepCopy ( array $ deepCopyList ) { if ( empty ( $ deepCopyList ) ) { return ; } $ factory = DcGeneralFactory :: deriveFromEnvironment ( $ this -> getEnvironment ( ) ) ; $ dataDefinition = $ this -> getEnvironment ( ) -> getDataDefinition ( ) ; $ modelRelationshipDefinition = $ dataDefinition -> getModelRelationshipDefinition ( ) ; $ childConditions = $ modelRelationshipDefinition -> getChildConditions ( $ dataDefinition -> getName ( ) ) ; foreach ( $ deepCopyList as $ deepCopy ) { /** @var ModelInterface $origin */ $ origin = $ deepCopy [ 'origin' ] ; /** @var ModelInterface $model */ $ model = $ deepCopy [ 'model' ] ; $ parentId = ModelId :: fromModel ( $ model ) ; foreach ( $ childConditions as $ childCondition ) { // create new destination environment $ destinationName = $ childCondition -> getDestinationName ( ) ; $ factory -> setContainerName ( $ destinationName ) ; $ destinationEnvironment = $ factory -> createEnvironment ( ) ; $ destinationDataDefinition = $ destinationEnvironment -> getDataDefinition ( ) ; $ destinationViewDefinition = $ destinationDataDefinition -> getDefinition ( Contao2BackendViewDefinitionInterface :: NAME ) ; $ destinationDataProvider = $ destinationEnvironment -> getDataProvider ( ) ; $ destinationController = $ destinationEnvironment -> getController ( ) ; /** @var Contao2BackendViewDefinitionInterface $destinationViewDefinition */ /** @var DefaultController $destinationController */ $ listingConfig = $ destinationViewDefinition -> getListingConfig ( ) ; $ groupAndSortingCollection = $ listingConfig -> getGroupAndSortingDefinition ( ) ; $ groupAndSorting = $ groupAndSortingCollection -> getDefault ( ) ; // ***** fetch the children $ filter = $ childCondition -> getFilter ( $ origin ) ; // apply parent-child condition $ config = $ destinationDataProvider -> getEmptyConfig ( ) ; $ config -> setFilter ( $ filter ) ; // apply sorting $ sorting = [ ] ; foreach ( $ groupAndSorting as $ information ) { /** @var GroupAndSortingInformationInterface $information */ $ sorting [ $ information -> getProperty ( ) ] = $ information -> getSortingMode ( ) ; } $ config -> setSorting ( $ sorting ) ; // receive children $ children = $ destinationDataProvider -> fetchAll ( $ config ) ; // ***** do the deep copy $ actions = [ ] ; // build the copy actions foreach ( $ children as $ childModel ) { $ childModelId = ModelId :: fromModel ( $ childModel ) ; $ actions [ ] = [ 'model' => $ childModel , 'item' => new Item ( ItemInterface :: DEEP_COPY , $ parentId , $ childModelId ) ] ; } // do the deep copy $ childrenModels = $ destinationController -> doActions ( $ actions , null , null , $ parentId ) ; // ensure parent-child condition foreach ( $ childrenModels as $ childrenModel ) { $ childCondition -> applyTo ( $ model , $ childrenModel ) ; } $ destinationDataProvider -> saveEach ( $ childrenModels ) ; } } }
Do deep copy.

@param array $deepCopyList The deep copy list.

@return void
Do deep copy .