示例#1
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;
 }
示例#2
0
 /**
  * @param integer $id
  * @return Object_Abstract
  */
 public static function getById($id)
 {
     $id = intval($id);
     if ($id < 1) {
         return null;
     }
     $cacheKey = "object_" . $id;
     try {
         $object = Zend_Registry::get($cacheKey);
         if (!$object) {
             throw new Exception("Object_Abstract: object in registry is null");
         }
     } catch (Exception $e) {
         try {
             if (!($object = Pimcore_Model_Cache::load($cacheKey))) {
                 $object = new Object_Abstract();
                 $typeInfo = $object->getResource()->getTypeById($id);
                 if ($typeInfo["o_type"] == "object" || $typeInfo["o_type"] == "variant" || $typeInfo["o_type"] == "folder") {
                     if ($typeInfo["o_type"] == "folder") {
                         $concreteClassName = "Object_Folder";
                     } else {
                         $concreteClassName = "Object_" . ucfirst($typeInfo["o_className"]);
                     }
                     // check for a mapped class
                     $concreteClassName = Pimcore_Tool::getModelClassMapping($concreteClassName);
                     $object = new $concreteClassName();
                     Zend_Registry::set($cacheKey, $object);
                     $object->getResource()->getById($id);
                     Pimcore_Model_Cache::save($object, $cacheKey);
                 } else {
                     throw new Exception("No entry for object id " . $id);
                 }
             } else {
                 Zend_Registry::set($cacheKey, $object);
             }
         } catch (Exception $e) {
             Logger::warning($e);
             return null;
         }
     }
     $selfType = get_class();
     $staticType = get_called_class();
     // check for type
     if ($selfType != $staticType) {
         if (get_class($object) != $staticType) {
             if (!($object instanceof Object_Concrete && $staticType == "Object_Concrete")) {
                 return null;
             }
         }
     }
     if (!$object) {
         return null;
     }
     return $object;
 }
示例#3
0
 /**
  * Checks if data for this field is valid and removes broken dependencies
  *
  * @param Object_Abstract $object
  * @return bool
  */
 public function sanityCheck($object)
 {
     $sane = true;
     $name = $this->getName();
     $getter = "get" . ucfirst($name);
     $data = $object->{$getter}();
     $objectRelationIds = array();
     if (is_array($data)) {
         foreach ($data as $o) {
             if ($o instanceof Element_Interface) {
                 $objectRelationIds[] = $o->getId();
             }
         }
     } else {
         if ($data instanceof Element_Interface) {
             $objectRelationIds[] = $data->getId();
         }
     }
     $resourceRelationIds = $object->getResource()->getRelationIds($this->getName());
     $diff = array_diff($objectRelationIds, $resourceRelationIds);
     if (count($diff) > 0) {
         $sane = false;
         Logger::notice("Detected insane relation(s), removing reference to non existent elements with ids [" . implode(',', $diff) . "]");
     }
     return $sane;
 }