diff --git a/Web/Models/Entities/Media.php b/Web/Models/Entities/Media.php index 872e7306..d86e6441 100644 --- a/Web/Models/Entities/Media.php +++ b/Web/Models/Entities/Media.php @@ -89,4 +89,21 @@ abstract class Media extends Postable $this->stateChanges("hash", $hash); } + + function delete(bool $softly = true): void + { + $deleteQuirk = ovkGetQuirk("blobs.erase-upon-deletion"); + if($deleteQuirk === 2 || ($deleteQuirk === 1 && !$softly)) + @unlink($this->getFileName()); + + parent::delete($softly); + } + + function undelete(): void + { + if(ovkGetQuirk("blobs.erase-upon-deletion") === 2) + throw new \LogicException("Can't undelete model which is tied to blob, because of config constraint (quriks.yml:blobs.erase-upon-deletion)"); + + parent::undelete(); + } } diff --git a/quirks.yml b/quirks.yml index e2e5473a..b97ded93 100644 --- a/quirks.yml +++ b/quirks.yml @@ -12,3 +12,16 @@ # + Set this option to 1 if you want to use quirky OpenVK behaviour # + Set this option to 0 if you want to use the canonical VK behaviour profile.rating-bar-behaviour: 0 + +# Blob deletion behaviour +# Current VK and old OpenVK don't delete files automatically, +# thus leaving ability to access user-deleted medias by direct URL. +# This config option allows to change this. +# +# Possible values: +# + Set this option to 2 if you want to delete files upon user-initiated deletion +# (this option will prohibit restoring any deleted media) +# + Set this option to 1 if you want to delete files once they're removed from DB completely +# (this option most likely won't have any meaningful effect, please use option 2) +# + Set this option to 0 if you want to use quirky VK and OpenVK behaviour +blobs.erase-upon-deletion: 0