/**
* @ORM\PreFlush()
*/
public function preUpload()
{
if ($this->file) {
if ($this->file instanceof FileUpload) {
$basename = $this->file->getSanitizedName();
$basename = $this->suggestName($this->getFilePath(), $basename);
$this->setName($basename);
} else {
$basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-');
$basename = $this->suggestName(dirname($this->file->getPathname()), $basename);
$this->setName($basename);
}
if ($this->_oldPath && $this->_oldPath !== $this->path) {
@unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath));
}
if ($this->file instanceof FileUpload) {
$this->file->move($this->getFilePath());
} else {
copy($this->file->getPathname(), $this->getFilePath());
}
return $this->file = NULL;
}
if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) {
$oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path);
if (file_exists($oldFilePath)) {
rename($oldFilePath, $this->getFilePath());
}
}
}