From 027b98ce76f28d8f6b7b28602c01dc93ebb58c59 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 28 Jun 2015 10:24:40 +0200 Subject: [PATCH] Fixed dangling tags on MySQL after post removal --- src/Upgrades/Upgrade39.php | 22 ++++++++++++++++++++++ src/di.php | 1 + 2 files changed, 23 insertions(+) create mode 100644 src/Upgrades/Upgrade39.php diff --git a/src/Upgrades/Upgrade39.php b/src/Upgrades/Upgrade39.php new file mode 100644 index 00000000..5a4d3077 --- /dev/null +++ b/src/Upgrades/Upgrade39.php @@ -0,0 +1,22 @@ +getPDO(); + + $pdo->exec('DROP TRIGGER IF EXISTS postsDelete'); + + // this triger is needed due to cascade triggers not working in MySQL. + // (specifically, postTagsDelete won't get triggered.) + $pdo->exec(' + CREATE TRIGGER postsDelete AFTER DELETE ON posts + FOR EACH ROW + BEGIN + UPDATE tags SET usages = (SELECT COUNT(1) FROM postTags WHERE tagId = tags.id); + END'); + } +} diff --git a/src/di.php b/src/di.php index ba7c9a29..c9f00a6a 100644 --- a/src/di.php +++ b/src/di.php @@ -55,6 +55,7 @@ return [ $container->get(\Szurubooru\Upgrades\Upgrade36::class), $container->get(\Szurubooru\Upgrades\Upgrade37::class), $container->get(\Szurubooru\Upgrades\Upgrade38::class), + $container->get(\Szurubooru\Upgrades\Upgrade39::class), ]; }),