Example #1
0
 public function saveAction()
 {
     if ($this->_getParam("id")) {
         $page = Document_Page::getById($this->_getParam("id"));
         $page = $this->getLatestVersion($page);
         $page->getPermissionsForUser($this->getUser());
         $page->setUserModification($this->getUser()->getId());
         // save to session
         $key = "document_" . $this->_getParam("id");
         $session = new Zend_Session_Namespace("pimcore_documents");
         $session->{$key} = $page;
         if ($this->_getParam("task") == "unpublish") {
             $page->setPublished(false);
         }
         if ($this->_getParam("task") == "publish") {
             $page->setPublished(true);
         }
         // only save when publish or unpublish
         if ($this->_getParam("task") == "publish" && $page->isAllowed("publish") or $this->_getParam("task") == "unpublish" && $page->isAllowed("unpublish")) {
             $this->setValuesToDocument($page);
             try {
                 $page->save();
                 $this->_helper->json(array("success" => true));
             } catch (Exception $e) {
                 Logger::err($e);
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         } else {
             if ($page->isAllowed("save")) {
                 $this->setValuesToDocument($page);
                 try {
                     $page->saveVersion();
                     $this->_helper->json(array("success" => true));
                 } catch (Exception $e) {
                     Logger::err($e);
                     $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
                 }
             }
         }
     }
     $this->_helper->json(false);
 }
 public function saveAction()
 {
     $data = json_decode($this->_getParam("data"), true);
     $document_id = $data["id"];
     $document = Document_Page::getById($document_id);
     $controller = $document->getController();
     $action = $document->getAction();
     $template = $document->getTemplate();
     $config_name = $controller . "_" . $action;
     if ($template != "") {
         $config_name . "_" . $template;
     }
     $documents = $this->config->getDocuments();
     unset($documents->{$config_name});
     if (sizeof($data["config"]) > 0) {
         $document_config = $documents->addChild($config_name);
         $document_config->addAttribute("controller", $controller);
         $document_config->addAttribute("action", $action);
         $document_config->addAttribute("template", $template);
         foreach ($data["config"] as $name => $values) {
             switch ($values["type"]) {
                 case "textarea":
                 case "wysiwyg":
                     $node = $document_config->addChild($name);
                     $node->addAttribute("type", $values["type"]);
                     $node->addAttribute("weight", $values["weight"]);
                     break;
                 default:
                     break;
             }
         }
         if ($document_config->count() == 0) {
             unset($documents->{$config_name});
         }
     }
     $this->config->writeXml();
     $this->config->writeSphinxConfig();
     $this->_helper->json(array("success" => true));
 }
$xml .= "  <sphinx:schema>\n";
$xml .= "    <sphinx:field name=\"o_published\"/>\n";
$xml .= "    <sphinx:field name=\"title\"/>\n";
$xml .= "    <sphinx:field name=\"description\"/>\n";
$xml .= "    <sphinx:field name=\"keywords\"/>\n";
$xml .= "    <sphinx:field name=\"site\"/>\n";
foreach ($document_config["elements"] as $name => $element) {
    $xml .= "    <sphinx:field name=\"" . $name . "\"/>\n";
}
$xml .= "  </sphinx:schema>\n";
foreach ($document_results as $document_result) {
    try {
        /**
         * @var Document_Page $document
         */
        $document = Document_Page::getById($document_result["id"]);
        SphinxSearch_Logger::debug("indexing document " . $document->getFullPath());
        /**
         * @var Site $site
         */
        $site = Pimcore_Tool_Frontend::getSiteForDocument($document);
        $site_id = "";
        if ($site) {
            $site_id = $site->getId();
        }
        if ($opts->language != "all" && $document->getProperty("language") != $opts->language) {
            continue;
        }
        $xml .= "\n  <sphinx:document id=\"" . $document->getId() . "\">\n";
        $xml .= "<o_published>" . ($document->getPublished() ? "1" : "0") . "</o_published>\n";
        $xml .= "<title><![CDATA[[" . $document->getTitle() . "]]></title>\n";
 public function saveAction()
 {
     if ($this->_getParam("id")) {
         $page = Document_Page::getById($this->_getParam("id"));
         $page = $this->getLatestVersion($page);
         $page->setUserModification($this->getUser()->getId());
         // save to session
         $key = "document_" . $this->_getParam("id");
         $session = new Zend_Session_Namespace("pimcore_documents");
         $session->{$key} = $page;
         if ($this->_getParam("task") == "unpublish") {
             $page->setPublished(false);
         }
         if ($this->_getParam("task") == "publish") {
             $page->setPublished(true);
         }
         // check for redirects
         if ($this->getUser()->isAllowed("redirects") && $this->_getParam("settings")) {
             $settings = Zend_Json::decode($this->_getParam("settings"));
             if (is_array($settings)) {
                 $redirectList = new Redirect_List();
                 $redirectList->setCondition("target = ?", $page->getId());
                 $existingRedirects = $redirectList->load();
                 $existingRedirectIds = array();
                 foreach ($existingRedirects as $existingRedirect) {
                     $existingRedirectIds[$existingRedirect->getId()] = $existingRedirect->getId();
                 }
                 for ($i = 1; $i < 100; $i++) {
                     if (array_key_exists("redirect_url_" . $i, $settings)) {
                         // check for existing
                         if ($settings["redirect_id_" . $i]) {
                             $redirect = Redirect::getById($settings["redirect_id_" . $i]);
                             unset($existingRedirectIds[$redirect->getId()]);
                         } else {
                             // create new one
                             $redirect = new Redirect();
                         }
                         $redirect->setSource($settings["redirect_url_" . $i]);
                         $redirect->setTarget($page->getId());
                         $redirect->setStatusCode(301);
                         $redirect->save();
                     }
                 }
                 // remove existing redirects which were delete
                 foreach ($existingRedirectIds as $existingRedirectId) {
                     $redirect = Redirect::getById($existingRedirectId);
                     $redirect->delete();
                 }
             }
         }
         // only save when publish or unpublish
         if ($this->_getParam("task") == "publish" && $page->isAllowed("publish") or $this->_getParam("task") == "unpublish" && $page->isAllowed("unpublish")) {
             $this->setValuesToDocument($page);
             try {
                 $page->save();
                 $this->_helper->json(array("success" => true));
             } catch (Exception $e) {
                 Logger::err($e);
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         } else {
             if ($page->isAllowed("save")) {
                 $this->setValuesToDocument($page);
                 try {
                     $page->saveVersion();
                     $this->_helper->json(array("success" => true));
                 } catch (Exception $e) {
                     Logger::err($e);
                     $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
                 }
             }
         }
     }
     $this->_helper->json(false);
 }
Example #5
0
 /**
  * creates a new document
  * @return void
  */
 public function testDocumentPageCreate()
 {
     $document = $this->createRandomDocument("page");
     $this->assertTrue($document->getId() > 0);
     $document->setKey($document->getKey() . "_data");
     $document->setProperties($this->getRandomProperties("document"));
     $document->setName("My document name");
     $document->setKeywords("document unittest");
     $document->setTitle("My unittest document title");
     $document->setDescription("This is a test document description");
     $this->addDataToDocument($document);
     $document->save();
     $refetch = Document_Page::getById($document->getId());
     //$this->assertTrue($refetch instanceof Document_Page);
     $this->assertTrue(Test_Tool::documentsAreEqual($document, $refetch, false));
 }