/** * Get latest available version, using $force always returns a version no matter if it is the same as the published one * @param bool $force * @return array */ public function getLatestVersion($force = false) { $versionData = $this->db->fetchRow("SELECT id,date FROM versions WHERE cid = ? AND ctype='document' ORDER BY `id` DESC LIMIT 1", $this->model->getId()); if ($versionData["id"] && $versionData["date"] > $this->model->getModificationDate() || $force) { $version = Version::getById($versionData["id"]); return $version; } return; }
public function diffVersionsAction() { include_once 'DaisyDiff/HTMLDiff.php'; include_once 'simple_html_dom.php'; $versionFrom = Version::getById($this->_getParam("from")); $versionTo = Version::getById($this->_getParam("to")); $docFrom = $versionFrom->loadData(); $docTo = $versionTo->loadData(); // unlock the current session to access the version files session_write_close(); $request = $this->getRequest(); $fromSource = file_get_html($request->getScheme() . "://" . $request->getHttpHost() . $docFrom->getFullPath() . "?pimcore_version=" . $this->_getParam("from") . "&pimcore_admin_sid=" . $_COOKIE["pimcore_admin_sid"]); $toSource = file_get_html($request->getScheme() . "://" . $request->getHttpHost() . $docTo->getFullPath() . "?pimcore_version=" . $this->_getParam("to") . "&pimcore_admin_sid=" . $_COOKIE["pimcore_admin_sid"]); if ($docFrom instanceof Document_Page) { $from = $fromSource->find("body", 0); $to = $toSource->find("body", 0); } else { $from = $fromSource; $to = $toSource; } $diff = new HTMLDiffer(); $text = $diff->htmlDiff($from, $to); if ($docFrom instanceof Document_Page) { $fromSource->find("head", 0)->innertext = $fromSource->find("head", 0)->innertext . '<link rel="stylesheet" type="text/css" href="/pimcore/static/css/daisydiff.css" />'; $fromSource->find("body", 0)->innertext = $text; echo $fromSource; } else { echo '<link rel="stylesheet" type="text/css" href="/pimcore/static/css/daisydiff.css" />'; echo $text; } $this->removeViewRenderer(); }
public function showVersionAction() { $version = Version::getById($this->_getParam("id")); $asset = $version->loadData(); $this->view->asset = $asset; $this->render("show-version-" . $asset->getType()); }
public function versionUpdateAction() { $data = \Zend_Json::decode($this->getParam("data")); $version = Version::getById($data["id"]); $version->setPublic($data["public"]); $version->setNote($data["note"]); $version->save(); $this->_helper->json(array("success" => true)); }
public function init() { parent::init(); // log exceptions if handled by error_handler $this->checkForErrors(); // general definitions Pimcore::unsetAdminMode(); Document::setHideUnpublished(true); Object_Abstract::setHideUnpublished(true); Object_Abstract::setGetInheritedValues(true); // contains the logged in user if necessary $user = null; // assign variables $this->view->controller = $this; // init website config $config = Pimcore_Config::getWebsiteConfig(); $this->config = $config; $this->view->config = $config; if (!$this->_getParam("document")) { Zend_Registry::set("pimcore_editmode", false); $this->editmode = false; $this->view->editmode = false; // no document available, continue, ... return; } else { $this->setDocument($this->_getParam("document")); } if ($this->_getParam("pimcore_editmode") || $this->_getParam("pimcore_version") || $this->_getParam("pimcore_preview") || $this->_getParam("pimcore_admin") || $this->_getParam("pimcore_object_preview")) { $specialAdminRequest = true; $this->disableBrowserCache(); // start admin session & get logged in user $user = Pimcore_Tool_Authentication::authenticateSession(); } if (!$this->document->isPublished()) { if ($specialAdminRequest) { if (!$user) { throw new Exception("access denied for " . $this->document->getFullPath()); } } else { throw new Exception("access denied for " . $this->document->getFullPath()); } } // register global locale if the document has the system property "language" if ($this->document->getProperty("language")) { $locale = new Zend_Locale($this->document->getProperty("language")); Zend_Registry::set('Zend_Locale', $locale); $this->getResponse()->setHeader("Content-Language", strtolower(str_replace("_", "-", (string) $locale)), true); } // for editmode if ($user) { if ($this->_getParam("pimcore_editmode") and !Zend_Registry::isRegistered("pimcore_editmode")) { Zend_Registry::set("pimcore_editmode", true); // check if there is the document in the session $docKey = "document_" . $this->getDocument()->getId(); $docSession = new Zend_Session_Namespace("pimcore_documents"); if ($docSession->{$docKey}) { // if there is a document in the session use it $this->setDocument($docSession->{$docKey}); } else { // set the latest available version for editmode if there is no doc in the session $latestVersion = $this->getDocument()->getLatestVersion(); if ($latestVersion) { $latestDoc = $latestVersion->loadData(); if ($latestDoc instanceof Document_PageSnippet) { $this->setDocument($latestDoc); } } } // register editmode plugin $front = Zend_Controller_Front::getInstance(); $front->registerPlugin(new Pimcore_Controller_Plugin_Frontend_Editmode($this), 1000); } else { Zend_Registry::set("pimcore_editmode", false); } } else { Zend_Registry::set("pimcore_editmode", false); } // for preview if ($user) { // document preview if ($this->_getParam("pimcore_preview")) { // get document from session $docKey = "document_" . $this->_getParam("document")->getId(); $docSession = new Zend_Session_Namespace("pimcore_documents"); if ($docSession->{$docKey}) { $this->setDocument($docSession->{$docKey}); } } // object preview if ($this->_getParam("pimcore_object_preview")) { $key = "object_" . $this->_getParam("pimcore_object_preview"); $session = new Zend_Session_Namespace("pimcore_objects"); if ($session->{$key}) { $object = $session->{$key}; // add the object to the registry so every call to Object_Abstract::getById() will return this object instead of the real one Zend_Registry::set("object_" . $object->getId(), $object); } } } // for version preview if ($this->_getParam("pimcore_version")) { if ($user) { // only get version data at the first call || because of embedded Snippets ... if (!Zend_Registry::isRegistered("pimcore_version_active")) { $version = Version::getById($this->_getParam("pimcore_version")); $this->setDocument($version->getData()); Zend_Registry::set("pimcore_version_active", true); } } } // for public versions if ($this->_getParam("v")) { try { $version = Version::getById($this->_getParam("v")); if ($version->getPublic()) { $this->setDocument($version->getData()); } } catch (Exception $e) { } } // check if document is a wrapped hardlink, if this is the case send a rel=canonical header to the source document if ($this->getDocument() instanceof Document_Hardlink_Wrapper_Interface) { // get the cononical (source) document $hardlinkCanonicalSourceDocument = Document::getById($this->getDocument()->getId()); $request = $this->getRequest(); $this->getResponse()->setHeader("Link", '<' . $request->getScheme() . "://" . $request->getHttpHost() . $hardlinkCanonicalSourceDocument->getFullPath() . '>; rel="canonical"'); } // set some parameters $this->editmode = Zend_Registry::get("pimcore_editmode"); $this->view->editmode = Zend_Registry::get("pimcore_editmode"); }
public function diffVersionsAction() { $version1 = Version::getById($this->_getParam("from")); $object1 = $version1->loadData(); $version2 = Version::getById($this->_getParam("to")); $object2 = $version2->loadData(); $this->view->object1 = $object1; $this->view->object2 = $object2; }
/** * Get latest available version * * @return array */ public function getLatestVersion() { if ($this->model->getType() != "folder") { $versionData = $this->db->fetchRow("SELECT id,date FROM versions WHERE cid = ? AND ctype='asset' ORDER BY `id` DESC LIMIT 1", $this->model->getId()); if ($versionData["id"] && $versionData["date"] > $this->model->getModificationDate()) { $version = Version::getById($versionData["id"]); return $version; } } return; }
/** * */ public function maintenanceCleanUp() { $conf["document"] = Pimcore_Config::getSystemConfig()->documents->versions; $conf["asset"] = Pimcore_Config::getSystemConfig()->assets->versions; $conf["object"] = Pimcore_Config::getSystemConfig()->objects->versions; $elementTypes = array(); foreach ($conf as $elementType => $tConf) { if (intval($tConf->days) > 0) { $versioningType = "days"; $value = intval($tConf->days); } else { $versioningType = "steps"; $value = intval($tConf->steps); } if ($versioningType) { $elementTypes[] = array("elementType" => $elementType, $versioningType => $value); } } $versions = $this->getResource()->maintenanceGetOutdatedVersions($elementTypes); if (is_array($versions)) { foreach ($versions as $index => $id) { $version = Version::getById($id); if ($version->getCtype() == "document") { $element = Document::getById($version->getCid()); } else { if ($version->getCtype() == "asset") { $element = Asset::getById($version->getCid()); } else { if ($version->getCtype() == "object") { $element = Object_Abstract::getById($version->getCid()); } } } if ($element instanceof Element_Interface) { if ($element->getModificationDate() > $version->getDate()) { // delete version if it is outdated $version->delete(); } } else { // delete version if the correspondening element doesn't exist anymore $version->delete(); } // call the garbage collector every 100 iterations, to avoid a out-of-memory if ($index % 100 == 0) { Pimcore::collectGarbage(); } } } }
public function init() { parent::init(); // log exceptions if handled by error_handler $this->checkForErrors(); // general definitions Pimcore::unsetAdminMode(); Document::setHideUnpublished(true); Object_Abstract::setHideUnpublished(true); Object_Abstract::setGetInheritedValues(true); $adminSession = null; // assign variables $this->view->controller = $this; // init website config $config = Pimcore_Config::getWebsiteConfig(); $this->config = $config; $this->view->config = $config; if (!$this->_getParam("document")) { Zend_Registry::set("pimcore_editmode", false); $this->editmode = false; $this->view->editmode = false; // no document available, continue, ... return; } else { $this->setDocument($this->_getParam("document")); } if ($this->_getParam("pimcore_editmode") || $this->_getParam("pimcore_version") || $this->_getParam("pimcore_preview") || $this->_getParam("pimcore_admin") || $this->_getParam("pimcore_object_preview")) { $specialAdminRequest = true; Pimcore_Tool_Authentication::initSession(); // start admin session $adminSession = new Zend_Session_Namespace("pimcore_admin"); } if (!$this->document->isPublished()) { if ($specialAdminRequest) { if (!$adminSession->user instanceof User) { throw new Exception("access denied for " . $this->document->getFullPath()); } } else { throw new Exception("access denied for " . $this->document->getFullPath()); } } // register global locale if the document has the system property "language" if ($this->document->getProperty("language")) { $locale = new Zend_Locale($this->document->getProperty("language")); Zend_Registry::set('Zend_Locale', $locale); } // for editmode if ($adminSession && $adminSession->user instanceof User) { if ($this->_getParam("pimcore_editmode") and !Zend_Registry::isRegistered("pimcore_editmode")) { Zend_Registry::set("pimcore_editmode", true); // check if there is the document in the session $docKey = "document_" . $this->getDocument()->getId(); $docSession = new Zend_Session_Namespace("pimcore_documents"); if ($docSession->{$docKey}) { // if there is a document in the session use it $this->setDocument($docSession->{$docKey}); } else { // set the latest available version for editmode if there is no doc in the session $latestVersion = $this->getDocument()->getLatestVersion(); if ($latestVersion) { $latestDoc = $latestVersion->loadData(); if ($latestDoc instanceof Document_PageSnippet) { $this->setDocument($latestDoc); } } } // register editmode plugin $front = Zend_Controller_Front::getInstance(); $front->registerPlugin(new Pimcore_Controller_Plugin_Frontend_Editmode($this), 1000); } else { Zend_Registry::set("pimcore_editmode", false); } } else { Zend_Registry::set("pimcore_editmode", false); } // for preview if ($adminSession && $adminSession->user instanceof User) { // document preview if ($this->_getParam("pimcore_preview")) { // get document from session $docKey = "document_" . $this->_getParam("document")->getId(); $docSession = new Zend_Session_Namespace("pimcore_documents"); if ($docSession->{$docKey}) { $this->setDocument($docSession->{$docKey}); } } // object preview if ($this->_getParam("pimcore_object_preview")) { $key = "object_" . $this->_getParam("pimcore_object_preview"); $session = new Zend_Session_Namespace("pimcore_objects"); if ($session->{$key}) { $object = $session->{$key}; // add the object to the registry so every call to Object_Abstract::getById() will return this object instead of the real one Zend_Registry::set("object_" . $object->getId(), $object); } } } // for version preview if ($this->_getParam("pimcore_version")) { if ($adminSession && $adminSession->user instanceof User) { // only get version data at the first call || because of embedded Snippets ... try { Zend_Registry::get("pimcore_version_active"); } catch (Exception $e) { $version = Version::getById($this->_getParam("pimcore_version")); $this->setDocument($version->getData()); Zend_Registry::set("pimcore_version_active", true); } } } // for public versions if ($this->_getParam("v")) { try { $version = Version::getById($this->_getParam("v")); if ($version->getPublic()) { $this->setDocument($version->getData()); } } catch (Exception $e) { } } // set some parameters $this->editmode = Zend_Registry::get("pimcore_editmode"); $this->view->editmode = Zend_Registry::get("pimcore_editmode"); }
public static function execute() { $list = new Schedule_Task_List(); $list->setCondition("active = 1 AND date < ?", time()); $tasks = $list->load(); foreach ($tasks as $task) { try { if ($task->getCtype() == "document") { $document = Document::getById($task->getCid()); if ($document instanceof Document) { if ($task->getAction() == "publish-version" && $task->getVersion()) { try { $version = Version::getById($task->getVersion()); $document = $version->getData(); if ($document instanceof Document) { $document->setPublished(true); $document->save(); } else { Logger::err("Schedule_Task_Executor: Could not restore document from version data."); } } catch (Exception $e) { Logger::err("Schedule_Task_Executor: Version [ " . $task->getVersion() . " ] does not exist."); } } else { if ($task->getAction() == "publish") { $document->setPublished(true); $document->save(); } else { if ($task->getAction() == "unpublish") { $document->setPublished(false); $document->save(); } else { if ($task->getAction() == "delete") { $document->delete(); } } } } } } else { if ($task->getCtype() == "asset") { $asset = Asset::getById($task->getCid()); if ($asset instanceof Asset) { if ($task->getAction() == "publish-version" && $task->getVersion()) { try { $version = Version::getById($task->getVersion()); $asset = $version->getData(); if ($asset instanceof Asset) { $asset->save(); } else { Logger::err("Schedule_Task_Executor: Could not restore asset from version data."); } } catch (Exception $e) { Logger::err("Schedule_Task_Executor: Version [ " . $task->getVersion() . " ] does not exist."); } } else { if ($task->getAction() == "delete") { $asset->delete(); } } } } else { if ($task->getCtype() == "object") { $object = Object_Abstract::getById($task->getCid()); if ($object instanceof Object_Abstract) { if ($task->getAction() == "publish-version" && $task->getVersion()) { try { $version = Version::getById($task->getVersion()); $object = $version->getData(); if ($object instanceof Object_Abstract) { $object->setO_Published(true); $object->save(); } else { Logger::err("Schedule_Task_Executor: Could not restore object from version data."); } } catch (Exception $e) { Logger::err("Schedule_Task_Executor: Version [ " . $task->getVersion() . " ] does not exist."); } } else { if ($task->getAction() == "publish") { $object->setO_Published(true); $object->save(); } else { if ($task->getAction() == "unpublish") { $object->setO_Published(false); $object->save(); } else { if ($task->getAction() == "delete") { $object->delete(); } } } } } } } } $task->setActive(false); $task->save(); } catch (Exception $e) { Logger::err("There was a problem with the scheduled task ID: " . $task->getId()); Logger::err($e); } } }
public function maintenanceCleanUp() { $conf["document"] = Pimcore_Config::getSystemConfig()->documents->versions; $conf["asset"] = Pimcore_Config::getSystemConfig()->assets->versions; $conf["object"] = Pimcore_Config::getSystemConfig()->objects->versions; $types = array(); foreach ($conf as $type => $tConf) { if (intval($tConf->days) > 0) { $types[] = array("type" => $type, "days" => intval($tConf->days)); } } $versions = $this->getResource()->maintenanceGetOutdatedVersions($types); if (is_array($versions)) { foreach ($versions as $id) { $version = Version::getById($id); if ($version->getCtype() == "document") { $element = Document::getById($version->getCid()); } else { if ($version->getCtype() == "asset") { $element = Asset::getById($version->getCid()); } else { if ($version->getCtype() == "object") { $element = Object_Abstract::getById($version->getCid()); } } } if ($element instanceof Element_Interface) { if ($element->getModificationDate() > $version->getDate()) { // delete version if it is outdated $version->delete(); } } else { // delete version if the correspondening element doesn't exist anymore $version->delete(); } } } }
/** * get versions from database, and assign it to object * * @return array */ public function getVersions() { $versionIds = $this->db->fetchAll("SELECT id FROM versions WHERE cid = ? AND ctype='asset' ORDER BY `id` DESC", $this->model->getId()); $versions = array(); foreach ($versionIds as $versionId) { $versions[] = Version::getById($versionId["id"]); } $this->model->setVersions($versions); return $versions; }