public function saveAction() { try { if ($this->getParam("id")) { $page = Document\Email::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->setUserModification($this->getUser()->getId()); 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->saveToSession($page); $this->_helper->json(["success" => true]); } catch (\Exception $e) { \Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->saveToSession($page); $this->_helper->json(["success" => true]); } catch (\Exception $e) { if (Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) { throw $e; } \Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } } } catch (\Exception $e) { \Logger::log($e); if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) { $this->_helper->json(["success" => false, "type" => "ValidationException", "message" => $e->getMessage(), "stack" => $e->getTraceAsString(), "code" => $e->getCode()]); } throw $e; } $this->_helper->json(false); }
public function requestPasswordReset() { $this->setResetHash($this->createHash()); $this->save(); $doc = Email::getByPath(Config::get('emails')->passwordReset); if (!$doc) { throw new \Exception('No password reset email defined'); } /** @var \Zend_Controller_Request_Http $request */ $request = \Zend_Controller_Front::getInstance()->getRequest(); $email = new Mail(); $email->addTo($this->getEmail()); $email->setDocument($doc); $email->setParams(['host' => sprintf('%s://%s', $request->getScheme(), $request->getHttpHost()), 'member_id' => $this->getId()]); $email->send(); return $this; }
/** * Callback for 'member.register.post' event. * Sending email with confirmation links. * * @param \Zend_EventManager_Event $event * @return \Member * @throws \Exception */ public static function confirm(\Zend_EventManager_Event $event) { /** @var \Member $member */ $member = $event->getTarget(); $member->setConfirmHash($member->createHash()); $member->save(); $doc = Email::getByPath(Config::get('emails')->registerConfirm); if (!$doc) { throw new \Exception('No confirmation email defined'); } /** @var \Zend_Controller_Request_Http $request */ $request = \Zend_Controller_Front::getInstance()->getRequest(); $email = new Mail(); $email->addTo($member->getEmail()); $email->setDocument($doc); $email->setParams(['host' => sprintf('%s://%s', $request->getScheme(), $request->getHttpHost()), 'member_id' => $member->getId()]); $email->send(); return $member; }
public function saveAction() { if ($this->getParam("id")) { $page = Document\Email::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->setUserModification($this->getUser()->getId()); 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->saveToSession($page); $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->saveToSession($page); $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 addAction() { $success = false; $errorMessage = ""; // 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 $docType = Document\DocType::getById(intval($this->getParam("docTypeId"))); if ($docType) { $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"] = Config::getSystemConfig()->documents->default_controller; $createValues["action"] = Config::getSystemConfig()->documents->default_action; } } switch ($this->getParam("type")) { case "page": $document = Document\Page::create($this->getParam("parentId"), $createValues, false); $document->setTitle($this->getParam('title', null)); $document->setProperty("navigation_name", "text", $this->getParam('name', null), false); $document->save(); $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: $classname = "\\Pimcore\\Model\\Document\\" . ucfirst($this->getParam("type")); // this is the fallback for custom document types using prefixes // so we need to check if the class exists first if (!\Pimcore\Tool::classExists($classname)) { $oldStyleClass = "\\Document_" . ucfirst($this->getParam("type")); if (\Pimcore\Tool::classExists($oldStyleClass)) { $classname = $oldStyleClass; } } if (Tool::classExists($classname)) { $document = $classname::create($this->getParam("parentId"), $createValues); try { $document->save(); $success = true; } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } break; } else { \Logger::debug("Unknown document type, can't add [ " . $this->getParam("type") . " ] "); } break; } } else { $errorMessage = "prevented adding a document because document with same path+key [ {$intendedPath} ] already exists"; \Logger::debug($errorMessage); } } else { $errorMessage = "prevented adding a document because of missing permissions"; \Logger::debug($errorMessage); } if ($success) { $this->_helper->json(array("success" => $success, "id" => $document->getId(), "type" => $document->getType())); } else { $this->_helper->json(array("success" => $success, "message" => $errorMessage)); } }
private function createEmailDocuments() { try { $email = Email::getByPath(self::DOCUMENT_EMAIL_CONFIRMATION_PATH); if (!is_object($email)) { $email = new Email(); $email->setParent(Page::getByPath(dirname(self::DOCUMENT_EMAIL_CONFIRMATION_PATH))); $email->setKey(basename(self::DOCUMENT_EMAIL_CONFIRMATION_PATH)); $email->setModule(self::CLASS_PARTICIPATION_NAME); $email->setController('Email'); $email->setAction('confirmation'); $email->setSubject(self::EMAIL_CONFIRMATION_SUBJECT_DEFAULT); $email->save(); } } catch (\Exception $exception) { throw new \Exception('Unable to create email document page [' . Plugin::DOCUMENT_EMAIL_CONFIRMATION_PATH . ']: ' . $exception->getMessage()); } }