err() public static méthode

public static err ( $m, $context = [] )
Exemple #1
0
 /**
  * Loads a list of entries for the specicifies parameters, returns an array of Search\Backend\Data
  *
  * @return array
  */
 public function load()
 {
     $entries = [];
     $data = $this->db->fetchAll("SELECT * FROM search_backend_data" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($data as $entryData) {
         if ($entryData['maintype'] == 'document') {
             $element = Document::getById($entryData['id']);
         } elseif ($entryData['maintype'] == 'asset') {
             $element = Asset::getById($entryData['id']);
         } elseif ($entryData['maintype'] == 'object') {
             $element = Object::getById($entryData['id']);
         } else {
             Logger::err("unknown maintype ");
         }
         if ($element) {
             $entry = new Search\Backend\Data();
             $entry->setId(new Search\Backend\Data\Id($element));
             $entry->setFullPath($entryData['fullpath']);
             $entry->setType($entryData['type']);
             $entry->setSubtype($entryData['subtype']);
             $entry->setUserOwner($entryData['userowner']);
             $entry->setUserModification($entryData['usermodification']);
             $entry->setCreationDate($entryData['creationdate']);
             $entry->setModificationDate($entryData['modificationdate']);
             $entry->setPublished($entryData['published'] === 0 ? false : true);
             $entries[] = $entry;
         }
     }
     $this->model->setEntries($entries);
     return $entries;
 }
Exemple #2
0
 /**
  * @return void
  */
 protected function update()
 {
     // only do this if the file exists and contains data
     if ($this->getDataChanged() || !$this->getCustomSetting("duration")) {
         try {
             $this->setCustomSetting("duration", $this->getDurationFromBackend());
         } catch (\Exception $e) {
             Logger::err("Unable to get duration of video: " . $this->getId());
         }
     }
     $this->clearThumbnails();
     parent::update();
 }
Exemple #3
0
 /**
  *
  */
 public function mail()
 {
     $conf = Config::getSystemConfig();
     if (!empty($conf->general->logrecipient)) {
         Logger::debug(get_class($this) . ": detected log recipient:" . $conf->general->logrecipient);
         $user = User::getById($conf->general->logrecipient);
         Logger::debug(get_class($this) . ": detected log recipient:" . $user->getEmail());
         if ($user instanceof User && $user->isAdmin()) {
             $email = $user->getEmail();
             Logger::debug(get_class($this) . ": user is valid");
             if (!empty($email)) {
                 if (is_dir(PIMCORE_LOG_MAIL_TEMP)) {
                     Logger::debug(get_class($this) . ": detected mail log dir");
                     Logger::debug(get_class($this) . ": opening dir " . PIMCORE_LOG_MAIL_TEMP);
                     if ($handle = opendir(PIMCORE_LOG_MAIL_TEMP)) {
                         Logger::debug(get_class($this) . ": reading dir " . PIMCORE_LOG_MAIL_TEMP);
                         while (false !== ($file = readdir($handle))) {
                             Logger::debug(get_class($this) . ": detected file " . $file);
                             if (is_file(PIMCORE_LOG_MAIL_TEMP . "/" . $file) and is_writable(PIMCORE_LOG_MAIL_TEMP . "/" . $file)) {
                                 $now = time();
                                 $threshold = 1 * 60 * 15;
                                 $fileModified = filemtime(PIMCORE_LOG_MAIL_TEMP . "/" . $file);
                                 Logger::debug(get_class($this) . ": file is writeable and was last modified: " . $fileModified);
                                 if ($fileModified !== false and $fileModified < $now - $threshold) {
                                     $mail = Tool::getMail([$email], "pimcore log notification - " . $file);
                                     $mail->setIgnoreDebugMode(true);
                                     $mail->setBodyText(file_get_contents(PIMCORE_LOG_MAIL_TEMP . "/" . $file));
                                     $mail->send();
                                     @unlink(PIMCORE_LOG_MAIL_TEMP . "/" . $file);
                                     Logger::debug(get_class($this) . ": sent mail and deleted temp log file " . $file);
                                 } elseif ($fileModified > $now - $threshold) {
                                     Logger::debug(get_class($this) . ": leaving temp log file alone because file [ {$file} ] was written to within the last 15 minutes");
                                 }
                             }
                         }
                     }
                 }
             } else {
                 Logger::err(get_class($this) . ": Cannot send mail to configured log user [" . $user->getName() . "] because email is empty");
             }
         } else {
             Logger::err(get_class($this) . ": Cannot send mail to configured log user. User is either null or not an admin");
         }
     } else {
         Logger::debug(get_class($this) . ": No log recipient configured");
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // clear all data
     $db = \Pimcore\Db::get();
     $db->query("TRUNCATE `search_backend_data`;");
     $elementsPerLoop = 100;
     $types = ["asset", "document", "object"];
     foreach ($types as $type) {
         $listClassName = "\\Pimcore\\Model\\" . ucfirst($type) . "\\Listing";
         $list = new $listClassName();
         if (method_exists($list, "setUnpublished")) {
             $list->setUnpublished(true);
         }
         $elementsTotal = $list->getTotalCount();
         for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) {
             $list->setLimit($elementsPerLoop);
             $list->setOffset($i * $elementsPerLoop);
             $this->output->writeln("Processing " . $type . ": " . ($list->getOffset() + $elementsPerLoop) . "/" . $elementsTotal);
             $elements = $list->load();
             foreach ($elements as $element) {
                 try {
                     $searchEntry = Search\Backend\Data::getForElement($element);
                     if ($searchEntry instanceof Search\Backend\Data and $searchEntry->getId() instanceof Search\Backend\Data\Id) {
                         $searchEntry->setDataFromElement($element);
                     } else {
                         $searchEntry = new Search\Backend\Data($element);
                     }
                     $searchEntry->save();
                 } catch (\Exception $e) {
                     Logger::err($e);
                 }
             }
             \Pimcore::collectGarbage();
         }
     }
     $db->query("OPTIMIZE TABLE search_backend_data;");
 }
Exemple #5
0
 public function copyAction()
 {
     $success = false;
     $message = "";
     $sourceId = intval($this->getParam("sourceId"));
     $source = Object::getById($sourceId);
     $session = Tool\Session::get("pimcore_copy");
     $targetId = intval($this->getParam("targetId"));
     if ($this->getParam("targetParentId")) {
         $sourceParent = Object::getById($this->getParam("sourceParentId"));
         // this is because the key can get the prefix "_copy" if the target does already exists
         if ($session->{$this->getParam("transactionId")}["parentId"]) {
             $targetParent = Object::getById($session->{$this->getParam("transactionId")}["parentId"]);
         } else {
             $targetParent = Object::getById($this->getParam("targetParentId"));
         }
         $targetPath = preg_replace("@^" . $sourceParent->getRealFullPath() . "@", $targetParent . "/", $source->getRealPath());
         $target = Object::getByPath($targetPath);
     } else {
         $target = Object::getById($targetId);
     }
     if ($target->isAllowed("create")) {
         $source = Object::getById($sourceId);
         if ($source != null) {
             try {
                 if ($this->getParam("type") == "child") {
                     $newObject = $this->_objectService->copyAsChild($target, $source);
                     $session->{$this->getParam("transactionId")}["idMapping"][(int) $source->getId()] = (int) $newObject->getId();
                     // this is because the key can get the prefix "_copy" if the target does already exists
                     if ($this->getParam("saveParentId")) {
                         $session->{$this->getParam("transactionId")}["parentId"] = $newObject->getId();
                         Tool\Session::writeClose();
                     }
                 } elseif ($this->getParam("type") == "replace") {
                     $this->_objectService->copyContents($target, $source);
                 }
                 $success = true;
             } catch (\Exception $e) {
                 Logger::err($e);
                 $success = false;
                 $message = $e->getMessage() . " in object " . $source->getRealFullPath() . " [id: " . $source->getId() . "]";
             }
         } else {
             Logger::error("could not execute copy/paste, source object with id [ {$sourceId} ] not found");
             $this->_helper->json(["success" => false, "message" => "source object not found"]);
         }
     } else {
         Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]");
         $this->_helper->json(["error" => false, "message" => "missing_permission"]);
     }
     $this->_helper->json(["success" => $success, "message" => $message]);
 }
