Pimcore\Model\Document::update PHP Method

update() protected method

protected update ( )
    protected function update()
    {
        $disallowedKeysInFirstLevel = ["install", "admin", "webservice", "plugin"];
        if ($this->getParentId() == 1 && in_array($this->getKey(), $disallowedKeysInFirstLevel)) {
            throw new \Exception("Key: " . $this->getKey() . " is not allowed in first level (root-level)");
        }
        // set index if null
        if ($this->getIndex() === null) {
            $this->setIndex($this->getDao()->getNextIndex());
        }
        // save properties
        $this->getProperties();
        $this->getDao()->deleteAllProperties();
        if (is_array($this->getProperties()) and count($this->getProperties()) > 0) {
            foreach ($this->getProperties() as $property) {
                if (!$property->getInherited()) {
                    $property->setDao(null);
                    $property->setCid($this->getId());
                    $property->setCtype("document");
                    $property->setCpath($this->getRealFullPath());
                    $property->save();
                }
            }
        }
        // save dependencies
        $d = $this->getDependencies();
        $d->clean();
        foreach ($this->resolveDependencies() as $requirement) {
            if ($requirement["id"] == $this->getId() && $requirement["type"] == "document") {
                // dont't add a reference to yourself
                continue;
            } else {
                $d->addRequirement($requirement["id"], $requirement["type"]);
            }
        }
        $d->save();
        $this->getDao()->update();
        //set object to registry
        \Zend_Registry::set("document_" . $this->getId(), $this);
    }

Usage Example

Example #1
0
 /**
  *
  */
 protected function update()
 {
     $oldPath = $this->getDao()->getCurrentFullPath();
     parent::update();
     $config = \Pimcore\Config::getSystemConfig();
     if ($oldPath && $config->documents->createredirectwhenmoved && $oldPath != $this->getFullPath()) {
         // create redirect for old path
         $redirect = new Redirect();
         $redirect->setTarget($this->getId());
         $redirect->setSource("@" . $oldPath . "/?@");
         $redirect->setStatusCode(301);
         $redirect->setExpiry(time() + 86400 * 60);
         // this entry is removed automatically after 60 days
         $redirect->save();
     }
 }
All Usage Examples Of Pimcore\Model\Document::update