Admin_TranslationController::contentExportJobsAction PHP Метод

contentExportJobsAction() публичный Метод

THE FOLLOWING ISN'T RELATED TO THE SHARED TRANSLATIONS OR ADMIN-TRANSLATIONS XLIFF CONTENT-EXPORT & MS WORD CONTENT-EXPORT
    public function contentExportJobsAction()
    {
        $data = \Zend_Json::decode($this->getParam("data"));
        $elements = [];
        $jobs = [];
        $exportId = uniqid();
        $source = $this->getParam("source");
        $target = $this->getParam("target");
        $type = $this->getParam("type");
        // XLIFF requires region in language code
        /*$languages = \Zend_Locale::getLocaleList();
                if(strlen($source) < 5) {
                    foreach ($languages as $key => $value) {
                        if(strlen($key) > 4 && strpos($key, $source . "_") === 0) {
                            $source = $key;
                            break;
                        }
                    }
                }
        
                if(strlen($target) < 5) {
                    foreach ($languages as $key => $value) {
                        if(strlen($key) > 4 && strpos($key, $target . "_") === 0) {
                            $target = $key;
                            break;
                        }
                    }
                }*/
        $source = str_replace("_", "-", $source);
        $target = str_replace("_", "-", $target);
        if ($data && is_array($data)) {
            foreach ($data as $element) {
                $elements[$element["type"] . "_" . $element["id"]] = ["id" => $element["id"], "type" => $element["type"]];
                if ($element["children"]) {
                    $el = Element\Service::getElementById($element["type"], $element["id"]);
                    $listClass = "\\Pimcore\\Model\\" . ucfirst($element["type"]) . "\\Listing";
                    $list = new $listClass();
                    $list->setUnpublished(true);
                    if ($el instanceof Object\AbstractObject) {
                        // inlcude variants
                        $list->setObjectTypes([Object\AbstractObject::OBJECT_TYPE_VARIANT, Object\AbstractObject::OBJECT_TYPE_OBJECT, Object\AbstractObject::OBJECT_TYPE_FOLDER]);
                    }
                    $list->setCondition(($el instanceof Object\AbstractObject ? "o_" : "") . "path LIKE ?", [$el->getRealFullPath() . ($el->getRealFullPath() != "/" ? "/" : "") . "%"]);
                    $idList = $list->loadIdList();
                    foreach ($idList as $id) {
                        $elements[$element["type"] . "_" . $id] = ["id" => $id, "type" => $element["type"]];
                    }
                }
            }
        }
        $elements = array_values($elements);
        $elementsPerJob = 10;
        if ($type == "word") {
            // the word export can only handle one document per request
            // the problem is Document\Service::render(), ... in the action can be a $this->redirect() or exit;
            // nobody knows what's happening in an action ;-) So we need to isolate them in isolated processes
            // so that the export doesn't stop completely after a "redirect" or any other unexpected behavior of an action
            $elementsPerJob = 1;
        }
        // one job = X elements
        $elements = array_chunk($elements, $elementsPerJob);
        foreach ($elements as $chunk) {
            $jobs[] = [["url" => "/admin/translation/" . $type . "-export", "params" => ["id" => $exportId, "source" => $source, "target" => $target, "data" => \Zend_Json::encode($chunk)]]];
        }
        $this->_helper->json(["success" => true, "jobs" => $jobs, "id" => $exportId]);
    }