Exemple #6
0
 /**
  * check if autogenerated views (eg. localized fields, ...) are still valid, if not, they're removed
  * @static
  */
 public static function cleanupBrokenViews()
 {
     $db = self::get();
     $tables = $db->fetchAll("SHOW FULL TABLES");
     foreach ($tables as $table) {
         reset($table);
         $name = current($table);
         $type = next($table);
         if ($type == "VIEW") {
             try {
                 $createStatement = $db->fetchRow("SHOW FIELDS FROM " . $name);
             } catch (\Exception $e) {
                 if (strpos($e->getMessage(), "references invalid table") !== false) {
                     \Logger::err("view " . $name . " seems to be a broken one, it will be removed");
                     \Logger::err("error message was: " . $e->getMessage());
                     $db->query("DROP VIEW " . $name);
                 } else {
                     \Logger::error($e);
                 }
             }
         }
     }
 }
Exemple #7
0
 public function saveAction()
 {
     try {
         $success = false;
         if ($this->getParam("id")) {
             $asset = Asset::getById($this->getParam("id"));
             if ($asset->isAllowed("publish")) {
                 // metadata
                 if ($this->getParam("metadata")) {
                     $metadata = \Zend_Json::decode($this->getParam("metadata"));
                     $metadata = Asset\Service::minimizeMetadata($metadata);
                     $asset->setMetadata($metadata);
                 }
                 // properties
                 if ($this->getParam("properties")) {
                     $properties = [];
                     $propertiesData = \Zend_Json::decode($this->getParam("properties"));
                     if (is_array($propertiesData)) {
                         foreach ($propertiesData as $propertyName => $propertyData) {
                             $value = $propertyData["data"];
                             try {
                                 $property = new Model\Property();
                                 $property->setType($propertyData["type"]);
                                 $property->setName($propertyName);
                                 $property->setCtype("asset");
                                 $property->setDataFromEditmode($value);
                                 $property->setInheritable($propertyData["inheritable"]);
                                 $properties[$propertyName] = $property;
                             } catch (\Exception $e) {
                                 Logger::err("Can't add " . $propertyName . " to asset " . $asset->getRealFullPath());
                             }
                         }
                         $asset->setProperties($properties);
                     }
                 }
                 // scheduled tasks
                 if ($this->getParam("scheduler")) {
                     $tasks = [];
                     $tasksData = \Zend_Json::decode($this->getParam("scheduler"));
                     if (!empty($tasksData)) {
                         foreach ($tasksData as $taskData) {
                             $taskData["date"] = strtotime($taskData["date"] . " " . $taskData["time"]);
                             $task = new Model\Schedule\Task($taskData);
                             $tasks[] = $task;
                         }
                     }
                     $asset->setScheduledTasks($tasks);
                 }
                 if ($this->hasParam("data")) {
                     $asset->setData($this->getParam("data"));
                 }
                 $asset->setUserModification($this->getUser()->getId());
                 try {
                     $asset->save();
                     $asset->getData();
                     $success = true;
                 } catch (\Exception $e) {
                     if (Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
                         throw $e;
                     }
                     $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                 }
             } else {
                 Logger::debug("prevented save asset because of missing permissions ");
             }
             $this->_helper->json(["success" => $success]);
         }
         $this->_helper->json(false);
     } catch (\Exception $e) {
         Logger::log($e);
         if (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;
     }
 }
 public function searchAction()
 {
     if ($this->getParam("q")) {
         try {
             $page = $this->getParam('page');
             if (empty($page)) {
                 $page = 1;
             }
             $perPage = 10;
             $result = \Pimcore\Google\Cse::search($this->getParam("q"), ($page - 1) * $perPage, null, ["cx" => "002859715628130885299:baocppu9mii"], $this->getParam("facet"));
             $paginator = \Zend_Paginator::factory($result);
             $paginator->setCurrentPageNumber($page);
             $paginator->setItemCountPerPage($perPage);
             $this->view->paginator = $paginator;
             $this->view->result = $result;
         } catch (\Exception $e) {
             // something went wrong: eg. limit exceeded, wrong configuration, ...
             \Pimcore\Logger::err($e);
             echo $e->getMessage();
             exit;
         }
     }
 }
Exemple #9
0
 public function saveAction()
 {
     try {
         if ($this->getParam("id")) {
             $page = Document\Page::getById($this->getParam("id"));
             // check if there's a document in session which should be used as data-source
             // see also self::clearEditableDataAction() | this is necessary to reset all fields and to get rid of
             // outdated and unused data elements in this document (eg. entries of area-blocks)
             $pageSession = Session::useSession(function ($session) use($page) {
                 if (isset($session->{"document_" . $page->getId()}) && isset($session->{"document_" . $page->getId() . "_useForSave"})) {
                     if ($session->{"document_" . $page->getId() . "_useForSave"}) {
                         // only use the page from the session once
                         unset($session->{"document_" . $page->getId() . "_useForSave"});
                         return $session->{"document_" . $page->getId()};
                     }
                 }
                 return null;
             }, "pimcore_documents");
             if ($pageSession) {
                 $page = $pageSession;
             } else {
                 $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);
             }
             $settings = [];
             if ($this->getParam("settings")) {
                 $settings = \Zend_Json::decode($this->getParam("settings"));
             }
             // check for redirects
             if ($this->getUser()->isAllowed("redirects") && $this->getParam("settings")) {
                 if (is_array($settings)) {
                     $redirectList = new Redirect\Listing();
                     $redirectList->setCondition("target = ?", $page->getId());
                     $existingRedirects = $redirectList->load();
                     $existingRedirectIds = [];
                     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();
                     }
                 }
             }
             // check if settings exist, before saving meta data
             if ($this->getParam("settings") && is_array($settings)) {
                 $metaData = [];
                 for ($i = 1; $i < 30; $i++) {
                     if (array_key_exists("metadata_" . $i, $settings)) {
                         $metaData[] = $settings["metadata_" . $i];
                     }
                 }
                 $page->setMetaData($metaData);
             }
             // 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) {
                     if (\Pimcore\Tool\Admin::isExtJS6() && $e instanceof Element\ValidationException) {
                         throw $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) {
                         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);
 }
Exemple #10
0
 /**
  * @param $documentId
  * @throws \Exception
  */
 public function startPdfGeneration($documentId)
 {
     $jobConfigFile = $this->loadJobConfigObject($documentId);
     $document = $this->getPrintDocument($documentId);
     // check if there is already a generating process running, wait if so ...
     Model\Tool\Lock::acquire($document->getLockKey(), 0);
     try {
         \Pimcore::getEventManager()->trigger("document.print.prePdfGeneration", $document, ["processor" => $this]);
         $pdf = $this->buildPdf($document, $jobConfigFile->config);
         file_put_contents($document->getPdfFileName(), $pdf);
         \Pimcore::getEventManager()->trigger("document.print.postPdfGeneration", $document, ["filename" => $document->getPdfFileName(), "pdf" => $pdf]);
         $creationDate = \Zend_Date::now();
         $document->setLastGenerated($creationDate->get() + 1);
         $document->save();
     } catch (\Exception $e) {
         $document->save();
         Logger::err($e);
     }
     Model\Tool\Lock::release($document->getLockKey());
     Model\Tool\TmpStore::delete($document->getLockKey());
     @unlink($this->getJobConfigFile($documentId));
 }
 public function deleteInfoAction()
 {
     $hasDependency = false;
     try {
         $document = Document::getById($this->getParam("id"));
         $hasDependency = $document->getDependencies()->isRequired();
     } catch (\Exception $e) {
         Logger::err("failed to access document with id: " . $this->getParam("id"));
     }
     $deleteJobs = [];
     // check for childs
     if ($document instanceof Document) {
         $deleteJobs[] = [["url" => "/admin/recyclebin/add", "params" => ["type" => "document", "id" => $document->getId()]]];
         $hasChilds = $document->hasChilds();
         if (!$hasDependency) {
             $hasDependency = $hasChilds;
         }
         $childs = 0;
         if ($hasChilds) {
             // get amount of childs
             $list = new Document\Listing();
             $list->setCondition("path LIKE '" . $document->getRealFullPath() . "/%'");
             $childs = $list->getTotalCount();
             if ($childs > 0) {
                 $deleteObjectsPerRequest = 5;
                 for ($i = 0; $i < ceil($childs / $deleteObjectsPerRequest); $i++) {
                     $deleteJobs[] = [["url" => "/admin/document/delete", "params" => ["step" => $i, "amount" => $deleteObjectsPerRequest, "type" => "childs", "id" => $document->getId()]]];
                 }
             }
         }
         // the object itself is the last one
         $deleteJobs[] = [["url" => "/admin/document/delete", "params" => ["id" => $document->getId()]]];
     }
     // get the element key
     $elementKey = $document->getKey();
     $this->_helper->json(["hasDependencies" => $hasDependency, "childs" => $childs, "deletejobs" => $deleteJobs, "elementKey" => $elementKey]);
 }
Exemple #12
0
 /**
  *
  */
 public function content()
 {
     // create info object and assign it to the view
     $info = new Area\Info();
     try {
         $info->setTag($this);
         $info->setName($this->getName());
         $info->setId($this->currentIndex["type"]);
         $info->setIndex($this->current);
         $info->setPath(str_replace(PIMCORE_DOCUMENT_ROOT, "", $this->getPathForBrick($this->currentIndex["type"])));
         $info->setConfig($this->getBrickConfig($this->currentIndex["type"]));
     } catch (\Exception $e) {
         Logger::err($e);
     }
     if ($this->getView() instanceof \Zend_View) {
         $this->getView()->brick = $info;
         $areas = $this->getAreaDirs();
         $view = $areas[$this->currentIndex["type"]] . "/view.php";
         $action = $areas[$this->currentIndex["type"]] . "/action.php";
         $edit = $areas[$this->currentIndex["type"]] . "/edit.php";
         $options = $this->getOptions();
         $params = [];
         if (isset($options["params"]) && is_array($options["params"]) && array_key_exists($this->currentIndex["type"], $options["params"])) {
             if (is_array($options["params"][$this->currentIndex["type"]])) {
                 $params = $options["params"][$this->currentIndex["type"]];
             }
         }
         // assign parameters to view
         foreach ($params as $key => $value) {
             $this->getView()->assign($key, $value);
         }
         // check for action file
         $actionObject = null;
         if (is_file($action)) {
             include_once $action;
             $actionClassFound = true;
             $actionClass = preg_replace_callback("/[\\-_][a-z]/", function ($matches) {
                 $replacement = str_replace(["-", "_"], "", $matches[0]);
                 return strtoupper($replacement);
             }, ucfirst($this->currentIndex["type"]));
             $actionClassname = "\\Pimcore\\Model\\Document\\Tag\\Area\\" . $actionClass;
             if (!class_exists($actionClassname, false)) {
                 // also check the legacy prefixed class name, as this is used by some plugins
                 $actionClassname = "\\Document_Tag_Area_" . ucfirst($this->currentIndex["type"]);
                 if (!class_exists($actionClassname, false)) {
                     $actionClassFound = false;
                 }
             }
             if ($actionClassFound) {
                 $actionObject = new $actionClassname();
                 if ($actionObject instanceof Area\AbstractArea) {
                     $actionObject->setView($this->getView());
                     $areaConfig = new \Zend_Config_Xml($areas[$this->currentIndex["type"]] . "/area.xml");
                     $actionObject->setConfig($areaConfig);
                     // params
                     $params = array_merge($this->view->getAllParams(), $params);
                     $actionObject->setParams($params);
                     if ($info) {
                         $actionObject->setBrick($info);
                     }
                     if (method_exists($actionObject, "action")) {
                         $actionObject->action();
                     }
                     $this->getView()->assign('actionObject', $actionObject);
                 }
             } else {
                 $this->getView()->assign('actionObject', null);
             }
         }
         if (is_file($view)) {
             $editmode = $this->getView()->editmode;
             if ($actionObject && method_exists($actionObject, "getBrickHtmlTagOpen")) {
                 echo $actionObject->getBrickHtmlTagOpen($this);
             } else {
                 echo '<div class="pimcore_area_' . $this->currentIndex["type"] . ' pimcore_area_content">';
             }
             if (is_file($edit) && $editmode) {
                 echo '<div class="pimcore_area_edit_button_' . $this->getName() . ' pimcore_area_edit_button"></div>';
                 // forces the editmode in view.php independent if there's an edit.php or not
                 if (!array_key_exists("forceEditInView", $params) || !$params["forceEditInView"]) {
                     $this->getView()->editmode = false;
                 }
             }
             $this->getView()->template($view);
             if (is_file($edit) && $editmode) {
                 $this->getView()->editmode = true;
                 echo '<div class="pimcore_area_editmode_' . $this->getName() . ' pimcore_area_editmode pimcore_area_editmode_hidden">';
                 $this->getView()->template($edit);
                 echo '</div>';
             }
             if ($actionObject && method_exists($actionObject, "getBrickHtmlTagClose")) {
                 echo $actionObject->getBrickHtmlTagClose($this);
             } else {
                 echo '</div>';
             }
             if ($actionObject && method_exists($actionObject, "postRenderAction")) {
                 $actionObject->postRenderAction();
             }
         }
     }
     $this->current++;
 }
Exemple #13
0
 /**
  * Replaces the placeholders with the content and returns
  * the rendered text if a text was set with "$mail->setBodyText()"     *
  * @return string
  */
 public function getBodyTextRendered()
 {
     $text = $this->getBodyText();
     //if the content was manually set with $obj->setBodyText(); this content will be used
     if ($text instanceof \Zend_Mime_Part) {
         $rawText = $text->getRawContent();
         $content = $this->placeholderObject->replacePlaceholders($rawText, $this->getParams(), $this->getDocument(), $this->getEnableLayoutOnPlaceholderRendering());
     } else {
         //creating text version from html email if html2text is installed
         try {
             include_once "simple_html_dom.php";
             $htmlContent = $this->getBodyHtmlRendered();
             $html = str_get_html($htmlContent);
             if ($html) {
                 $body = $html->find("body", 0);
                 if ($body) {
                     $style = $body->find("style", 0);
                     if ($style) {
                         $style->clear();
                     }
                     $htmlContent = $body->innertext;
                 }
                 $html->clear();
                 unset($html);
             }
             $content = $this->html2Text($htmlContent);
         } catch (\Exception $e) {
             \Logger::err($e);
             $content = "";
         }
     }
     return $content;
 }
 public function saveAction()
 {
     try {
         if ($this->getParam("id")) {
             $page = Document\Newsletter::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);
 }
Exemple #15
0
 /**
  *
  */
 public static function updateMaxmindDb()
 {
     $downloadUrl = "http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz";
     $geoDbFile = PIMCORE_CONFIGURATION_DIRECTORY . "/GeoLite2-City.mmdb";
     $geoDbFileGz = $geoDbFile . ".gz";
     $firstTuesdayOfMonth = strtotime(date("F") . " 2013 tuesday");
     $filemtime = 0;
     if (file_exists($geoDbFile)) {
         $filemtime = filemtime($geoDbFile);
     }
     // update if file is older than 30 days, or if it is the first tuesday of the month
     if ($filemtime < time() - 30 * 86400 || date("m/d/Y") == date("m/d/Y", $firstTuesdayOfMonth) && $filemtime < time() - 86400) {
         $data = Tool::getHttpData($downloadUrl);
         if (strlen($data) > 1000000) {
             File::put($geoDbFileGz, $data);
             @unlink($geoDbFile);
             $sfp = gzopen($geoDbFileGz, "rb");
             $fp = fopen($geoDbFile, "w");
             while ($string = gzread($sfp, 4096)) {
                 fwrite($fp, $string, strlen($string));
             }
             gzclose($sfp);
             fclose($fp);
             unlink($geoDbFileGz);
             \Logger::info("Updated MaxMind GeoIP2 Database in: " . $geoDbFile);
         } else {
             \Logger::err("Failed to update MaxMind GeoIP2, size is under about 1M");
         }
     } else {
         \Logger::debug("MayMind GeoIP2 Download skipped, everything up to date, last update: " . date("m/d/Y H:i", $filemtime));
     }
 }
Exemple #16
0
 /**
  * @param $permission
  * @throws \Exception
  */
 protected function checkPermission($permission)
 {
     if (!$this->getUser() || !$this->getUser()->isAllowed($permission)) {
         $message = "attempt to access " . $permission . ", but has no permission to do so.";
         Logger::err($message);
         throw new \Exception($message);
     }
 }
Exemple #17
0
 public function saveAction()
 {
     if ($this->getParam("id")) {
         $page = Document\Printpage::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);
         }
         // only save when publish or unpublish
         if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) {
             //check, if to cleanup existing elements of document
             $config = Config::getWeb2PrintConfig();
             if ($config->generalDocumentSaveMode == "cleanup") {
                 $page->setElements([]);
             }
             $this->setValuesToDocument($page);
             try {
                 $page->save();
                 $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->_helper->json(["success" => true]);
                 } catch (\Exception $e) {
                     Logger::err($e);
                     $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
                 }
             }
         }
     }
     $this->_helper->json(false);
 }
