From a82fb56063132f9700dc372297dc43f71679afbb Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Thu, 27 Jun 2019 13:34:25 -0500 Subject: [PATCH] Added force flag to image deletion event to override trash extension --- core/imageboard/event.php | 6 +++++- ext/trash/main.php | 2 +- tests/bootstrap.php | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/imageboard/event.php b/core/imageboard/event.php index ec663d6b..3064fa03 100644 --- a/core/imageboard/event.php +++ b/core/imageboard/event.php @@ -42,15 +42,19 @@ class ImageDeletionEvent extends Event /** @var Image */ public $image; + /** @var bool */ + public $force = false; + /** * Deletes an image. * * Used by things like tags and comments handlers to * clean out related rows in their tables. */ - public function __construct(Image $image) + public function __construct(Image $image, bool $force = false) { $this->image = $image; + $this->force = $force; } } diff --git a/ext/trash/main.php b/ext/trash/main.php index bda019b7..1c9484d3 100644 --- a/ext/trash/main.php +++ b/ext/trash/main.php @@ -67,7 +67,7 @@ class Trash extends Extension public function onImageDeletion(ImageDeletionEvent $event) { - if($event->image->trash===false) { + if($event->force===false && $event->image->trash===false) { self::set_trash($event->image->id, true); $event->stop_processing = true; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e2bcb800..40166c21 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -167,7 +167,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase { $img = Image::by_id($image_id); if ($img) { - $ide = new ImageDeletionEvent($img); + $ide = new ImageDeletionEvent($img, true); send_event($ide); } }