/** * @static * @param $path * @return bool */ public static function pathExists($path, $type = null) { $path = Element\Service::correctPath($path); try { $asset = new Asset(); if (\Pimcore\Tool::isValidPath($path)) { $asset->getDao()->getByPath($path); return true; } } catch (\Exception $e) { } return false; }
/** * Static helper to get an asset by the passed id (returned is not the concrete asset like Asset\Folder!) * * @param integer $id * @return Asset */ public static function getById($id) { $id = intval($id); if ($id < 1) { return null; } $cacheKey = "asset_" . $id; try { $asset = \Zend_Registry::get($cacheKey); if (!$asset) { throw new \Exception("Asset in registry is null"); } } catch (\Exception $e) { try { if (!($asset = \Pimcore\Cache::load($cacheKey))) { $asset = new Asset(); $asset->getDao()->getById($id); $className = "Pimcore\\Model\\Asset\\" . ucfirst($asset->getType()); $asset = \Pimcore::getDiContainer()->make($className); \Zend_Registry::set($cacheKey, $asset); $asset->getDao()->getById($id); \Pimcore\Cache::save($asset, $cacheKey); } else { \Zend_Registry::set($cacheKey, $asset); } } catch (\Exception $e) { \Logger::warning($e->getMessage()); return null; } } if (!$asset) { return null; } return $asset; }
/** * Static helper to get an asset by the passed id (returned is not the concrete asset like Asset\Folder!) * * @param integer $id * @return Asset */ public static function getById($id) { $id = intval($id); if ($id < 1) { return null; } $cacheKey = "asset_" . $id; try { $asset = \Zend_Registry::get($cacheKey); if (!$asset) { throw new \Exception("Asset in registry is null"); } } catch (\Exception $e) { try { if (!($asset = Cache::load($cacheKey))) { $asset = new Asset(); $asset->getDao()->getById($id); $mappingClass = "\\Pimcore\\Model\\Asset\\" . ucfirst($asset->getType()); $typeClass = Tool::getModelClassMapping($mappingClass); if (Tool::classExists($typeClass)) { $asset = new $typeClass(); \Zend_Registry::set($cacheKey, $asset); $asset->getDao()->getById($id); Cache::save($asset, $cacheKey); } } else { \Zend_Registry::set($cacheKey, $asset); } } catch (\Exception $e) { \Logger::warning($e->getMessage()); return null; } } if (!$asset) { return null; } return $asset; }