Fixed dangling tags on MySQL after post removal

This commit is contained in:
rr- 2015-06-28 10:24:40 +02:00
parent edee487ff9
commit 027b98ce76
2 changed files with 23 additions and 0 deletions

View 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');
}
}

View file

@ -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),
]; ];
}), }),