Exemple #18
0
 /**
  * @param null $imagePath
  * @return bool
  */
 public function isVectorGraphic($imagePath = null)
 {
     if (!$imagePath) {
         $imagePath = $this->imagePath;
     }
     // we need to do this check first, because ImageMagick using the inkscape delegate returns "PNG" when calling
     // getimageformat() onto SVG graphics, this is a workaround to avoid problems
     if (preg_match("@\\.(svgz?|eps|pdf|ps|ai|indd)\$@", $imagePath)) {
         return true;
     }
     try {
         if ($this->resource) {
             $type = $this->resource->getimageformat();
             $vectorTypes = ["EPT", "EPDF", "EPI", "EPS", "EPS2", "EPS3", "EPSF", "EPSI", "EPT", "PDF", "PFA", "PFB", "PFM", "PS", "PS2", "PS3", "SVG", "SVGZ", "MVG"];
             if (in_array(strtoupper($type), $vectorTypes)) {
                 return true;
             }
         }
     } catch (\Exception $e) {
         Logger::err($e);
     }
     return false;
 }
Exemple #19
0
 public function uploadAction()
 {
     $success = true;
     $tmpId = uniqid();
     $zipPath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/plugin-" . $tmpId . ".zip";
     $tempPath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/plugin-" . $tmpId;
     mkdir($tempPath);
     copy($_FILES["zip"]["tmp_name"], $zipPath);
     $zip = new ZipArchive();
     if ($zip->open($zipPath) === true) {
         $zip->extractTo($tempPath);
         $zip->close();
     } else {
         $success = false;
     }
     unlink($zipPath);
     // look for the plugin.xml
     $rootDir = null;
     $pluginName = null;
     $files = rscandir($tempPath);
     foreach ($files as $file) {
         if (preg_match("@[\\\\/]plugin\\.xml\$@", $file)) {
             $rootDir = dirname($file);
             $pluginConfig = new \Zend_Config_Xml($file);
             if ($pluginConfig->plugin->pluginName) {
                 $pluginName = $pluginConfig->plugin->pluginName;
             } else {
                 Logger::error("Unable to find 'pluginName' in " . $file);
             }
             break;
         }
     }
     if ($rootDir && $pluginName) {
         $pluginPath = PIMCORE_PLUGINS_PATH . "/" . $pluginName;
         // check for existing plugin
         if (is_dir($pluginPath)) {
             // move it to the backup directory
             rename($pluginPath, PIMCORE_BACKUP_DIRECTORY . "/" . $pluginName . "-" . time());
         }
         rename($rootDir, $pluginPath);
     } else {
         $success = false;
         Logger::err("No plugin.xml or plugin name found for uploaded plugin");
     }
     $this->_helper->json(["success" => $success], false);
     // set content-type to text/html, otherwise (when application/json is sent) chrome will complain in
     // Ext.form.Action.Submit and mark the submission as failed
     $this->getResponse()->setHeader("Content-Type", "text/html");
 }
