log() public static method

public static log ( $message, $level = "info", array $context = [] )
$message
$context array
Beispiel #1
0
 public function saveAction()
 {
     try {
         if ($this->getParam("id")) {
             $link = Document\Hardlink::getById($this->getParam("id"));
             $this->setValuesToDocument($link);
             $link->setModificationDate(time());
             $link->setUserModification($this->getUser()->getId());
             if ($this->getParam("task") == "unpublish") {
                 $link->setPublished(false);
             }
             if ($this->getParam("task") == "publish") {
                 $link->setPublished(true);
             }
             // only save when publish or unpublish
             if ($this->getParam("task") == "publish" && $link->isAllowed("publish") || $this->getParam("task") == "unpublish" && $link->isAllowed("unpublish")) {
                 $link->save();
                 $this->_helper->json(["success" => true]);
             }
         }
     } 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);
 }
 /**
  * This Action listen to server2server communication
  */
 public function paymentReturnServerAction()
 {
     $requestData = $this->parseRequestData();
     $this->disableLayout();
     $this->disableViewAutoRender();
     \Pimcore\Logger::log('OmniPay paymentReturnServer [Postfinance]. TransactionID: ' . $requestData['transaction'] . ', Status: ' . $requestData['status']);
     if ($requestData['status'] === 5) {
         if (!empty($requestData['transaction'])) {
             $cart = \CoreShop\Model\Cart::findByCustomIdentifier($requestData['transaction']);
             if ($cart instanceof \CoreShop\Model\Cart) {
                 \Pimcore\Logger::notice('OmniPay paymentReturnServer [Postfinance]: create order with: ' . $requestData['transaction']);
                 $order = $cart->createOrder(\CoreShop\Model\Order\State::getById(\CoreShop\Model\Configuration::get("SYSTEM.ORDERSTATE.PAYMENT")), $this->getModule(), $cart->getTotal(), $this->view->language);
                 $payments = $order->getPayments();
                 foreach ($payments as $p) {
                     $dataBrick = new \Pimcore\Model\Object\Objectbrick\Data\CoreShopPaymentOmnipay($p);
                     $dataBrick->setTransactionId($requestData['transaction']);
                     $p->save();
                 }
             } else {
                 \Pimcore\Logger::notice('OmniPay paymentReturnServer [Postfinance]: Cart with identifier' . $requestData['transaction'] . 'not found');
             }
         } else {
             \Pimcore\Logger::notice('OmniPay paymentReturnServer [Postfinance]: No valid transaction id given');
         }
     } else {
         \Pimcore\Logger::notice('OmniPay paymentReturnServer [Postfinance]: Error Status: ' . $requestData['status']);
     }
     exit;
 }
Beispiel #3
0
 public function saveAction()
 {
     try {
         if ($this->getParam("id")) {
             $folder = Document\Folder::getById($this->getParam("id"));
             $folder->setModificationDate(time());
             $folder->setUserModification($this->getUser()->getId());
             if ($folder->isAllowed("publish")) {
                 $this->setValuesToDocument($folder);
                 $folder->save();
                 $this->_helper->json(["success" => true]);
             }
         }
     } 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 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);
 }
Beispiel #5
0
 public function saveAction()
 {
     try {
         $object = Object::getById($this->getParam("id"));
         $originalModificationDate = $object->getModificationDate();
         // set the latest available version for editmode
         $object = $this->getLatestVersion($object);
         $object->setUserModification($this->getUser()->getId());
         // data
         if ($this->getParam("data")) {
             $data = \Zend_Json::decode($this->getParam("data"));
             foreach ($data as $key => $value) {
                 $fd = $object->getClass()->getFieldDefinition($key);
                 if ($fd) {
                     if ($fd instanceof Object\ClassDefinition\Data\Localizedfields) {
                         $user = Tool\Admin::getCurrentUser();
                         if (!$user->getAdmin()) {
                             $allowedLanguages = Object\Service::getLanguagePermissions($object, $user, "lEdit");
                             if (!is_null($allowedLanguages)) {
                                 $allowedLanguages = array_keys($allowedLanguages);
                                 $submittedLanguages = array_keys($data[$key]);
                                 foreach ($submittedLanguages as $submittedLanguage) {
                                     if (!in_array($submittedLanguage, $allowedLanguages)) {
                                         unset($value[$submittedLanguage]);
                                     }
                                 }
                             }
                         }
                     }
                     if (method_exists($fd, "isRemoteOwner") and $fd->isRemoteOwner()) {
                         $remoteClass = Object\ClassDefinition::getByName($fd->getOwnerClassName());
                         $relations = $object->getRelationData($fd->getOwnerFieldName(), false, $remoteClass->getId());
                         $toAdd = $this->detectAddedRemoteOwnerRelations($relations, $value);
                         $toDelete = $this->detectDeletedRemoteOwnerRelations($relations, $value);
                         if (count($toAdd) > 0 or count($toDelete) > 0) {
                             $this->processRemoteOwnerRelations($object, $toDelete, $toAdd, $fd->getOwnerFieldName());
                         }
                     } else {
                         $object->setValue($key, $fd->getDataFromEditmode($value, $object));
                     }
                 }
             }
         }
         // general settings
         // @TODO: IS THIS STILL NECESSARY?
         if ($this->getParam("general")) {
             $general = \Zend_Json::decode($this->getParam("general"));
             // do not allow all values to be set, will cause problems (eg. icon)
             if (is_array($general) && count($general) > 0) {
                 foreach ($general as $key => $value) {
                     if (!in_array($key, ["o_id", "o_classId", "o_className", "o_type", "icon", "o_userOwner", "o_userModification"])) {
                         $object->setValue($key, $value);
                     }
                 }
             }
         }
         $object = $this->assignPropertiesFromEditmode($object);
         // 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;
                 }
             }
             $object->setScheduledTasks($tasks);
         }
         if ($this->getParam("task") == "unpublish") {
             $object->setPublished(false);
         }
         if ($this->getParam("task") == "publish") {
             $object->setPublished(true);
         }
         // unpublish and save version is possible without checking mandatory fields
         if ($this->getParam("task") == "unpublish" || $this->getParam("task") == "version") {
             $object->setOmitMandatoryCheck(true);
         }
         if ($this->getParam("task") == "publish" && $object->isAllowed("publish") or $this->getParam("task") == "unpublish" && $object->isAllowed("unpublish")) {
             if ($data) {
                 $this->performFieldcollectionModificationCheck($object, $originalModificationDate, $data);
             }
             $object->save();
             $treeData = $this->getTreeNodeConfig($object);
             $this->_helper->json(["success" => true, "general" => ["o_modificationDate" => $object->getModificationDate()], "treeData" => $treeData]);
         } elseif ($this->getParam("task") == "session") {
             //$object->_fulldump = true; // not working yet, donno why
             Tool\Session::useSession(function ($session) use($object) {
                 $key = "object_" . $object->getId();
                 $session->{$key} = $object;
             }, "pimcore_objects");
             $this->_helper->json(["success" => true]);
         } else {
             if ($object->isAllowed("save")) {
                 $object->saveVersion();
                 $treeData = $this->getTreeNodeConfig($object);
                 $this->_helper->json(["success" => true, "general" => ["o_modificationDate" => $object->getModificationDate()], "treeData" => $treeData]);
             }
         }
     } 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;
     }
 }
