Ejemplo n.º 1
0
 public function reverseMap($object)
 {
     $keys = get_object_vars($this);
     foreach ($keys as $key => $value) {
         $method = "set" . $key;
         if (method_exists($object, $method)) {
             $object->{$method}($value);
         }
     }
     $object->setProperties(null);
     if (is_array($this->properties)) {
         foreach ($this->properties as $propertyWs) {
             $dat = $propertyWs->data;
             $type = $propertyWs->type;
             if (in_array($type, array("object", "document", "asset"))) {
                 $dat = Element_Service::getElementById($propertyWs->type, $propertyWs->data);
                 if (is_numeric($propertyWs->data) and !$dat) {
                     throw new Exception("cannot import property [ " . $propertyWs->name . " ] because it references unknown " . $propertyWs->type);
                 }
             } else {
                 if ($type == "date") {
                     $dat = new Pimcore_Date(strtotime($propertyWs->data));
                 } else {
                     $dat = $propertyWs->data;
                 }
             }
             $object->setProperty($propertyWs->name, $propertyWs->type, $dat, $propertyWs->inherited);
         }
     }
 }
Ejemplo n.º 2
0
 public function extractRelations($element, $apiElementKeys, $recursive, $includeRelations)
 {
     $foundRelations = array();
     if ($includeRelations) {
         $dependency = $element->getDependencies();
         if ($dependency) {
             foreach ($dependency->getRequires() as $r) {
                 if ($e = Element_Service::getDependedElement($r)) {
                     if ($element->getId() != $e->getId() and !in_array(Element_Service::getElementType($e) . "_" . $e->getId(), $apiElementKeys)) {
                         $foundRelations[Element_Service::getElementType($e) . "_" . $e->getId()] = array("elementType" => Element_Service::getType($e), "element" => $e->getId(), "recursive" => false);
                     }
                 }
             }
         }
     }
     $childs = $element->getChilds();
     if ($recursive and $childs) {
         foreach ($childs as $child) {
             if (!in_array(Element_Service::getType($child) . "_" . $child->getId(), $apiElementKeys)) {
                 $foundRelations[Element_Service::getType($child) . "_" . $child->getId()] = array("elementType" => Element_Service::getType($child), "element" => $child->getId(), "recursive" => $recursive);
             }
         }
     }
     return $foundRelations;
 }
Ejemplo n.º 3
0
 /**
  * @param  Element_Interface $webResource
  * @return void
  */
 public function __construct($webResource)
 {
     $this->id = $webResource->getId();
     if ($webResource instanceof Element_Interface) {
         $this->type = Element_Service::getType($webResource);
     } else {
         $this->type = "unknown";
     }
 }
 public function addAction()
 {
     $element = Element_Service::getElementById($this->_getParam("type"), $this->_getParam("id"));
     if ($element) {
         Element_Recyclebin_Item::create($element, $this->getUser());
         $this->_helper->json(array("success" => true));
     } else {
         $this->_helper->json(array("success" => false));
     }
 }
Ejemplo n.º 5
0
 /**
  * Get the data for the object from database for the given id
  *
  * @param integer $cid
  * @param string $ctype
  * @return void
  */
 public function getByElement($cid, $ctype)
 {
     $data = $this->db->fetchRow("SELECT * FROM edit_lock WHERE cid = ? AND ctype = ?", array($cid, $ctype));
     if (!$data["id"]) {
         throw new Exception("Lock with cid " . $cid . " and ctype " . $ctype . " not found");
     }
     $this->assignVariablesToModel($data);
     // add elements path
     $element = Element_Service::getElementById($ctype, $cid);
     if ($element) {
         $this->model->setCpath($element->getFullpath());
     }
 }
Ejemplo n.º 6
0
 /**
  * Clear all relations in the database
  * @param Element_Interface $element
  */
 public function clearAllForElement($element)
 {
     try {
         $id = $element->getId();
         $type = Element_Service::getElementType($element);
         //schedule for sanity check
         $data = $this->db->fetchAll("SELECT * FROM dependencies WHERE targetid = ? AND targettype = ?", array($id, $type));
         if (is_array($data)) {
             foreach ($data as $row) {
                 $sanityCheck = new Element_Sanitycheck();
                 $sanityCheck->setId($row['sourceid']);
                 $sanityCheck->setType($row['sourcetype']);
                 $sanityCheck->save();
             }
         }
         $this->db->delete("dependencies", $this->db->quoteInto("sourceid = ?", $id) . " AND " . $this->db->quoteInto("sourcetype = ?", $type));
         $this->db->delete("dependencies", $this->db->quoteInto("targetid = ?", $id) . " AND " . $this->db->quoteInto("targettype = ?", $type));
     } catch (Exception $e) {
         Logger::error($e);
     }
 }
