Pimcore\Model\Element\Recyclebin\Item::save PHP Method

save() public method

public save ( User $user = null ) : void
$user User
return void
    public function save($user = null)
    {
        if ($this->getElement() instanceof Element\ElementInterface) {
            $this->setType(Element\Service::getElementType($this->getElement()));
        }
        $this->setSubtype($this->getElement()->getType());
        $this->setPath($this->getElement()->getRealFullPath());
        $this->setDate(time());
        $this->loadChilds($this->getElement());
        if ($user instanceof Model\User) {
            $this->setDeletedby($user->getName());
        }
        // serialize data
        Element\Service::loadAllFields($this->element);
        $data = Serialize::serialize($this->getElement());
        $this->getDao()->save();
        if (!is_dir(PIMCORE_RECYCLEBIN_DIRECTORY)) {
            File::mkdir(PIMCORE_RECYCLEBIN_DIRECTORY);
        }
        File::put($this->getStoreageFile(), $data);
        $saveBinaryData = function ($element, $rec, $scope) {
            // assets are kina special because they can contain massive amount of binary data which isn't serialized, we create separate files for them
            if ($element instanceof Asset) {
                if ($element->getType() != "folder") {
                    $handle = fopen($scope->getStorageFileBinary($element), "w", false, File::getContext());
                    $src = $element->getStream();
                    stream_copy_to_stream($src, $handle);
                    fclose($handle);
                }
                $children = $element->getChilds();
                foreach ($children as $child) {
                    $rec($child, $rec, $scope);
                }
            }
        };
        $saveBinaryData($this->getElement(), $saveBinaryData, $this);
        @chmod($this->getStoreageFile(), File::getDefaultMode());
    }