/** * @return void */ protected function update() { if (!$this->getFilename() && $this->getId() != 1) { $this->delete(); throw new Exception("Asset requires filename, asset with id " . $this->getId() . " deleted"); } // set date $this->setModificationDate(time()); // save data $conf = Pimcore_Config::getSystemConfig(); // create foldertree $destinationPath = $this->getFileSystemPath(); if (!is_dir(dirname($destinationPath))) { mkdir(dirname($destinationPath), self::$chmod, true); } if ($this->_oldPath) { rename(PIMCORE_ASSET_DIRECTORY . $this->_oldPath, $this->getFileSystemPath()); } if ($this->getType() != "folder") { // get data $this->getData(); // remove if exists if (is_file($destinationPath)) { unlink($destinationPath); } file_put_contents($destinationPath, $this->getData()); chmod($destinationPath, self::$chmod); // check file exists if (!is_file($destinationPath)) { throw new Exception("couldn't create new asset"); } // set mime type $mimetype = MIME_Type::autoDetect($this->getFileSystemPath()); $this->setMimetype($mimetype); // set type $this->setTypeFromMapping(); // update scheduled tasks $this->saveScheduledTasks(); // create version $this->getData(); // load data from filesystem to put it into the version $version = new Version(); $version->setCid($this->getId()); $version->setCtype("asset"); $version->setDate($this->getModificationDate()); $version->setUserId($this->getUserModification()); $version->setData($this); $version->save(); } // save properties $this->getProperties(); $this->getResource()->deleteAllProperties(); if (is_array($this->getProperties()) and count($this->getProperties()) > 0) { foreach ($this->getProperties() as $property) { if (!$property->getInherited()) { $property->setResource(null); $property->setCid($this->getId()); $property->setCpath($this->getPath() . $this->getKey()); $property->save(); } } } // save permissions $this->getPermissions(); if (is_array($this->permissions)) { // remove all permissions $this->getResource()->deleteAllPermissions(); foreach ($this->permissions as $permission) { $permission->setId(null); $permission->setCid($this->getId()); $permission->setCpath($this->getFullPath()); $permission->save(); } } // save dependencies $d = $this->getDependencies(); $d->clean(); foreach ($this->resolveDependencies() as $requirement) { if ($requirement["id"] == $this->getId() && $requirement["type"] == "asset") { // dont't add a reference to yourself continue; } else { $d->addRequirement($requirement["id"], $requirement["type"]); } } $d->save(); $this->getResource()->update(); if ($this->_oldPath) { $this->getResource()->updateChildsPaths($this->_oldPath); } $this->clearDependedCache(); //set object to registry Zend_Registry::set("asset_" . $this->getId(), $this); Pimcore_API_Plugin_Broker::getInstance()->postUpdateAsset($this); }
/** * Save the current object as version * * @return void */ public function saveVersion($setModificationDate = true, $callPluginHook = true) { // hook should be also called if "save only new version" is selected if ($callPluginHook) { Pimcore_API_Plugin_Broker::getInstance()->preUpdateDocument($this); } // set date if ($setModificationDate) { $this->setModificationDate(time()); } // scheduled tasks are saved always, they are not versioned! $this->saveScheduledTasks(); // create version $version = new Version(); $version->setCid($this->getId()); $version->setCtype("document"); $version->setDate($this->getModificationDate()); $version->setUserId($this->getUserModification()); $version->setData($this); $version->save(); // hook should be also called if "save only new version" is selected if ($callPluginHook) { Pimcore_API_Plugin_Broker::getInstance()->postUpdateDocument($this); } }
/** * $directCall is true when the method is called from outside (eg. directly in the controller "save only version") * it is false when the method is called by $this->update() * @param bool $setModificationDate * @param bool $directCall * @return Version */ public function saveVersion($setModificationDate = true, $directCall = true) { if ($setModificationDate) { $this->setO_modificationDate(time()); } // hook should be also called if "save only new version" is selected if ($directCall) { Pimcore_API_Plugin_Broker::getInstance()->preUpdateObject($this); } // scheduled tasks are saved always, they are not versioned! if ($directCall) { $this->saveScheduledTasks(); } $version = null; // only create a new version if there is at least 1 allowed if (Pimcore_Config::getSystemConfig()->objects->versions) { // create version $version = new Version(); $version->setCid($this->getO_Id()); $version->setCtype("object"); $version->setDate($this->getO_modificationDate()); $version->setUserId($this->getO_userModification()); $version->setData($this); $version->save(); } // hook should be also called if "save only new version" is selected if ($directCall) { Pimcore_API_Plugin_Broker::getInstance()->postUpdateObject($this); } return $version; }
/** * Save the current object as version * * @return void */ public function saveVersion($setModificationDate = true) { // set date if ($setModificationDate) { $this->setModificationDate(time()); } // scheduled tasks are saved always, they are not versioned! $this->saveScheduledTasks(); // create version $version = new Version(); $version->setCid($this->getId()); $version->setCtype("document"); $version->setDate($this->getModificationDate()); $version->setUserId($this->getUserModification()); $version->setData($this); $version->save(); }