[Attachment] Allow to delete the associated file
This commit is contained in:
parent
508f1f8796
commit
78c5c4b084
@ -71,7 +71,6 @@ class Attachment extends Entity
|
|||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function getLives(): int
|
public function getLives(): int
|
||||||
{
|
{
|
||||||
return $this->lives;
|
return $this->lives;
|
||||||
@ -205,6 +204,28 @@ class Attachment extends Entity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attachment delete always removes dependencies, cleanups and flushes
|
||||||
|
*/
|
||||||
|
public function deleteStorage(): bool
|
||||||
|
{
|
||||||
|
if (!is_null($filepath = $this->getPath())) {
|
||||||
|
if (file_exists($filepath)) {
|
||||||
|
if (@unlink($filepath) === false) {
|
||||||
|
Log::error("Failed deleting file for attachment with id={$this->getId()} at {$filepath}.");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
$this->setFilename(null);
|
||||||
|
DB::persist($this);
|
||||||
|
DB::flush();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log::warning("File for attachment with id={$this->getId()} at {$filepath} was already deleted when I was going to handle it.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attachment delete always removes dependencies, cleanups and flushes
|
* Attachment delete always removes dependencies, cleanups and flushes
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user