Exemple #20
0
 /**
  *
  */
 public static function execute()
 {
     $list = new Listing();
     $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.");
                         }
                     } elseif ($task->getAction() == "publish") {
                         $document->setPublished(true);
                         $document->save();
                     } elseif ($task->getAction() == "unpublish") {
                         $document->setPublished(false);
                         $document->save();
                     } elseif ($task->getAction() == "delete") {
                         $document->delete();
                     }
                 }
             } elseif ($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.");
                         }
                     } elseif ($task->getAction() == "delete") {
                         $asset->delete();
                     }
                 }
             } elseif ($task->getCtype() == "object") {
                 $object = Object::getById($task->getCid());
                 if ($object instanceof Object) {
                     if ($task->getAction() == "publish-version" && $task->getVersion()) {
                         try {
                             $version = Version::getById($task->getVersion());
                             $object = $version->getData();
                             if ($object instanceof Object\AbstractObject) {
                                 $object->setPublished(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.");
                         }
                     } elseif ($task->getAction() == "publish") {
                         $object->setPublished(true);
                         $object->save();
                     } elseif ($task->getAction() == "unpublish") {
                         $object->setPublished(false);
                         $object->save();
                     } elseif ($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);
         }
     }
 }
Exemple #21
0
 /**
  * Object
  *
  * @return mixed
  */
 public function loadData()
 {
     $data = null;
     $zipped = false;
     // check both the legacy file path and the new structure
     foreach ([$this->getFilePath(), $this->getLegacyFilePath()] as $path) {
         if (file_exists($path)) {
             $filePath = $path;
             break;
         }
         if (file_exists($path . ".gz")) {
             $filePath = $path . ".gz";
             $zipped = true;
             break;
         }
     }
     if ($zipped && is_file($filePath) && is_readable($filePath)) {
         $data = gzdecode(file_get_contents($filePath));
     } elseif (is_file($filePath) && is_readable($filePath)) {
         $data = file_get_contents($filePath);
     }
     if (!$data) {
         Logger::err("Version: cannot read version data from file system.");
         $this->delete();
         return;
     }
     if ($this->getSerialized()) {
         $data = Serialize::unserialize($data);
     }
     if ($data instanceof Asset && file_exists($this->getBinaryFilePath())) {
         $binaryHandle = fopen($this->getBinaryFilePath(), "r+", false, File::getContext());
         $data->setStream($binaryHandle);
     } elseif ($data instanceof Asset && $data->data) {
         // this is for backward compatibility
         $data->setData($data->data);
     }
     $data = Element\Service::renewReferences($data);
     $this->setData($data);
     return $data;
 }
Exemple #22
0
 /**
  * @param $step
  * @return array
  * @throws \Exception
  */
 public function fileStep($step)
 {
     $filesContainer = $this->getFilesToBackup();
     $files = $filesContainer[$step];
     $excludePatterns = array(PIMCORE_FRONTEND_MODULE . "/var/backup/.*", PIMCORE_FRONTEND_MODULE . "/var/cache/.*", PIMCORE_FRONTEND_MODULE . "/var/log/.*", PIMCORE_FRONTEND_MODULE . "/var/system/.*", PIMCORE_FRONTEND_MODULE . "/var/tmp/.*", PIMCORE_FRONTEND_MODULE . "/var/webdav/.*");
     if (!empty($this->additionalExcludePatterns) && is_array($this->additionalExcludePatterns)) {
         $excludePatterns = array_merge($excludePatterns, $this->additionalExcludePatterns);
     }
     foreach ($excludePatterns as &$excludePattern) {
         $excludePattern = "@" . $excludePattern . "@";
     }
     clearstatcache();
     foreach ($files as $file) {
         if ($file) {
             if (file_exists($file) && is_readable($file)) {
                 $exclude = false;
                 $relPath = str_replace(PIMCORE_DOCUMENT_ROOT, "", $file);
                 $relPath = str_replace(DIRECTORY_SEPARATOR, "/", $relPath);
                 // windows compatibility
                 foreach ($excludePatterns as $pattern) {
                     if (preg_match($pattern, $relPath)) {
                         $exclude = true;
                     }
                 }
                 if (!$exclude && is_file($file)) {
                     $this->getArchive()->addFile($file, ltrim($relPath, "/"));
                 } else {
                     \Logger::info("Backup: Excluded: " . $file);
                 }
             } else {
                 \Logger::err("Backup: Can't read file: " . $file);
             }
         }
     }
     $this->setFileAmount($this->getFileAmount() + count($files));
     return array("success" => true, "filesize" => $this->getFormattedFilesize(), "fileAmount" => $this->getFileAmount());
 }
 public function batchAction()
 {
     $success = true;
     try {
         $object = Object::getById($this->getParam("job"));
         if ($object) {
             $className = $object->getClassName();
             $class = Object\ClassDefinition::getByName($className);
             $value = $this->getParam("value");
             if ($this->getParam("valueType") == "object") {
                 $value = \Zend_Json::decode($value);
             }
             $name = $this->getParam("name");
             $parts = explode("~", $name);
             if (substr($name, 0, 1) == "~") {
                 $type = $parts[1];
                 $field = $parts[2];
                 $keyid = $parts[3];
                 $getter = "get" . ucfirst($field);
                 $setter = "set" . ucfirst($field);
                 $keyValuePairs = $object->{$getter}();
                 if (!$keyValuePairs) {
                     $keyValuePairs = new Object\Data\KeyValue();
                     $keyValuePairs->setObjectId($object->getId());
                     $keyValuePairs->setClass($object->getClass());
                 }
                 $keyValuePairs->setPropertyWithId($keyid, $value, true);
                 $object->{$setter}($keyValuePairs);
             } elseif (count($parts) > 1) {
                 // check for bricks
                 $brickType = $parts[0];
                 $brickKey = $parts[1];
                 $brickField = Object\Service::getFieldForBrickType($object->getClass(), $brickType);
                 $fieldGetter = "get" . ucfirst($brickField);
                 $brickGetter = "get" . ucfirst($brickType);
                 $valueSetter = "set" . ucfirst($brickKey);
                 $brick = $object->{$fieldGetter}()->{$brickGetter}();
                 if (empty($brick)) {
                     $classname = "\\Pimcore\\Model\\Object\\Objectbrick\\Data\\" . ucfirst($brickType);
                     $brickSetter = "set" . ucfirst($brickType);
                     $brick = new $classname($object);
                     $object->{$fieldGetter}()->{$brickSetter}($brick);
                 }
                 $brickClass = Object\Objectbrick\Definition::getByKey($brickType);
                 $field = $brickClass->getFieldDefinition($brickKey);
                 $brick->{$valueSetter}($field->getDataFromEditmode($value, $object));
             } else {
                 // everything else
                 $field = $class->getFieldDefinition($name);
                 if ($field) {
                     $object->setValue($name, $field->getDataFromEditmode($value, $object));
                 } else {
                     // check if it is a localized field
                     if ($this->getParam("language")) {
                         $localizedField = $class->getFieldDefinition("localizedfields");
                         if ($localizedField) {
                             $field = $localizedField->getFieldDefinition($name);
                             if ($field) {
                                 /** @var $field Pimcore\Model\Object\ClassDefinition\Data */
                                 $object->{"set" . $name}($field->getDataFromEditmode($value, $object), $this->getParam("language"));
                             }
                         }
                     }
                     // seems to be a system field, this is actually only possible for the "published" field yet
                     if ($name == "published") {
                         if ($value == "false" || empty($value)) {
                             $object->setPublished(false);
                         } else {
                             $object->setPublished(true);
                         }
                     }
                 }
             }
             try {
                 // don't check for mandatory fields here
                 $object->setOmitMandatoryCheck(true);
                 $object->setUserModification($this->getUser()->getId());
                 $object->save();
                 $success = true;
             } catch (\Exception $e) {
                 $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
             }
         } else {
             Logger::debug("ObjectController::batchAction => There is no object left to update.");
             $this->_helper->json(["success" => false, "message" => "ObjectController::batchAction => There is no object left to update."]);
         }
     } catch (\Exception $e) {
         Logger::err($e);
         $this->_helper->json(["success" => false, "message" => $e->getMessage()]);
     }
     $this->_helper->json(["success" => $success]);
 }