/** * Update the mapped file for Entity (obj) * * @param \Doctrine\ORM\Event\PreUpdateEventArgs $args */ public function preUpdate(PreUpdateEventArgs $args) { $mappings = $this->mappingFactory->fromEventArgs($args); foreach ($mappings as $mapping) { //Uploaded or setted file $file = $mapping->getFilePropertyValue(); $currentFileData = $args->hasChangedField($mapping->getPropertyName()) ? $args->getOldValue($mapping->getPropertyName()) : null; //If no new file if (is_null($file) || !$file instanceof File) { //Preserve old fileData if current file exists, else null if ($currentFileData) { $mapping->setFileDataPropertyValue($this->fileStorage->checkFileExists($currentFileData) ? $currentFileData : null); } } else { if ($file instanceof \Iphp\FileStoreBundle\File\File && $file->isDeleted()) { if ($this->fileStorage->removeFile($currentFileData)) { $mapping->setFileDataPropertyValue(null); } } else { if ($currentFileData && !$this->fileStorage->isSameFile($file, $currentFileData)) { $this->fileStorage->removeFile($currentFileData); } $fileData = $this->fileStorage->upload($mapping, $file); $mapping->setFileDataPropertyValue($fileData); } } } $this->dataStorage->recomputeChangeSet($args); }
/** * Update the mapped file for Entity (obj) * * @param \Doctrine\Common\EventArgs $args */ public function preUpdate(\Doctrine\Common\EventArgs $args) { //All mappings from updated object $mappings = $this->getMappingsFromArgs($args); foreach ($mappings as $mapping) { if ($mapping->isUseOneProperty()) { $this->updateUseOneProperties($args, $mapping); } else { $this->updateSeparateProperties($args, $mapping); } } $this->dataStorage->recomputeChangeSet($args); }