Beispiel #6
0
 /**
  *
  * @param string $filterJson
  * @param ClassDefinition $class
  * @return string
  */
 public static function getFilterCondition($filterJson, $class)
 {
     $systemFields = self::getSystemFields();
     // create filter condition
     $conditionPartsFilters = [];
     if ($filterJson) {
         $db = \Pimcore\Db::get();
         $filters = \Zend_Json::decode($filterJson);
         foreach ($filters as $filter) {
             $operator = "=";
             /**
              * @extjs
              */
             $filterField = $filter["field"];
             $filterOperator = $filter["comparison"];
             if (\Pimcore\Tool\Admin::isExtJS6()) {
                 $filterField = $filter["property"];
                 $filterOperator = $filter["operator"];
             }
             if ($filter["type"] == "string") {
                 $operator = "LIKE";
             } elseif ($filter["type"] == "numeric") {
                 if ($filterOperator == "lt") {
                     $operator = "<";
                 } elseif ($filterOperator == "gt") {
                     $operator = ">";
                 } elseif ($filterOperator == "eq") {
                     $operator = "=";
                 }
             } elseif ($filter["type"] == "date") {
                 if ($filterOperator == "lt") {
                     $operator = "<";
                 } elseif ($filterOperator == "gt") {
                     $operator = ">";
                 } elseif ($filterOperator == "eq") {
                     $operator = "=";
                 }
                 $filter["value"] = strtotime($filter["value"]);
             } elseif ($filter["type"] == "list") {
                 $operator = "=";
             } elseif ($filter["type"] == "boolean") {
                 $operator = "=";
                 $filter["value"] = (int) $filter["value"];
             }
             $field = $class->getFieldDefinition($filterField);
             $brickField = null;
             $brickType = null;
             if (!$field) {
                 // if the definition doesn't exist check for a localized field
                 $localized = $class->getFieldDefinition("localizedfields");
                 if ($localized instanceof ClassDefinition\Data\Localizedfields) {
                     $field = $localized->getFieldDefinition($filterField);
                 }
                 //if the definition doesn't exist check for object brick
                 $keyParts = explode("~", $filterField);
                 if (substr($filterField, 0, 1) == "~") {
                     // not needed for now
                     //                            $type = $keyParts[1];
                     //                            $field = $keyParts[2];
                     //                            $keyid = $keyParts[3];
                 } elseif (count($keyParts) > 1) {
                     $brickType = $keyParts[0];
                     $brickKey = $keyParts[1];
                     $key = self::getFieldForBrickType($class, $brickType);
                     $field = $class->getFieldDefinition($key);
                     $brickClass = Objectbrick\Definition::getByKey($brickType);
                     $brickField = $brickClass->getFieldDefinition($brickKey);
                 }
             }
             if ($field instanceof ClassDefinition\Data\Objectbricks) {
                 // custom field
                 $db = \Pimcore\Db::get();
                 if (is_array($filter["value"])) {
                     $fieldConditions = [];
                     foreach ($filter["value"] as $filterValue) {
                         $fieldConditions[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filterValue, $operator);
                     }
                     $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                 } else {
                     $conditionPartsFilters[] = $db->getQuoteIdentifierSymbol() . $brickType . $db->getQuoteIdentifierSymbol() . "." . $brickField->getFilterCondition($filter["value"], $operator);
                 }
             } elseif ($field instanceof ClassDefinition\Data) {
                 // custom field
                 if (is_array($filter["value"])) {
                     $fieldConditions = [];
                     foreach ($filter["value"] as $filterValue) {
                         $fieldConditions[] = $field->getFilterCondition($filterValue, $operator);
                     }
                     $conditionPartsFilters[] = "(" . implode(" OR ", $fieldConditions) . ")";
                 } else {
                     $conditionPartsFilters[] = $field->getFilterCondition($filter["value"], $operator);
                 }
             } elseif (in_array("o_" . $filterField, $systemFields)) {
                 // system field
                 if ($filterField == "fullpath") {
                     $conditionPartsFilters[] = "concat(o_path, o_key) " . $operator . " " . $db->quote("%" . $filter["value"] . "%");
                 } else {
                     if ($filter['type'] == 'date' && $operator == '=') {
                         //if the equal operator is chosen with the date type, condition has to be changed
                         $maxTime = $filter['value'] + (86400 - 1);
                         //specifies the top point of the range used in the condition
                         $conditionPartsFilters[] = "`o_" . $filterField . "` BETWEEN " . $db->quote($filter["value"]) . " AND " . $db->quote($maxTime);
                     } else {
                         $conditionPartsFilters[] = "`o_" . $filterField . "` " . $operator . " " . $db->quote($filter["value"]);
                     }
                 }
             }
         }
     }
     $conditionFilters = "1 = 1";
     if (count($conditionPartsFilters) > 0) {
         $conditionFilters = "(" . implode(" AND ", $conditionPartsFilters) . ")";
     }
     Logger::log("ObjectController filter condition:" . $conditionFilters);
     return $conditionFilters;
 }
Beispiel #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;
     }
 }
Beispiel #8
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);
 }
 public function addAdminTranslationKeysAction()
 {
     $this->removeViewRenderer();
     $keys = $this->getParam("keys");
     if ($keys) {
         $availableLanguages = Tool\Admin::getLanguages();
         $data = \Zend_Json_Decoder::decode($keys);
         foreach ($data as $translationData) {
             $t = null;
             // reset
             try {
                 $t = Translation\Admin::getByKey($translationData);
             } catch (\Exception $e) {
                 Logger::log($e);
             }
             if (!$t instanceof Translation\Admin) {
                 $t = new Translation\Admin();
                 $t->setKey($translationData);
                 $t->setCreationDate(time());
                 $t->setModificationDate(time());
                 foreach ($availableLanguages as $lang) {
                     $t->addTranslation($lang, "");
                 }
                 try {
                     $t->save();
                 } catch (\Exception $e) {
                     Logger::log($e);
                 }
             }
         }
     }
 }