Copy all attached sub blocks (referencing sourceId) into new context and update prevId to sourceId

@param $sourceId
@param $targetPrevId
@param $targetNavItemPageId
540368
private function copySubBlocksTo($sourceId, $targetPrevId, $targetNavItemPageId)
    {
        if ($sourceId) {
            $subBlocks = NavItemPageBlockItem::findAll(['prev_id' => $sourceId]);
            foreach ($subBlocks as $block) {
                $newBlock = new NavItemPageBlockItem();
                $newBlock->attributes = $block->toArray();
                $newBlock->nav_item_page_id = $targetNavItemPageId;
                $newBlock->prev_id = $targetPrevId;
                $newBlock->insert();

                // check for attached sub blocks and start recursion
                $attachedBlocks = NavItemPageBlockItem::findAll(['prev_id' => $block->id]);
                if ($attachedBlocks) {
                    $this->copySubBlocksTo($block->id, $newBlock->id, $targetNavItemPageId);
                }
            }
        }
    }
365409
public function updateTarget(Target $target): void
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->update('ngbm_rule_target')
            ->set('rule_id', ':rule_id')
            ->set('type', ':type')
            ->set('value', ':value')
            ->where(
                $query->expr()->eq('id', ':id')
            )
            ->setParameter('id', $target->id, Type::INTEGER)
            ->setParameter('rule_id', $target->ruleId, Type::INTEGER)
            ->setParameter('type', $target->type, Type::STRING)
            ->setParameter('value', $target->value, is_array($target->value) ? Type::JSON_ARRAY : Type::STRING);

        $this->applyStatusCondition($query, $target->status);

        $query->execute();
    }
1002871
public function fillObjectWithRawData($targetObject, $rawData)
	{
		$classDefinition = $this->classDefinitionBuilder->buildFromClass(get_class($targetObject));

		$this->processObject($classDefinition, $targetObject, $rawData);
	}
779560
public function copyFile($source, $target, $file)
    {
        $this->mkDir($target);
        if (file_exists($source.$file)) {
            copy($source.$file, $target.$file);
        }
    }
1241964
public static function convertJsonToIni( $sourceFile, $targetFile )
	{
		$data	= self::loadJson( $sourceFile );
		return self::saveIni( $targetFile, $data );
	}
1352007
public void registerClonedEntity(String sourceEntityId, String targetEntityId) {

        CmsEntityBackend.getInstance().getEntity(sourceEntityId).createDeepCopy(targetEntityId);
    }
252505
protected function listenToHookable($targetEventName)
    {
        foreach ($this->sourcePatterns as $sourceEvent) {
            $listener = $this->newHookableListener($sourceEvent, $targetEventName);
            $this->source->onAfter($sourceEvent, $listener);
        }
        $this->isFixed = true;
    }
1025978
public static function staticToStatic(string $sourceName, string $targetName): void
  {
    $source      = file_get_contents($sourceName);
    $sourceClass = basename($sourceName, '.php');
    $targetClass = basename($targetName, '.php');

    $source = NonStatic::nonStatic($source, $sourceClass, $targetClass);

    file_put_contents($targetName, $source);
  }
29903
public function remove($sourceId, $targetId = null, $roleId = null)
    {
        $request = (new RequestDescriptor())
            ->setUrl($this->buildUrl(self::IDP_ATTRIBUTIONS_API))
            ->setMethod('DELETE')
            ->setRawData(json_encode([
                'source_id' => $sourceId,
                'target_id' => $targetId,
                'role_id' => $roleId,
            ]));

        try {
            $this->send($request);
        } catch (\Exception $e) {
            $previous = $e->getPrevious();

            if ($previous instanceof BadResponseException) {
                $error = json_decode($previous->getResponse()->getBody(), true);

                throw new UserAttributionException($error['error'], $error['code'], $previous);
            }

            throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
        }
    }
