/**
  * 
  * @param string $propertyName
  * 
  * @return \Document_Page|null
  */
 public function getPropertyDocument($propertyName)
 {
     /* @var $property \Property */
     $property = $this->currentDocument->getProperty($propertyName, true);
     if (!$property) {
         return null;
     }
     if (!$property->getInherited()) {
         return $this->currentDocument;
     }
     $document = $this->currentDocument;
     while ($document = $document->getParent()) {
         /* @var $property \Property */
         $property = $document->getProperty($propertyName, true);
         if (!$property->getInherited()) {
             return $document;
         }
     }
     return null;
 }
Exemple #2
0
 public function getChilds()
 {
     if ($this->childs === null) {
         $childs = parent::getChilds();
         $hardLink = $this->getHardLinkSource();
         if ($hardLink->getChildsFromSource() && $hardLink->getSourceDocument() && !Pimcore::inAdmin()) {
             foreach ($childs as &$c) {
                 $c = Document_Hardlink_Wrapper::wrap($c);
                 $c->setHardLinkSource($hardLink);
                 $c->setPath(preg_replace("@^" . preg_quote($hardLink->getSourceDocument()->getFullpath()) . "@", $hardLink->getFullpath(), $c->getPath()));
             }
         }
         $this->setChilds($childs);
     }
     return $this->childs;
 }
Exemple #3
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));
 }
 public function addAction()
 {
     $success = false;
     // check for permission
     $parentDocument = Document::getById(intval($this->_getParam("parentId")));
     if ($parentDocument->isAllowed("create")) {
         $intendedPath = $parentDocument->getFullPath() . "/" . $this->_getParam("key");
         if (!Document_Service::pathExists($intendedPath)) {
             $createValues = array("userOwner" => $this->getUser()->getId(), "userModification" => $this->getUser()->getId(), "published" => false);
             $createValues["key"] = $this->_getParam("key");
             // check for a docType
             if ($this->_getParam("docTypeId") && is_numeric($this->_getParam("docTypeId"))) {
                 $docType = Document_DocType::getById(intval($this->_getParam("docTypeId")));
                 $createValues["template"] = $docType->getTemplate();
                 $createValues["controller"] = $docType->getController();
                 $createValues["action"] = $docType->getAction();
                 $createValues["module"] = $docType->getModule();
             } else {
                 if ($this->_getParam("type") == "page" || $this->_getParam("type") == "snippet" || $this->_getParam("type") == "email") {
                     $createValues["controller"] = Pimcore_Config::getSystemConfig()->documents->default_controller;
                     $createValues["action"] = Pimcore_Config::getSystemConfig()->documents->default_action;
                 }
             }
             switch ($this->_getParam("type")) {
                 case "page":
                     $document = Document_Page::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "snippet":
                     $document = Document_Snippet::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "email":
                     //ckogler
                     $document = Document_Email::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "link":
                     $document = Document_Link::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "hardlink":
                     $document = Document_Hardlink::create($this->_getParam("parentId"), $createValues);
                     $success = true;
                     break;
                 case "folder":
                     $document = Document_Folder::create($this->_getParam("parentId"), $createValues);
                     $document->setPublished(true);
                     try {
                         $document->save();
                         $success = true;
                     } catch (Exception $e) {
                         $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
                     }
                     break;
                 default:
                     Logger::debug("Unknown document type, can't add [ " . $this->_getParam("type") . " ] ");
                     break;
             }
         } else {
             Logger::debug("prevented adding a document because document with same path+key [ {$intendedPath} ] already exists");
         }
     } else {
         Logger::debug("prevented adding a document because of missing permissions");
     }
     if ($success) {
         $this->_helper->json(array("success" => $success, "id" => $document->getId(), "type" => $document->getType()));
     } else {
         $this->_helper->json(array("success" => $success));
     }
 }
$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);
 }
 /**
  * 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));
 }
 public function testCopyAndDeleteDocument()
 {
     $documentList = new Document_List();
     $documentList->setCondition("`key` like '%_data%' and `type` = 'page'");
     $documents = $documentList->load();
     $parent = $documents[0];
     $this->assertTrue($parent instanceof Document_Page);
     //remove childs if there are some
     if ($parent->hasChilds()) {
         foreach ($parent->getChilds() as $child) {
             $child->delete();
         }
     }
     $this->assertFalse($parent->hasChilds());
     $service = new Document_Service(User::getById(1));
     //copy as child
     $service->copyAsChild($parent, $parent);
     $this->assertTrue($parent->hasChilds());
     $this->assertTrue(count($parent->getChilds()) == 1);
     //copy as child no. 2
     $service->copyAsChild($parent, $parent);
     $this->assertTrue($parent->hasChilds());
     $this->assertTrue(count($parent->getChilds()) == 2);
     $childs = $parent->getChilds();
     $this->assertTrue(Test_Tool::documentsAreEqual($parent, $childs[0], true));
     $this->assertTrue(Test_Tool::documentsAreEqual($parent, $childs[1], true));
     //copy recursivley
     $rootNode = Document::getById(1);
     $copy = $service->copyRecursive($rootNode, $parent);
     $this->assertTrue($copy->hasChilds());
     $this->assertTrue(count($copy->getChilds()) == 2);
     $this->assertTrue(Test_Tool::documentsAreEqual($parent, $copy, true));
     //create empty document
     $emptyDoc = Document_Page::create(1, array("userOwner" => 1, "key" => uniqid() . rand(10, 99)));
     $this->assertFalse(Test_Tool::documentsAreEqual($emptyDoc, $copy, true));
     //copy contents
     $emptyDoc = $service->copyContents($emptyDoc, $copy);
     $this->assertTrue(Test_Tool::documentsAreEqual($emptyDoc, $copy, true));
     //todo copy contents must fail if types differ
     //delete recusively
     $shouldBeDeleted[] = $copy->getId();
     $childs = $copy->getChilds();
     foreach ($childs as $child) {
         $shouldBeDeleted[] = $child->getId();
     }
     $copy->delete();
     foreach ($shouldBeDeleted as $id) {
         $o = Document::getById($id);
         $this->assertFalse($o instanceof Document);
     }
 }