Fixed dangling tags on MySQL after post removal
This commit is contained in:
parent
edee487ff9
commit
027b98ce76
2 changed files with 23 additions and 0 deletions
22
src/Upgrades/Upgrade39.php
Normal file
22
src/Upgrades/Upgrade39.php
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Upgrades;
|
||||||
|
use Szurubooru\DatabaseConnection;
|
||||||
|
|
||||||
|
class Upgrade39 implements IUpgrade
|
||||||
|
{
|
||||||
|
public function run(DatabaseConnection $databaseConnection)
|
||||||
|
{
|
||||||
|
$pdo = $databaseConnection->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');
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,6 +55,7 @@ return [
|
||||||
$container->get(\Szurubooru\Upgrades\Upgrade36::class),
|
$container->get(\Szurubooru\Upgrades\Upgrade36::class),
|
||||||
$container->get(\Szurubooru\Upgrades\Upgrade37::class),
|
$container->get(\Szurubooru\Upgrades\Upgrade37::class),
|
||||||
$container->get(\Szurubooru\Upgrades\Upgrade38::class),
|
$container->get(\Szurubooru\Upgrades\Upgrade38::class),
|
||||||
|
$container->get(\Szurubooru\Upgrades\Upgrade39::class),
|
||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue