示例#1
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;
 }
示例#2
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);
     }
 }
示例#3
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);
 }
示例#4
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;
 }
示例#5
0
 /**
  * @see Object_Class_Data::getDataForResource
  * @param array $data
  * @param null|Object_Abstract $object
  * @return array
  */
 public function getDataForResource($data, $object = null)
 {
     $return = array();
     if (is_array($data) && count($data) > 0) {
         $counter = 1;
         foreach ($data as $object) {
             if ($object instanceof Element_Interface) {
                 $return[] = array("dest_id" => $object->getId(), "type" => Element_Service::getElementType($object), "fieldname" => $this->getName(), "index" => $counter);
             }
             $counter++;
         }
         return $return;
     } else {
         if (is_array($data) and count($data) === 0) {
             //give empty array if data was not null
             return array();
         } else {
             //return null if data was null  - this indicates data was not loaded
             return null;
         }
     }
 }
示例#6
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());
     }
 }
示例#7
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;
 }