1094640
public function rebaseAndRedirectAction(NodeInterface $targetNode, Workspace $targetWorkspace)
    {
        $currentAccount = $this->securityContext->getAccount();
        $personalWorkspace = $this->workspaceRepository->findOneByName(UserUtility::getPersonalWorkspaceNameForUsername($currentAccount->getAccountIdentifier()));
        /** @var Workspace $personalWorkspace */

        if ($personalWorkspace !== $targetWorkspace) {
            if ($this->publishingService->getUnpublishedNodesCount($personalWorkspace) > 0) {
                $message = $this->translator->translateById('workspaces.cantEditBecauseWorkspaceContainsChanges', [], null, null, 'Modules', 'Neos.Neos');
                $this->addFlashMessage($message, '', Message::SEVERITY_WARNING, [], 1437833387);
                $this->redirect('show', null, null, ['workspace' => $targetWorkspace]);
            }

            $personalWorkspace->setBaseWorkspace($targetWorkspace);
            $this->workspaceRepository->update($personalWorkspace);
        }

        $contextProperties = $targetNode->getContext()->getProperties();
        $contextProperties['workspaceName'] = $personalWorkspace->getName();
        $context = $this->contextFactory->create($contextProperties);

        $mainRequest = $this->controllerContext->getRequest()->getMainRequest();
        /** @var ActionRequest $mainRequest */
        $this->uriBuilder->setRequest($mainRequest);

        if ($this->packageManager->isPackageAvailable('Neos.Neos.Ui')) {
            $this->redirect('index', 'Backend', 'Neos.Neos.Ui', ['node' => $context->getNode($targetNode->getPath())]);
        }

        $this->redirect('show', 'Frontend\\Node', 'Neos.Neos', ['node' => $context->getNode($targetNode->getPath())]);
    }
560466
public function injectNewValues(InputInterface $input, $instance, $targetId = 'id')
    {
        list($fields, $associations) = $this->getConfigs($instance);
        $fieldNames = array_keys(array_merge($fields, $associations));

        foreach ($fieldNames as $fieldName) {
            $value = ObjectFieldUtil::getFieldValue($input, $fieldName);

            if (empty($value)) {
                continue;
            }

            $value = ObjectFieldUtil::convertEmptyValue($value);

            if ((array_key_exists($fieldName, $fields))) {
                ObjectFieldUtil::setFieldValue($instance, $fieldName, $value);
            } elseif ((array_key_exists($fieldName, $associations))) {
                $this->setAssociationValue($instance, $fieldName, $value, $associations[$fieldName], $targetId);
            }
        }
    }
709663
def add_rel(self, source_id, target_id, rel):
        '''  '''
        if (source_id, target_id) not in self.rel_cache:
            self.workbench.add_rel(source_id, target_id, rel)
            self.rel_cache.add((source_id, target_id))
449039
public function validateTargetUpdateStruct(Target $target, TargetUpdateStruct $targetUpdateStruct): void
    {
        $targetType = $target->getTargetType();

        $this->validate(
            $targetUpdateStruct->value,
            $targetType->getConstraints(),
            'value'
        );
    }
1220028
public function move($target, $source)
    {
        $this->copy($target, $source);

        $this->delete($target);
    }
199840
private function copySource(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
    {
        if (self::DO_NOT_COPY === $this->copySource) {
            return;
        }

        if (($oldValue = $target->getSource()) === ($newValue = $source->getSource())) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Source is same, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );
            return;
        }

        if ((self::COPY_IF_EMPTY === $this->copySource) && !$target->isSourceEmpty()) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Source is not empty, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );

            return;
        }

        $this->logger->log(
            LogLevel::NOTICE,
            '{key}: Updating source value.',
            ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
        );

        if ($this->dryRun) {
            return;
        }

        $target->setSource($newValue);
    }
534339
public function setSiteTargetId(int $nb_site_target_id) : CNabuDataObject
    {
        if ($nb_site_target_id === null) {
            throw new ENabuCoreException(
                    ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
                    array("\$nb_site_target_id")
            );
        }
        $this->setValue('nb_site_target_id', $nb_site_target_id);
        
        return $this;
    }
1198701
public function rename(string $interface, string $newName, string $sourceName = Name::ANY, string $targetInterface = '')
    {
        $targetInterface = $targetInterface ?: $interface;
        if ($this->lastModule instanceof self) {
            $this->lastModule->getContainer()->move($interface, $sourceName, $targetInterface, $newName);
        }
    }