Ejemplo n.º 7
0
 /**
  * @param  User $user
  * @return void
  */
 public function save($user = null)
 {
     if ($this->getElement() instanceof Element_Interface) {
         $this->setType(Element_Service::getElementType($this->getElement()));
     }
     $this->setSubtype($this->getElement()->getType());
     $this->setPath($this->getElement()->getFullPath());
     $this->setDate(time());
     $this->loadChilds($this->getElement());
     if ($user instanceof User) {
         $this->setDeletedby($user->getName());
     }
     // serialize data
     $this->element->_fulldump = true;
     $data = Pimcore_Tool_Serialize::serialize($this->getElement());
     $this->getResource()->save();
     if (!is_dir(PIMCORE_RECYCLEBIN_DIRECTORY)) {
         mkdir(PIMCORE_RECYCLEBIN_DIRECTORY);
     }
     file_put_contents($this->getStoreageFile(), $data);
     chmod($this->getStoreageFile(), 0766);
 }
Ejemplo n.º 8
0
 /**
  * Static helper to get an asset by the passed path (returned is not the concrete asset like Asset_Folder!)
  *
  * @param string $path
  * @return Asset
  */
 public static function getByPath($path)
 {
     $path = Element_Service::correctPath($path);
     try {
         $asset = new Asset();
         if (Pimcore_Tool::isValidPath($path)) {
             $asset->getResource()->getByPath($path);
             return self::getById($asset->getId());
         }
     } catch (Exception $e) {
         Logger::warning($e);
     }
     return null;
 }
Ejemplo n.º 9
0
 public function getFolderAction()
 {
     // check for lock
     if (Element_Editlock::isLocked($this->_getParam("id"), "object")) {
         $this->_helper->json(array("editlock" => Element_Editlock::getByElement($this->_getParam("id"), "object")));
     }
     Element_Editlock::lock($this->_getParam("id"), "object");
     $object = Object_Abstract::getById(intval($this->_getParam("id")));
     if ($object->isAllowed("view")) {
         $objectData = array();
         $objectData["general"] = array();
         $objectData["idPath"] = Pimcore_Tool::getIdPathForElement($object);
         $allowedKeys = array("o_published", "o_key", "o_id", "o_type");
         foreach (get_object_vars($object) as $key => $value) {
             if (strstr($key, "o_") && in_array($key, $allowedKeys)) {
                 $objectData["general"][$key] = $value;
             }
         }
         $objectData["general"]["o_locked"] = $object->isLocked();
         $objectData["properties"] = Element_Service::minimizePropertiesForEditmode($object->getProperties());
         $objectData["userPermissions"] = $object->getUserPermissions();
         $objectData["classes"] = $object->getResource()->getClasses();
         $this->_helper->json($objectData);
     } else {
         Logger::debug("prevented getting folder id [ " . $object->getId() . " ] because of missing permissions");
         $this->_helper->json(array("success" => false, "message" => "missing_permission"));
     }
 }
