Ejemplo n.º 1
0
 /**
  * @return void
  */
 public function save()
 {
     // check if versioning is disabled for this process
     if (self::$disabled) {
         return;
     }
     if (!$this->date) {
         $this->setDate(time());
     }
     $data = $this->getData();
     // if necessary convert the data to save it to filesystem
     if (is_object($data) or is_array($data)) {
         // this is because of lazy loaded element inside documents and objects (eg: multihref, objects, fieldcollections, ...)
         if ($data instanceof Element_Interface) {
             Element_Service::loadAllFields($data);
         }
         $this->setSerialized(true);
         $data->_fulldump = true;
         $dataString = Pimcore_Tool_Serialize::serialize($this->getData());
         unset($this->_fulldump);
     } else {
         $dataString = $data;
     }
     $this->id = $this->getResource()->save();
     // check if directory exists
     $saveDir = dirname($this->getFilePath());
     if (!is_dir($saveDir)) {
         mkdir($saveDir, 0766, true);
     }
     // save data to filesystem
     if (!is_writable(dirname($this->getFilePath())) || is_file($this->getFilePath()) && !is_writable($this->getFilePath())) {
         throw new Exception("Cannot save version for element " . $this->getCid() . " with type " . $this->getCtype() . " because the file " . $this->getFilePath() . " is not writeable.");
     } else {
         file_put_contents($this->getFilePath(), $dataString);
     }
     // only do this in the maintenance job, to improve the speed of mass imports
     //$this->cleanHistory();
 }