[COMPONENT][Attachment] Wrap delete operations in transactions and correct sequence of deletation
This commit is contained in:
parent
bf4a0008ef
commit
46d121ef7b
@ -22,6 +22,7 @@ declare(strict_types = 1);
|
||||
namespace Component\Attachment;
|
||||
|
||||
use App\Core\Cache;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Event;
|
||||
use App\Core\Modules\Component;
|
||||
use App\Core\Router\RouteLoader;
|
||||
@ -56,13 +57,14 @@ class Attachment extends Component
|
||||
return Event::stop;
|
||||
}
|
||||
|
||||
public function onNoteDeleteRelated(Note &$note): bool
|
||||
public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
|
||||
{
|
||||
Cache::delete("note-attachments-{$note->getId()}");
|
||||
E\AttachmentToNote::removeWhereNoteId($note->getId());
|
||||
foreach ($note->getAttachments() as $attachment) {
|
||||
$attachment->kill();
|
||||
}
|
||||
DB::wrapInTransaction(fn () => E\AttachmentToNote::removeWhereNoteId($note->getId()));
|
||||
Cache::delete("note-attachments-{$note->getId()}");
|
||||
return Event::next;
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ class Attachment extends Entity
|
||||
public function kill(): bool
|
||||
{
|
||||
if ($this->livesDecrementAndGet() <= 0) {
|
||||
return $this->delete();
|
||||
return DB::wrapInTransaction(fn () => $this->delete());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -237,6 +237,7 @@ class Attachment extends Entity
|
||||
|
||||
/**
|
||||
* Attachment delete always removes dependencies, cleanups and flushes
|
||||
* WARNING: Wrap this function in a transaction!
|
||||
*
|
||||
* @see kill() It's more likely that you want to use that rather than call delete directly
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user