Ejemplo n.º 10
0
 /**
  * @throws Exception
  * @param  $rootElement
  * @param  $apiKey
  * @param  $path
  * @param  $apiElement
  * @param  bool $overwrite
  * @param  $elementCounter
  * @return Element_Interface
  */
 public function create($rootElement, $apiKey, $path, $apiElement, $overwrite, $elementCounter)
 {
     //correct relative path
     if (strpos($path, "/") !== 0) {
         $path = $rootElement->getFullPath() . "/" . $path;
     }
     $type = $apiElement->type;
     if ($apiElement instanceof Webservice_Data_Asset) {
         $className = "Asset_" . ucfirst($type);
         $parentClassName = "Asset";
         $maintype = "asset";
         $fullPath = $path . $apiElement->filename;
     } else {
         if ($apiElement instanceof Webservice_Data_Object) {
             $maintype = "object";
             if ($type == "object") {
                 $className = "Object_" . ucfirst($apiElement->className);
                 if (!class_exists($className)) {
                     throw new Exception("Unknown class [ " . $className . " ]");
                 }
             } else {
                 $className = "Object_" . ucfirst($type);
             }
             $parentClassName = "Object_Abstract";
             $fullPath = $path . $apiElement->key;
         } else {
             if ($apiElement instanceof Webservice_Data_Document) {
                 $maintype = "document";
                 $className = "Document_" . ucfirst($type);
                 $parentClassName = "Document";
                 $fullPath = $path . $apiElement->key;
             } else {
                 throw new Exception("Unknown import element");
             }
         }
     }
     $existingElement = $className::getByPath($fullPath);
     if ($overwrite && $existingElement) {
         $apiElement->parentId = $existingElement->getParentId();
         return $existingElement;
     }
     $element = new $className();
     $element->setId(null);
     $element->setCreationDate(time());
     if ($element instanceof Asset) {
         $element->setFilename($apiElement->filename);
         $element->setData(base64_decode($apiElement->data));
     } else {
         if ($element instanceof Object_Concrete) {
             $element->setKey($apiElement->key);
             $element->setO_className($apiElement->className);
             $class = Object_Class::getByName($apiElement->className);
             if (!$class instanceof Object_Class) {
                 throw new Exception("Unknown object class [ " . $apiElement->className . " ] ");
             }
             $element->setO_classId($class->getId());
         } else {
             $element->setKey($apiElement->key);
         }
     }
     $this->setModificationParams($element, true);
     $key = $element->getKey();
     if (empty($key) and $apiElement->id == 1) {
         if ($element instanceof Asset) {
             $element->setFilename("home_" . uniqid());
         } else {
             $element->setKey("home_" . uniqid());
         }
     } else {
         if (empty($key)) {
             throw new Exception("Cannot create element without key ");
         }
     }
     $parent = $parentClassName::getByPath($path);
     if (Element_Service::getType($rootElement) == $maintype and $parent) {
         $element->setParentId($parent->getId());
         $apiElement->parentId = $parent->getId();
         $existingElement = $parentClassName::getByPath($parent->getFullPath() . "/" . $element->getKey());
         if ($existingElement) {
             //set dummy key to avoid duplicate paths
             if ($element instanceof Asset) {
                 $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename());
             } else {
                 $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey());
             }
         }
     } else {
         if (Element_Service::getType($rootElement) != $maintype) {
             //this is a related element - try to import it to it's original path or set the parent to home folder
             $potentialParent = $parentClassName::getByPath($path);
             //set dummy key to avoid duplicate paths
             if ($element instanceof Asset) {
                 $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename());
             } else {
                 $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey());
             }
             if ($potentialParent) {
                 $element->setParentId($potentialParent->getId());
                 //set actual id and path for second run
                 $apiElements[$apiKey]["path"] = $potentialParent->getFullPath();
                 $apiElement->parentId = $potentialParent->getId();
             } else {
                 $element->setParentId(1);
                 //set actual id and path for second run
                 $apiElements[$apiKey]["path"] = "/";
                 $apiElement->parentId = 1;
             }
         } else {
             $element->setParentId($rootElement->getId());
             //set actual id and path for second run
             $apiElements[$apiKey]["path"] = $rootElement->getFullPath();
             $apiElement->parentId = $rootElement->getId();
             //set dummy key to avoid duplicate paths
             if ($element instanceof Asset) {
                 $element->setFilename(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getFilename());
             } else {
                 $element->setKey(str_replace("/", "_", $apiElement->path) . uniqid() . "_" . $elementCounter . "_" . $element->getKey());
             }
         }
     }
     //if element exists, make temp key permanent by setting it in apiElement
     if ($parentClassName::getByPath($fullPath)) {
         if ($element instanceof Asset) {
             $apiElement->filename = $element->getFilename();
         } else {
             $apiElement->key = $element->getKey();
         }
     }
     $element->save();
     //todo save type and id for later rollback
     $this->importInfo[Element_Service::getType($element) . "_" . $element->getId()] = array("id" => $element->getId(), "type" => Element_Service::getType($element), "fullpath" => $element->getFullPath());
     return $element;
 }
Ejemplo n.º 11
0
 protected function getImportCopyName($intendedPath, $key, $objectId, $type)
 {
     $equalObject = Element_Service::getElementByPath($type, str_replace("//", "/", $intendedPath . "/" . $key));
     while ($equalObject and $equalObject->getId() != $objectId) {
         $key .= "_importcopy";
         $equalObject = Element_Service::getElementByPath($type, str_replace("//", "/", $intendedPath . "/" . $key));
         if (!$equalObject) {
             break;
         }
     }
     return $key;
 }
Ejemplo n.º 12
0
 public function typePathAction()
 {
     $id = $this->getParam("id");
     $type = $this->getParam("type");
     if ($type == "asset") {
         $asset = Asset::getById($id);
         $typePath = self::getAssetTypePath($asset);
         $data = array("success" => true, "idPath" => Element_Service::getIdPath($asset), "typePath" => $typePath);
         $this->_helper->json($data);
     } else {
         $object = Object_Abstract::getById($id);
         $typePath = self::getTypePath($object);
         $data = array("success" => true, "idPath" => Element_Service::getIdPath($object), "typePath" => $typePath);
         $this->_helper->json($data);
     }
 }
Ejemplo n.º 13
0
 /**
  * Returns the current tag's data for web service export
  *
  * @abstract
  * @return array
  */
 public function getForWebserviceExport()
 {
     $el = parent::getForWebserviceExport();
     if ($this->data["internal"]) {
         if (intval($this->data["internalId"]) > 0) {
             if ($this->data["internalType"] == "document") {
                 $referencedDocument = Document::getById($this->data["internalId"]);
                 if (!$referencedDocument instanceof Document) {
                     //detected broken link
                     $document = Document::getById($this->getDocumentId());
                     Element_Service::scheduleForSanityCheck($document);
                 }
             } else {
                 if ($this->data["internalType"] == "asset") {
                     $referencedAsset = Asset::getById($this->data["internalId"]);
                     if (!$referencedAsset instanceof Asset) {
                         //detected broken link
                         $document = Document::getById($this->getDocumentId());
                         Element_Service::scheduleForSanityCheck($document);
                     }
                 }
             }
         }
     }
     $el->data = $this->data;
     return $el;
 }
Ejemplo n.º 14
0
 /**
  * renews all references, for example after unserializing an Element_Interface
  * @param  Document|Asset|Object_Abstract $data
  * @return mixed
  */
 public static function renewReferences($data, $initial = true)
 {
     if (is_array($data)) {
         foreach ($data as &$value) {
             $value = self::renewReferences($value, false);
         }
         return $data;
     } else {
         if (is_object($data)) {
             if ($data instanceof Element_Interface && !$initial) {
                 return Element_Service::getElementById(Element_Service::getElementType($data), $data->getId());
             } else {
                 // if this is the initial element set the correct path and key
                 if ($data instanceof Element_Interface && $initial) {
                     $originalElement = Element_Service::getElementById(Element_Service::getElementType($data), $data->getId());
                     if ($originalElement) {
                         if ($data instanceof Asset) {
                             $data->setFilename($originalElement->getFilename());
                         } else {
                             if ($data instanceof Document) {
                                 $data->setKey($originalElement->getKey());
                             } else {
                                 if ($data instanceof Object_Abstract) {
                                     $data->setKey($originalElement->getKey());
                                 }
                             }
                         }
                         $data->setPath($originalElement->getPath());
                     }
                 }
                 $properties = get_object_vars($data);
                 foreach ($properties as $name => $value) {
                     $data->{$name} = self::renewReferences($value, false);
                 }
                 return $data;
             }
         }
     }
     return $data;
 }
Ejemplo n.º 15
0
 public function preGetData($object)
 {
     $data = $object->{$this->getName()};
     if ($this->getLazyLoading() and !in_array($this->getName(), $object->getO__loadedLazyFields())) {
         //$data = $this->getDataFromResource($object->getRelationData($this->getName(),true,null));
         $data = $this->load($object, array("force" => true));
         $setter = "set" . ucfirst($this->getName());
         if (method_exists($object, $setter)) {
             $object->{$setter}($data);
         }
     }
     if (Object_Abstract::doHideUnpublished() and is_array($data)) {
         $publishedList = array();
         foreach ($data as $listElement) {
             if (Element_Service::isPublished($listElement)) {
                 $publishedList[] = $listElement;
             }
         }
         return $publishedList;
     }
     return is_array($data) ? $data : array();
 }
