Page copy, use for multilang site

@param number $sourceId
@param number $targetId
@param string $lang
@return \Symfony\Component\HttpFoundation\Response>
334629
public function copyAction($sourceId, $targetId, $lang)
    {
        $em = $this->getDoctrine()->getManager();
        $source = $this->getPage($sourceId);
        $target = $this->getPage($targetId);
        $newPage = clone($source);
        $newPage->setParent($target);
        // Children page
        if ($target->getLang())
        {
            $newPage->setLang($target->getLang());
        }
        else
        {
            $newPage->setLang($lang);
            $newPage->setPosition($em->getRepository('FulgurioLightCMSBundle:Page')->getNextPosition($target));
        }
        $newPage->setStatus('draft');
        $newPage->setSourceId($sourceId);
        $models = $this->container->getParameter('fulgurio_light_cms.models');
        return $this->createPage($newPage, array('pageMetas' => $this->getPageMetas($sourceId), 'parent' => $target, 'sourceId' => $sourceId), $models);
    }
1153793
public static function convertXmlToIni( $sourceFile, $targetFile )
	{
		$data		= self::loadXml( $sourceFile );
		return self::saveIni( $targetFile, $data );
	}
184631
private function getArticleMap(string $sourceLanguage, string $targetLanguage): ArticleMap
    {
        if (!array_key_exists($key = $sourceLanguage . '->' . $targetLanguage, $this->articleMaps)) {
            return $this->articleMaps[$key] = new ArticleMap(
                $this->getPageMap($sourceLanguage, $targetLanguage),
                $this->logger
            );
        }

        return $this->articleMaps[$key];
    }
124816
public function getById($languageId, array $queryParams = [])
    {
        $response = $this->api->languages()->getById($languageId, $queryParams);

        return new LanguageResponse($response);
    }
590840
private function _initLanguageElements($languageSourceIds)
    {
        $languageSources = LanguageSource::findAll(['id' => $languageSourceIds]);
        foreach ($languageSources as $languageSource) {
            $this->_languageElements[$languageSource->category][$languageSource->message] = $languageSource->id;

            $category = Console::ansiFormat($languageSource->category, [Console::FG_RED]);
            $message = Console::ansiFormat($languageSource->message, [Console::FG_RED]);

            $this->_scanner->stdout('category: ' . $category . ', message: ' . $message);
        }
    }
704349
public static function create(
        UUID $id,
        MIMEType $mimeType,
        StringLiteral $description,
        StringLiteral $copyrightHolder,
        Url $sourceLocation,
        Language $language
    ) {
        $mediaObject = new self();
        $mediaObject->apply(
            new MediaObjectCreated(
                $id,
                $mimeType,
                $description,
                $copyrightHolder,
                $sourceLocation,
                $language
            )
        );

        return $mediaObject;
    }
71678
public function delete($lang, $id)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Tags', 'delete')) {
            return $this->noPermission();
        }

        $tagDeleteRes = $this->deleteTag($id);
        if(gettype($tagDeleteRes) == "boolean") {
            if($tagDeleteRes) {
                return $this->response('Tag is successfully deleted');
            }
        }else{
            return $tagDeleteRes;
        }
        return $this->response('Tag could not be deleted. Please try again later or contact your Administrator!', 500);
    }
361175
public function getPage(int $uid, int $languageUid = null) {
    $page   = null;
    $record = $this->pageRepository->getPage($uid);

    if (is_array($record) && !empty($record)) {
      if (in_array($record['doktype'], self::PAGE_DOKTYPES)) {
        $page        = $record;
        $languageUid = isset($languageUid) ? $languageUid : $this->languageService->getLanguageUid();

        if ($languageUid > 0) {
          $page = $this->pageRepository->getPageOverlay($page, $languageUid);
        }
      }
    }

    return $page;
  }
658856
public function createTarget($targetId, $base)
    {

        if(!is_string($base) && !is_array($base)){
            throw new \common_Exception('Invalid base format');
        }

        $array = array(
            'base'  => $base,
            'available' => array()
        );
        $this->set($targetId, $array);
    }
83023
public function get($entityId, $lang = 'en') 
    {
        if(!is_qid($entityId)) {
            throw new Exception("First argument in get() must by a valid Wikidata entity ID (e.g.: Q646).", 1);
        }

        $query = '
            SELECT ?item ?itemLabel ?itemDescription ?itemAltLabel ?prop ?propLabel (GROUP_CONCAT(DISTINCT ?valueLabel;separator=", ") AS ?propValue) WHERE { 
                  BIND(wd:'.$entityId.' AS ?item).
                  ?prop wikibase:directClaim ?p .
                  ?item ?p ?value .
                  SERVICE wikibase:label { 
                    bd:serviceParam wikibase:language "'.$lang.'". 
                    ?value rdfs:label ?valueLabel . 
                    ?prop rdfs:label ?propLabel . 
                    ?item rdfs:label ?itemLabel . 
                    ?item skos:altLabel ?itemAltLabel . 
                    ?item schema:description ?itemDescription . 
                  }    
                } group by ?item ?itemLabel ?itemDescription ?itemAltLabel ?prop ?propLabel
        '; 

        $client = new SparqlClient();

        $data = $client->execute($query); 

        if(!$data) {
            return null;
        }

        $entity = new Entity($data, $lang);

        return $entity;
    }
