Pimcore\Model\Document\Service::pathExists PHP Method

pathExists() public static method

public static pathExists ( $path, $type = null ) : boolean
$path
return boolean
    public static function pathExists($path, $type = null)
    {
        $path = Element\Service::correctPath($path);
        try {
            $document = new Document();
            // validate path
            if (\Pimcore\Tool::isValidPath($path)) {
                $document->getDao()->getByPath($path);
                return true;
            }
        } catch (\Exception $e) {
        }
        return false;
    }

Usage Example

Exemplo n.º 1
0
 public function importDocuments()
 {
     $file = sprintf('%s/documents.json', $this->baseDir);
     $docs = new \Zend_Config_Json($file);
     foreach ($docs as $def) {
         $def = $def->toArray();
         $parent = Document::getByPath($def['parent']);
         unset($def['parent']);
         if (!$parent) {
             $parent = Document::getById(1);
         }
         $path = $parent->getFullPath() . '/' . $def['key'];
         if (Document\Service::pathExists($path)) {
             $doc = Document::getByPath($path);
         } else {
             $docClass = '\\Pimcore\\Model\\Document\\' . ucfirst($def['type']);
             /** @var Document $doc */
             $doc = $docClass::create($parent->getId(), $def, false);
             $doc->setUserOwner(self::getUser()->getId());
             $doc->setUserModification(self::getUser()->getId());
         }
         $doc->setValues($def);
         $doc->setPublished(true);
         $doc->save();
     }
 }
All Usage Examples Of Pimcore\Model\Document\Service::pathExists