Ejemplo n.º 16
0
 /**
  * converts data to be imported via webservices
  * @param mixed $value
  * @return mixed
  */
 public function getFromWebserviceImport($value)
 {
     if (empty($value)) {
         return null;
     } else {
         if (is_array($value) and !empty($value['text']) and !empty($value['direct'])) {
             $link = new Object_Data_Link();
             foreach ($value as $key => $value) {
                 $method = "set" . ucfirst($key);
                 if (method_exists($link, $method)) {
                     $link->{$method}($value);
                 } else {
                     throw new Exception("cannot get values from web service import - invalid data. Unknown Object_Data_Link setter [ " . $method . " ]");
                 }
             }
             return $link;
         } else {
             if (is_array($value) and !empty($value['text']) and !empty($value['internalType']) and !empty($value['internal'])) {
                 $element = Element_Service::getElementById($value['internalType'], $value['internal']);
                 if (!$element) {
                     throw new Exception("cannot get values from web service import - referencing unknown internal element with type [ " . $value['internalType'] . " ] and id [ " . $value['internal'] . " ]");
                 }
                 $link = new Object_Data_Link();
                 foreach ($value as $key => $value) {
                     $method = "set" . ucfirst($key);
                     if (method_exists($link, $method)) {
                         $link->{$method}($value);
                     } else {
                         throw new Exception("cannot get values from web service import - invalid data. Unknown Object_Data_Link setter [ " . $method . " ]");
                     }
                 }
                 return $link;
             } else {
                 throw new Exception("cannot get values from web service import - invalid data");
             }
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * Object
  *
  * @return mixed
  */
 public function loadData()
 {
     if (!is_file($this->getFilePath()) or !is_readable($this->getFilePath())) {
         Logger::err("Version: cannot read version data from file system.");
         $this->delete();
         return;
     }
     $data = file_get_contents($this->getFilePath());
     if ($this->getSerialized()) {
         $data = Pimcore_Tool_Serialize::unserialize($data);
     }
     $data = Element_Service::renewReferences($data);
     $this->setData($data);
     return $data;
 }
Ejemplo n.º 18
0
 /**
  * Checks if data is valid for current data field
  *
  * @param mixed $data
  * @param boolean $omitMandatoryCheck
  * @throws Exception
  */
 public function checkValidity($data, $omitMandatoryCheck = false)
 {
     if (!$omitMandatoryCheck and $this->getMandatory() and empty($data)) {
         throw new Exception("Empty mandatory field [ " . $this->getName() . " ]");
     }
     $dependencies = Pimcore_Tool_Text::getDependenciesOfWysiwygText($data);
     if (is_array($dependencies)) {
         foreach ($dependencies as $key => $value) {
             $el = Element_Service::getElementById($value['type'], $value['id']);
             if (!$el) {
                 throw new Exception("invalid dependency in wysiwyg text");
             }
         }
     }
 }
Ejemplo n.º 19
0
 /**
  * @static
  * @param $path
  * @return bool
  */
 public static function pathExists($path, $type = null)
 {
     $path = Element_Service::correctPath($path);
     try {
         $object = new Object_Abstract();
         if (Pimcore_Tool::isValidPath($path)) {
             $object->getResource()->getByPath($path);
             return true;
         }
     } catch (Exception $e) {
     }
     return false;
 }
Ejemplo n.º 20
0
 /**
  * @static
  * @param $path
  * @return bool
  */
 public static function pathExists($path)
 {
     $path = Element_Service::correctPath($path);
     try {
         $document = new Document();
         // validate path
         if (Pimcore_Tool::isValidPath($path)) {
             $document->getResource()->getByPath($path);
             return true;
         }
     } catch (Exception $e) {
     }
     return false;
 }
Ejemplo n.º 21
0
 /**
  * @return bool
  */
 public function sanityCheck()
 {
     $sane = true;
     if ($this->id) {
         $el = Element_Service::getElementById($this->type, $this->id);
         if (!$el instanceof Element_Interface) {
             $sane = false;
             Logger::notice("Detected insane relation, removing reference to non existent " . $this->type . " with id [" . $this->id . "]");
             $this->id = null;
             $this->type = null;
             $this->subtype = null;
             $this->element = null;
         }
     }
     return $sane;
 }
Ejemplo n.º 22
0
 /**
  * @static
  * @param Pimcore_Model_List_Abstract $list
  * @return void
  */
 protected static function loadToCache(Pimcore_Model_List_Abstract $list)
 {
     $totalCount = $list->getTotalCount();
     $iterations = ceil($totalCount / self::getPerIteration());
     Logger::info("New list of elements queued for storing into the cache with " . $iterations . " iterations and " . $totalCount . " total items");
     for ($i = 0; $i < $iterations; $i++) {
         Logger::info("Starting iteration " . $i . " with offset: " . self::getPerIteration() * $i);
         $list->setLimit(self::getPerIteration());
         $list->setOffset(self::getPerIteration() * $i);
         $elements = $list->load();
         foreach ($elements as $element) {
             $cacheKey = Element_Service::getElementType($element) . "_" . $element->getId();
             Pimcore_Model_Cache::storeToCache($element, $cacheKey);
         }
         Pimcore::collectGarbage();
         sleep(self::getTimoutBetweenIteration());
     }
 }
Ejemplo n.º 23
0
 /**
  * @static
  * @param $text
  * @return array
  */
 public static function getElementsInWysiwyg($text)
 {
     $hash = "elements_wysiwyg_text_" . md5($text);
     if (Zend_Registry::isRegistered($hash)) {
         return Zend_Registry::get($hash);
     }
     $elements = array();
     $matches = self::getElementsTagsInWysiwyg($text);
     if (count($matches[2]) > 0) {
         for ($i = 0; $i < count($matches[2]); $i++) {
             preg_match("/[0-9]+/", $matches[2][$i], $idMatches);
             preg_match("/asset|object|document/", $matches[3][$i], $typeMatches);
             $id = $idMatches[0];
             $type = $typeMatches[0];
             $element = Element_Service::getElementById($type, $id);
             if ($id && $type && $element instanceof Element_Interface) {
                 $elements[] = array("id" => $id, "type" => $type, "element" => $element);
             }
         }
     }
     Zend_Registry::set($hash, $elements);
     return $elements;
 }
 /**
  * @see Object_Class_Data::getDataFromEditmode
  * @param array $data
  * @param null|Object_Abstract $object
  * @return array
  */
 public function getDataFromEditmode($data, $object = null)
 {
     //if not set, return null
     if ($data === null or $data === FALSE) {
         return null;
     }
     $elements = array();
     $data = explode(",", $data);
     if (is_array($data) && count($data) > 0) {
         foreach ($data as $id) {
             $elements[] = Element_Service::getElementById("object", $id);
         }
     }
     //must return array if data shall be set
     return $elements;
 }
Ejemplo n.º 25
0
 public function preGetData($object)
 {
     $data = $object->{$this->getName()};
     if ($this->getLazyLoading() and !in_array($this->getName(), $object->getO__loadedLazyFields())) {
         //$data = $this->getDataFromResource($object->getRelationData($this->getName(),true,null));
         $data = $this->load($object, array("force" => true));
         $setter = "set" . ucfirst($this->getName());
         if (method_exists($object, $setter)) {
             $object->{$setter}($data);
         }
     }
     if (Object_Abstract::doHideUnpublished() and $data instanceof Element_Interface) {
         if (!Element_Service::isPublished($data)) {
             return null;
         }
     }
     return $data;
 }
Ejemplo n.º 26
0
 public function doExportJobsAction()
 {
     $exportSession = new Zend_Session_Namespace("element_export");
     $exportName = "export_" . Zend_Session::getId();
     $exportDir = PIMCORE_WEBSITE_PATH . "/var/tmp/" . $exportName;
     if (!$exportSession->elements) {
         $exportSession->type = $this->_getParam("type");
         $exportSession->id = $this->_getParam("id");
         $exportSession->includeRelations = (bool) $this->_getParam("includeRelations");
         $exportSession->recursive = (bool) $this->_getParam("recursive");
         $exportSession->counter = 0;
         $element = Element_Service::getElementById($exportSession->type, $exportSession->id);
         $exportSession->rootPath = $element->getPath();
         $exportSession->rootType = Element_Service::getType($element);
         $exportSession->elements = array(Element_Service::getType($element) . "_" . $element->getId() => array("elementType" => Element_Service::getType($element), "element" => $element->getId(), "recursive" => $exportSession->recursive));
         $exportSession->apiElements = array();
         if (is_dir($exportDir)) {
             recursiveDelete($exportDir);
         }
         mkdir($exportDir, 0755, true);
         $this->_helper->json(array("more" => true, "totalElementsDone" => 0, "totalElementsFound" => 0));
     } else {
         $data = array_pop($exportSession->elements);
         $element = Element_Service::getElementById($data["elementType"], $data["element"]);
         $recursive = $data["recursive"];
         $exportService = new Element_Export_Service();
         $apiElement = $exportService->getApiElement($element);
         $exportSession->foundRelations = $exportService->extractRelations($element, array_keys($exportSession->apiElements), $recursive, $exportSession->includeRelations);
         //make path relative to root
         if (Element_Service::getType($element) == $exportSession->rootType and $exportSession->rootPath == $element->getPath()) {
             $apiElement->path = "";
         } else {
             if (Element_Service::getType($element) == $exportSession->rootType and strpos($element->getPath(), $exportSession->rootPath) === 0) {
                 if ($exportSession->rootPath === "/") {
                     $len = 1;
                 } else {
                     $len = strlen($exportSession->rootPath) - 1;
                 }
                 $apiElement->path = substr($element->getPath(), $len);
             } else {
                 $apiElement->path = $element->getPath();
             }
         }
         $path = $apiElement->path;
         //convert the Webservice _Out element to _In elements
         $outClass = get_class($apiElement);
         $inClass = str_replace("_Out", "_In", $outClass);
         $apiElementIn = new $inClass();
         $objectVars = get_object_vars($apiElementIn);
         foreach ($objectVars as $var => $value) {
             if (property_exists(get_class($apiElement), $var)) {
                 $apiElementIn->{$var} = $apiElement->{$var};
             }
         }
         //remove parentId, add path
         $apiElementIn->parentId = null;
         $apiElement = $apiElementIn;
         $key = Element_Service::getType($element) . "_" . $element->getId();
         $exportSession->apiElements[$key] = array("element" => $apiElement, "path" => $path);
         $exportFile = $exportDir . "/" . $exportSession->counter . "_" . $key;
         file_put_contents($exportFile, serialize(array("element" => $apiElement, "path" => $path)));
         chmod($exportFile, 0766);
         $exportSession->elements = array_merge($exportSession->elements, $exportSession->foundRelations);
         if (count($exportSession->elements) == 0) {
             $exportArchive = $exportDir . ".zip";
             if (is_file($exportArchive)) {
                 unlink($exportArchive);
             }
             $zip = new ZipArchive();
             $created = $zip->open($exportArchive, ZipArchive::CREATE);
             if ($created === TRUE) {
                 $dh = opendir($exportDir);
                 while ($file = readdir($dh)) {
                     if ($file != '.' && $file != '..') {
                         $fullFilePath = $exportDir . "/" . $file;
                         if (is_file($fullFilePath)) {
                             $zip->addFile($fullFilePath, str_replace($exportDir . "/", "", $fullFilePath));
                         }
                     }
                 }
                 closedir($dh);
                 $zip->close();
             }
         }
         $exportSession->counter++;
         $this->_helper->json(array("more" => count($exportSession->elements) != 0, "totalElementsDone" => count($exportSession->apiElements), "totalElementsFound" => count($exportSession->foundRelations)));
     }
 }
Ejemplo n.º 27
0
 /**
  * @see Document_Tag_Interface::frontend
  * @return void
  */
 public function frontend()
 {
     $this->setElements();
     $return = "";
     if (is_array($this->elements) && count($this->elements) > 0) {
         foreach ($this->elements as $element) {
             $return .= Element_Service::getElementType($element) . ": " . $element->getFullPath() . "<br />";
         }
     }
     return $return;
 }
Ejemplo n.º 28
0
 protected function minimizeProperties($document)
 {
     $properties = Element_Service::minimizePropertiesForEditmode($document->getProperties());
     $document->setProperties($properties);
 }
Ejemplo n.º 29
0
 public function getRequiredByDependenciesAction()
 {
     $id = $this->_getParam("id");
     $asset = Asset::getById($id);
     if ($asset instanceof Asset) {
         $dependencies = Element_Service::getRequiredByDependenciesForFrontend($asset->getDependencies());
         $this->_helper->json($dependencies);
     }
     $this->_helper->json(false);
 }
Ejemplo n.º 30
0
 /**
  * @return void
  */
 public function findAction()
 {
     $user = $this->getUser();
     $query = $this->_getParam("query");
     if ($query == "*") {
         $query = "";
     }
     $query = str_replace("%", "*", $query);
     $types = explode(",", $this->_getParam("type"));
     $subtypes = explode(",", $this->_getParam("subtype"));
     $classnames = explode(",", $this->_getParam("class"));
     $offset = intval($this->_getParam("start"));
     $limit = intval($this->_getParam("limit"));
     $offset = $offset ? $offset : 0;
     $limit = $limit ? $limit : 50;
     $searcherList = new Search_Backend_Data_List();
     $conditionParts = array();
     $db = Pimcore_Resource::get();
     //exclude forbidden assets
     if (in_array("asset", $types)) {
         if (!$user->isAllowed("assets")) {
             $forbiddenConditions[] = " `type` != 'asset' ";
         } else {
             $forbiddenAssetPaths = Element_Service::findForbiddenPaths("asset", $user);
             if (count($forbiddenAssetPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
                     $forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
             }
         }
     }
     //exclude forbidden documents
     if (in_array("document", $types)) {
         if (!$user->isAllowed("documents")) {
             $forbiddenConditions[] = " `type` != 'document' ";
         } else {
             $forbiddenDocumentPaths = Element_Service::findForbiddenPaths("document", $user);
             if (count($forbiddenDocumentPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
                     $forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
             }
         }
     }
     //exclude forbidden objects
     if (in_array("object", $types)) {
         if (!$user->isAllowed("objects")) {
             $forbiddenConditions[] = " `type` != 'object' ";
         } else {
             $forbiddenObjectPaths = Element_Service::findForbiddenPaths("object", $user);
             if (count($forbiddenObjectPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
                     $forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
             }
         }
     }
     if ($forbiddenConditions) {
         $conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
     }
     if (!empty($query)) {
         $queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
         // the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
         // if the query is numeric the user might want to search by id
         //if(is_numeric($query)) {
         //$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
         //}
         $conditionParts[] = $queryCondition;
     }
     //For objects - handling of bricks
     $fields = array();
     $bricks = array();
     if ($this->_getParam("fields")) {
         $fields = $this->_getParam("fields");
         foreach ($fields as $f) {
             $parts = explode("~", $f);
             if (count($parts) > 1) {
                 $bricks[$parts[0]] = $parts[0];
             }
         }
     }
     // filtering for objects
     if ($this->_getParam("filter")) {
         $class = Object_Class::getByName($this->_getParam("class"));
         $conditionFilters = Object_Service::getFilterCondition($this->_getParam("filter"), $class);
         $join = "";
         foreach ($bricks as $ob) {
             $join .= " LEFT JOIN object_brick_query_" . $ob . "_" . $class->getId();
             $join .= " `" . $ob . "`";
             $join .= " ON `" . $ob . "`.o_id = `object_" . $class->getId() . "`.o_id";
         }
         $conditionParts[] = "( id IN (SELECT `object_" . $class->getId() . "`.o_id FROM object_" . $class->getId() . $join . " WHERE 1=1 " . $conditionFilters . ") )";
     }
     if (is_array($types) and !empty($types[0])) {
         foreach ($types as $type) {
             $conditionTypeParts[] = $db->quote($type);
         }
         $conditionParts[] = "( maintype IN (" . implode(",", $conditionTypeParts) . ") )";
     }
     if (is_array($subtypes) and !empty($subtypes[0])) {
         foreach ($subtypes as $subtype) {
             $conditionSubtypeParts[] = $db->quote($subtype);
         }
         $conditionParts[] = "( type IN (" . implode(",", $conditionSubtypeParts) . ") )";
     }
     if (is_array($classnames) and !empty($classnames[0])) {
         if (in_array("folder", $subtypes)) {
             $classnames[] = "folder";
         }
         foreach ($classnames as $classname) {
             $conditionClassnameParts[] = $db->quote($classname);
         }
         $conditionParts[] = "( subtype IN (" . implode(",", $conditionClassnameParts) . ") )";
     }
     if (count($conditionParts) > 0) {
         $condition = implode(" AND ", $conditionParts);
         //echo $condition; die();
         $searcherList->setCondition($condition);
     }
     $searcherList->setOffset($offset);
     $searcherList->setLimit($limit);
     // do not sort per default, it is VERY SLOW
     //$searcherList->setOrder("desc");
     //$searcherList->setOrderKey("modificationdate");
     if ($this->_getParam("sort")) {
         $searcherList->setOrderKey($this->_getParam("sort"));
     }
     if ($this->_getParam("dir")) {
         $searcherList->setOrder($this->_getParam("dir"));
     }
     $hits = $searcherList->load();
     $elements = array();
     foreach ($hits as $hit) {
         $element = Element_Service::getElementById($hit->getId()->getType(), $hit->getId()->getId());
         if ($element->isAllowed("list")) {
             if ($element instanceof Object_Abstract) {
                 $data = Object_Service::gridObjectData($element, $fields);
             } else {
                 if ($element instanceof Document) {
                     $data = Document_Service::gridDocumentData($element);
                 } else {
                     if ($element instanceof Asset) {
                         $data = Asset_Service::gridAssetData($element);
                     }
                 }
             }
             $elements[] = $data;
         } else {
             //TODO: any message that view is blocked?
             //$data = Element_Service::gridElementData($element);
         }
     }
     // only get the real total-count when the limit parameter is given otherwise use the default limit
     if ($this->_getParam("limit")) {
         $totalMatches = $searcherList->getTotalCount();
     } else {
         $totalMatches = count($elements);
     }
     $this->_helper->json(array("data" => $elements, "success" => true, "total" => $totalMatches));
     $this->removeViewRenderer();
 }