509389
public function deleteMenu($lang, $menuID)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Menu', 'delete')) {
            return $this->noPermission();
        }

        $menu = Menu::find($menuID);
        if(!$menu) {
            return $this->response("Menu doesn't exist", 400);
        }

        if(!$menu->isPrimary) {
            $menuLinks = MenuLink::where('menuID', $menuID);
            $menuLinks->delete();
            $menu->delete();
            return $this->response("Menu deleted", 200, Menu::getPrimaryMenuID());
        }else{
            return $this->response("Primary menu can not be deleted", 400);
        }
    }
1125208
public function getTargetIdFor(int $sourceId): int
    {
        if (!array_key_exists($sourceId, $this->map)) {
            throw new \RuntimeException('Not mapped');
        }
        return $this->map[$sourceId];
    }
1252004
public function findByPageIdAndByLanguageId($pageId, $languageId)
    {
        try {
            $this->initializeSearch($pageId, $languageId);
            $pageQuery = $this->queryBuilder->buildPageQuery($pageId);
            $response = $this->search->search($pageQuery, 0, 10000);
        } catch (NoSolrConnectionFoundException $exception) {
            return [];
        } catch (SolrCommunicationException $exception) {
            return [];
        }
        $data = $response->getParsedData();
        return $this->documentEscapeService->applyHtmlSpecialCharsOnAllFields($data->response->docs ?? []);
    }
630839
public function generateTranslation($packageKey, $sourceLanguageKey, array $targetLanguageKeys = [])
    {
        $translationPath = 'resource://' . $packageKey . '/Private/Translations';
        $contextVariables = [];
        $contextVariables['packageKey'] = $packageKey;
        $contextVariables['sourceLanguageKey'] = $sourceLanguageKey;

        $templatePathAndFilename = 'resource://Neos.Kickstarter/Private/Generator/Translations/SourceLanguageTemplate.xlf.tmpl';
        $fileContent = $this->renderTemplate($templatePathAndFilename, $contextVariables);
        $sourceLanguageFile = Files::concatenatePaths([$translationPath, $sourceLanguageKey, 'Main.xlf']);
        $this->generateFile($sourceLanguageFile, $fileContent);

        if ($targetLanguageKeys) {
            $xliffParser = new XliffParser();
            $parsedXliffArray = $xliffParser->getParsedData($sourceLanguageFile);
            foreach ($targetLanguageKeys as $targetLanguageKey) {
                $contextVariables['targetLanguageKey'] = $targetLanguageKey;
                $contextVariables['translationUnits'] = $parsedXliffArray['translationUnits'];

                $templatePathAndFilename = 'resource://Neos.Kickstarter/Private/Generator/Translations/TargetLanguageTemplate.xlf.tmpl';
                $fileContent = $this->renderTemplate($templatePathAndFilename, $contextVariables);
                $targetPathAndFilename = Files::concatenatePaths([$translationPath, $targetLanguageKey, 'Main.xlf']);
                $this->generateFile($targetPathAndFilename, $fileContent);
            }
        }

        return $this->generatedFiles;
    }
135510
public function beginExport(TranslatableInterface $translatable, $targetLang) {

    $this->openMemory();
    $this->setIndent(TRUE);
    $this->setIndentString(' ');
    $this->startDocument('1.0', 'UTF-8');

    // Root element with schema definition.
    $this->startElement('xliff');
    $this->writeAttribute('version', '1.2');
    $this->writeAttribute('xmlns:xlf', 'urn:oasis:names:tc:xliff:document:1.2');
    $this->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
    $this->writeAttribute('xmlns:html', 'http://www.w3.org/1999/xhtml');
    $this->writeAttribute('xsi:schemaLocation', 'urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-strict.xsd');

    // File element.
    $this->startElement('file');
    $this->writeAttribute('original', 'xliff-core-1.2-strict.xsd');
    $this->writeAttribute('source-language', $this->sourceLang);
    $this->writeAttribute('target-language', $targetLang);
    $this->writeAttribute('datatype', 'plaintext');

    // Date needs to be in ISO-8601 UTC.
    $this->writeAttribute('date', date('Y-m-d\Th:m:i\Z'));

    $this->startElement('header');
    $this->startElement('phase-group');
    $this->startElement('phase');
    $this->writeAttribute('tool-id', 'eggs-n-cereal');
    $this->writeAttribute('phase-name', 'extraction');
    $this->writeAttribute('process-name', 'extraction');
    $this->writeAttribute('job-id', $translatable->getIdentifier());

    $this->endElement();
    $this->endElement();
    $this->startElement('tool');
    $this->writeAttribute('tool-id', 'eggs-n-cereal');
    $this->writeAttribute('tool-name', 'Eggs-n-Cereal XLIFF Serializer');
    $this->endElement();
    $this->endElement();

    return $this->outputMemory() . '<body>';
  }
65454
public function translate($source, $target, $text)
    {
        return $this->getResponse($this->getRequest('', $text, $source, $target));
    }
495468
protected function copyElement(DOMElement $source, DOMElement $target)
	{
		if ($source->hasAttributes())
		{
			$attributes = $source->attributes;
			if (!is_null($attributes))
			{
				foreach ($attributes as $attr)
				{
					$target->setAttribute($attr->name, $attr->value);
				}
			}
		}

		foreach ($source->childNodes as $child)
		{
			$target->appendChild($child->cloneNode(true));
		}
	}