Pimcore\Model\Document\PageSnippet::update PHP Method

update() protected method

See also: Document::update
protected update ( ) : void
return void
    protected function update()
    {
        // update elements
        $this->getElements();
        $this->getDao()->deleteAllElements();
        if (is_array($this->getElements()) and count($this->getElements()) > 0) {
            foreach ($this->getElements() as $name => $element) {
                if (!$element->getInherited()) {
                    $element->setDao(null);
                    $element->setDocumentId($this->getId());
                    $element->save();
                }
            }
        }
        // scheduled tasks are saved in $this->saveVersion();
        // load data which must be requested
        $this->getProperties();
        $this->getElements();
        // update this
        parent::update();
        // save version if needed
        $this->saveVersion(false, false);
    }

Usage Example

Beispiel #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();
     }
 }