public function subscribeAction()
 {
     $this->enableLayout();
     $newsletter = new Newsletter("person");
     // replace "crm" with the class name you have used for your class above (mailing list)
     $params = $this->getAllParams();
     $this->view->success = false;
     if ($newsletter->checkParams($params)) {
         try {
             $params["parentId"] = 1;
             // default folder (home) where we want to save our subscribers
             $newsletterFolder = Model\Object::getByPath("/crm/newsletter");
             if ($newsletterFolder) {
                 $params["parentId"] = $newsletterFolder->getId();
             }
             $user = $newsletter->subscribe($params);
             // user and email document
             // parameters available in the email: gender, firstname, lastname, email, token, object
             // ==> see mailing framework
             $newsletter->sendConfirmationMail($user, Model\Document::getByPath("/en/advanced-examples/newsletter/confirmation-email"), ["additional" => "parameters"]);
             // do some other stuff with the new user
             $user->setDateRegister(new \DateTime());
             $user->save();
             $this->view->success = true;
         } catch (\Exception $e) {
             echo $e->getMessage();
         }
     }
 }
Beispiel #2
0
 /**
  * @param $importValue
  * @return mixed|null|Asset|Document|Element\ElementInterface
  */
 public function getFromCsvImport($importValue)
 {
     $value = null;
     $values = explode(":", $importValue);
     if (count($values) == 2) {
         $type = $values[0];
         $path = $values[1];
         $value = Element\Service::getElementByPath($type, $path);
     } else {
         //fallback for old export files
         if ($el = Asset::getByPath($importValue)) {
             $value = $el;
         } else {
             if ($el = Document::getByPath($importValue)) {
                 $value = $el;
             } else {
                 if ($el = Object::getByPath($importValue)) {
                     $value = $el;
                 }
             }
         }
     }
     return $value;
 }
 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->getFullPath() . "@", $targetParent . "/", $source->getPath());
         $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->getFullPath() . " [id: " . $source->getId() . "]";
             }
         } else {
             \Logger::error("could not execute copy/paste, source object with id [ {$sourceId} ] not found");
             $this->_helper->json(array("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(array("error" => false, "message" => "missing_permission"));
     }
     $this->_helper->json(array("success" => $success, "message" => $message));
 }
Beispiel #4
0
 /**
  * @param $importValue
  * @return array|mixed
  */
 public function getFromCsvImport($importValue)
 {
     $values = explode(",", $importValue);
     $value = array();
     foreach ($values as $element) {
         if ($el = Object::getByPath($element)) {
             $value[] = $el;
         }
     }
     return $value;
 }
Beispiel #5
0
 /**
  * @param $importValue
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @return array|mixed
  */
 public function getFromCsvImport($importValue, $object = null, $params = [])
 {
     $values = explode(",", $importValue);
     $value = [];
     foreach ($values as $element) {
         if ($el = Object::getByPath($element)) {
             $value[] = $el;
         }
     }
     return $value;
 }
 /**
  * @param $importValue
  * @return array|mixed
  */
 public function getFromCsvImport($importValue)
 {
     $values = explode(",", $importValue);
     $value = array();
     foreach ($values as $element) {
         if ($el = Object::getByPath($element)) {
             $className = Tool::getModelClassMapping('\\Pimcore\\Model\\Object\\Data\\ObjectMetadata');
             $metaObject = new $className($this->getName(), $this->getColumnKeys(), $el);
             $value[] = $metaObject;
         }
     }
     return $value;
 }
 public function importProcessAction()
 {
     $success = true;
     $parentId = $this->getParam("parentId");
     $job = $this->getParam("job");
     $id = $this->getParam("id");
     $mappingRaw = \Zend_Json::decode($this->getParam("mapping"));
     $class = Object\ClassDefinition::getById($this->getParam("classId"));
     $skipFirstRow = $this->getParam("skipHeadRow") == "true";
     $fields = $class->getFieldDefinitions();
     $file = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id;
     // currently only csv supported
     // determine type
     $dialect = Tool\Admin::determineCsvDialect(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/import_" . $id . "_original");
     $count = 0;
     if (($handle = fopen($file, "r")) !== false) {
         $data = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
     }
     if ($skipFirstRow && $job == 1) {
         //read the next row, we need to skip the head row
         $data = fgetcsv($handle, 0, $dialect->delimiter, $dialect->quotechar, $dialect->escapechar);
     }
     $tmpFile = $file . "_tmp";
     $tmpHandle = fopen($tmpFile, "w+");
     while (!feof($handle)) {
         $buffer = fgets($handle);
         fwrite($tmpHandle, $buffer);
     }
     fclose($handle);
     fclose($tmpHandle);
     unlink($file);
     rename($tmpFile, $file);
     // prepare mapping
     foreach ($mappingRaw as $map) {
         if ($map[0] !== "" && $map[1] && !empty($map[2])) {
             $mapping[$map[2]] = $map[0];
         } else {
             if ($map[1] == "published (system)") {
                 $mapping["published"] = $map[0];
             } else {
                 if ($map[1] == "type (system)") {
                     $mapping["type"] = $map[0];
                 }
             }
         }
     }
     // create new object
     $className = "\\Pimcore\\Model\\Object\\" . ucfirst($this->getParam("className"));
     $className = Tool::getModelClassMapping($className);
     $parent = Object::getById($this->getParam("parentId"));
     $objectKey = "object_" . $job;
     if ($this->getParam("filename") == "id") {
         $objectKey = null;
     } else {
         if ($this->getParam("filename") != "default") {
             $objectKey = File::getValidFilename($data[$this->getParam("filename")]);
         }
     }
     $overwrite = false;
     if ($this->getParam("overwrite") == "true") {
         $overwrite = true;
     }
     if ($parent->isAllowed("create")) {
         $intendedPath = $parent->getFullPath() . "/" . $objectKey;
         if ($overwrite) {
             $object = Object::getByPath($intendedPath);
             if (!$object instanceof Object\Concrete) {
                 //create new object
                 $object = new $className();
             } else {
                 if ($object instanceof Object\Concrete and !$object instanceof $className) {
                     //delete the old object it is of a different class
                     $object->delete();
                     $object = new $className();
                 } else {
                     if ($object instanceof Object\Folder) {
                         //delete the folder
                         $object->delete();
                         $object = new $className();
                     } else {
                         //use the existing object
                     }
                 }
             }
         } else {
             $counter = 1;
             while (Object::getByPath($intendedPath) != null) {
                 $objectKey .= "_" . $counter;
                 $intendedPath = $parent->getFullPath() . "/" . $objectKey;
                 $counter++;
             }
             $object = new $className();
         }
         $object->setClassId($this->getParam("classId"));
         $object->setClassName($this->getParam("className"));
         $object->setParentId($this->getParam("parentId"));
         $object->setKey($objectKey);
         $object->setCreationDate(time());
         $object->setUserOwner($this->getUser()->getId());
         $object->setUserModification($this->getUser()->getId());
         if (in_array($data[$mapping["type"]], ["object", "variant"])) {
             $object->setType($data[$mapping["type"]]);
         } else {
             $object->setType("object");
         }
         if ($data[$mapping["published"]] === "1") {
             $object->setPublished(true);
         } else {
             $object->setPublished(false);
         }
         foreach ($class->getFieldDefinitions() as $key => $field) {
             $value = $data[$mapping[$key]];
             if (array_key_exists($key, $mapping) and $value != null) {
                 // data mapping
                 $value = $field->getFromCsvImport($value);
                 if ($value !== null) {
                     $object->setValue($key, $value);
                 }
             }
         }
         try {
             $object->save();
             $this->_helper->json(array("success" => true));
         } catch (\Exception $e) {
             $this->_helper->json(array("success" => false, "message" => $object->getKey() . " - " . $e->getMessage()));
         }
     }
     $this->_helper->json(array("success" => $success));
 }
Beispiel #8
0
 public function indexAction()
 {
     // IE compatibility
     //$this->getResponse()->setHeader("X-UA-Compatible", "IE=8; IE=9", true);
     // clear open edit locks for this session (in the case of a reload, ...)
     \Pimcore\Model\Element\Editlock::clearSession(session_id());
     // check maintenance
     $maintenance_enabled = false;
     $manager = Model\Schedule\Manager\Factory::getManager("maintenance.pid");
     $lastExecution = $manager->getLastExecution();
     if ($lastExecution) {
         if (time() - $lastExecution < 610) {
             // maintenance script should run at least every 10 minutes + a little tolerance
             $maintenance_enabled = true;
         }
     }
     $this->view->maintenance_enabled = \Zend_Json::encode($maintenance_enabled);
     // configuration
     $sysConfig = Config::getSystemConfig();
     $this->view->config = $sysConfig;
     //mail settings
     $mailIncomplete = false;
     if ($sysConfig->email) {
         if (!$sysConfig->email->debug->emailaddresses) {
             $mailIncomplete = true;
         }
         if (!$sysConfig->email->sender->email) {
             $mailIncomplete = true;
         }
         if ($sysConfig->email->method == "smtp" && !$sysConfig->email->smtp->host) {
             $mailIncomplete = true;
         }
     }
     $this->view->mail_settings_complete = \Zend_Json::encode(!$mailIncomplete);
     // report configuration
     $this->view->report_config = Config::getReportConfig();
     // customviews config
     $cvConfig = Tool::getCustomViewConfig();
     $cvData = array();
     if ($cvConfig) {
         foreach ($cvConfig as $node) {
             $tmpData = $node;
             $rootNode = Model\Object::getByPath($tmpData["rootfolder"]);
             if ($rootNode) {
                 $tmpData["rootId"] = $rootNode->getId();
                 $tmpData["allowedClasses"] = explode(",", $tmpData["classes"]);
                 $tmpData["showroot"] = (bool) $tmpData["showroot"];
                 $cvData[] = $tmpData;
             }
         }
     }
     $this->view->customview_config = $cvData;
     // upload limit
     $max_upload = filesize2bytes(ini_get("upload_max_filesize") . "B");
     $max_post = filesize2bytes(ini_get("post_max_size") . "B");
     $upload_mb = min($max_upload, $max_post);
     $this->view->upload_max_filesize = $upload_mb;
     // csrf token
     $user = $this->getUser();
     $this->view->csrfToken = Tool\Session::useSession(function ($adminSession) use($user) {
         if (!isset($adminSession->csrfToken) && !$adminSession->csrfToken) {
             $adminSession->csrfToken = sha1(microtime() . $user->getName() . uniqid());
         }
         return $adminSession->csrfToken;
     });
     if (\Pimcore\Tool\Admin::isExtJS6()) {
         $this->forward("index6");
     }
 }
Beispiel #9
0
 /**
  * fills object field data values from CSV Import String
  * @abstract
  * @param string $importValue
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @return Object\ClassDefinition\Data
  */
 public function getFromCsvImport($importValue, $object = null, $params = [])
 {
     $values = explode(",", $importValue);
     $value = [];
     foreach ($values as $element) {
         $tokens = explode(":", $element);
         if (count($tokens) == 2) {
             $type = $tokens[0];
             $path = $tokens[1];
             $value[] = Element\Service::getElementByPath($type, $path);
         } else {
             //fallback for old export files
             if ($el = Asset::getByPath($element)) {
                 $value[] = $el;
             } elseif ($el = Document::getByPath($element)) {
                 $value[] = $el;
             } elseif ($el = Object::getByPath($element)) {
                 $value[] = $el;
             }
         }
     }
     return $value;
 }
Beispiel #10
0
 /**
  *
  */
 public function restore()
 {
     $raw = file_get_contents($this->getStoreageFile());
     $element = Serialize::unserialize($raw);
     // check for element with the same name
     if ($element instanceof Document) {
         $indentElement = Document::getByPath($element->getFullpath());
         if ($indentElement) {
             $element->setKey($element->getKey() . "_restore");
         }
     } else {
         if ($element instanceof Asset) {
             $indentElement = Asset::getByPath($element->getFullpath());
             if ($indentElement) {
                 $element->setFilename($element->getFilename() . "_restore");
             }
         } else {
             if ($element instanceof Object\AbstractObject) {
                 $indentElement = Object::getByPath($element->getFullpath());
                 if ($indentElement) {
                     $element->setKey($element->getKey() . "_restore");
                 }
             }
         }
     }
     $this->restoreChilds($element);
     $this->delete();
 }
Beispiel #11
0
 public function objectFormAction()
 {
     $success = false;
     // getting parameters is very easy ... just call $this->getParam("yorParamKey"); regardless if's POST or GET
     if ($this->getParam("firstname") && $this->getParam("lastname") && $this->getParam("email") && $this->getParam("terms")) {
         $success = true;
         // for this example the class "person" and "inquiry" is used
         // first we create a person, then we create an inquiry object and link them together
         // check for an existing person with this name
         $person = Object\Person::getByEmail($this->getParam("email"), 1);
         if (!$person) {
             // if there isn't an existing, ... create one
             $filename = \Pimcore\File::getValidFilename($this->getParam("email"));
             // first we need to create a new object, and fill some system-related information
             $person = new Object\Person();
             $person->setParent(Object::getByPath("/crm/inquiries"));
             // we store all objects in /crm
             $person->setKey($filename);
             // the filename of the object
             $person->setPublished(true);
             // yep, it should be published :)
             // of course this needs some validation here in production...
             $person->setGender($this->getParam("gender"));
             $person->setFirstname($this->getParam("firstname"));
             $person->setLastname($this->getParam("lastname"));
             $person->setEmail($this->getParam("email"));
             $person->setDateRegister(new \DateTime());
             $person->save();
         }
         // now we create the inquiry object and link the person in it
         $inquiryFilename = \Pimcore\File::getValidFilename(date("Y-m-d") . "~" . $person->getEmail());
         $inquiry = new Object\Inquiry();
         $inquiry->setParent(Object::getByPath("/inquiries"));
         // we store all objects in /inquiries
         $inquiry->setKey($inquiryFilename);
         // the filename of the object
         $inquiry->setPublished(true);
         // yep, it should be published :)
         // now we fill in the data
         $inquiry->setMessage($this->getParam("message"));
         $inquiry->setPerson($person);
         $inquiry->setDate(new \DateTime());
         $inquiry->setTerms((bool) $this->getParam("terms"));
         $inquiry->save();
     } elseif ($this->getRequest()->isPost()) {
         $this->view->error = true;
     }
     // do some validation & assign the parameters to the view
     foreach (["firstname", "lastname", "email", "message", "terms"] as $key) {
         if ($this->getParam($key)) {
             $this->view->{$key} = htmlentities(strip_tags($this->getParam($key)));
         }
     }
     // assign the status to the view
     $this->view->success = $success;
 }
 /**
  * @static
  * @param  string $type
  * @param  string $path
  * @return ElementInterface
  */
 public static function getElementByPath($type, $path)
 {
     if ($type == "asset") {
         $element = Asset::getByPath($path);
     } else {
         if ($type == "object") {
             $element = Object::getByPath($path);
         } else {
             if ($type == "document") {
                 $element = Document::getByPath($path);
             }
         }
     }
     return $element;
 }
Beispiel #13
0
 /**
  *
  */
 public function restore($user = null)
 {
     $raw = file_get_contents($this->getStoreageFile());
     $element = Serialize::unserialize($raw);
     // check for element with the same name
     if ($element instanceof Document) {
         $indentElement = Document::getByPath($element->getRealFullPath());
         if ($indentElement) {
             $element->setKey($element->getKey() . "_restore");
         }
     } elseif ($element instanceof Asset) {
         $indentElement = Asset::getByPath($element->getRealFullPath());
         if ($indentElement) {
             $element->setFilename($element->getFilename() . "_restore");
         }
     } elseif ($element instanceof Object\AbstractObject) {
         $indentElement = Object::getByPath($element->getRealFullPath());
         if ($indentElement) {
             $element->setKey($element->getKey() . "_restore");
         }
     }
     if (\Pimcore\Tool\Admin::getCurrentUser()) {
         $parent = $element->getParent();
         if (!$parent->isAllowed("publish")) {
             throw new \Exception("Not sufficient permissions");
         }
     }
     $this->restoreChilds($element);
     $this->delete();
 }
Beispiel #14
0
 /**
  * @param $importValue
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @return array|mixed
  */
 public function getFromCsvImport($importValue, $object = null, $params = [])
 {
     $values = explode(",", $importValue);
     $value = [];
     foreach ($values as $element) {
         if ($el = Object::getByPath($element)) {
             $metaObject = \Pimcore::getDiContainer()->make('Pimcore\\Model\\Object\\Data\\ObjectMetadata', ["fieldname" => $this->getName(), "columns" => $this->getColumnKeys(), "object" => $el]);
             $value[] = $metaObject;
         }
     }
     return $value;
 }