From 2ede81e1d81557f2cbcbe205fb0fe2fba49acd77 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 9 Nov 2014 16:12:36 +0100 Subject: [PATCH] Fixed default tag category --- src/Controllers/ViewProxies/TagViewProxy.php | 2 +- src/Entities/Tag.php | 2 +- src/Upgrades/Upgrade32.php | 19 +++++++++++++++++++ src/di.php | 1 + tests/Dao/TagDaoFilterTest.php | 2 -- 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/Upgrades/Upgrade32.php diff --git a/src/Controllers/ViewProxies/TagViewProxy.php b/src/Controllers/ViewProxies/TagViewProxy.php index 6d58a3f4..baf2f8c6 100644 --- a/src/Controllers/ViewProxies/TagViewProxy.php +++ b/src/Controllers/ViewProxies/TagViewProxy.php @@ -32,7 +32,7 @@ class TagViewProxy extends AbstractViewProxy $result->name = $tag->getName(); $result->usages = $tag->getUsages(); $result->banned = $tag->isBanned(); - $result->category = !empty($tag->getCategory()) ? $tag->getCategory() : 'default'; + $result->category = $tag->getCategory(); if (!empty($config[self::FETCH_IMPLICATIONS])) $result->implications = $this->fromArray($tag->getImpliedTags()); diff --git a/src/Entities/Tag.php b/src/Entities/Tag.php index d6943776..d186fc40 100644 --- a/src/Entities/Tag.php +++ b/src/Entities/Tag.php @@ -6,7 +6,7 @@ final class Tag extends Entity private $name; private $creationTime; private $banned = false; - private $category; + private $category = 'default'; const LAZY_LOADER_IMPLIED_TAGS = 'implications'; const LAZY_LOADER_SUGGESTED_TAGS = 'suggestions'; diff --git a/src/Upgrades/Upgrade32.php b/src/Upgrades/Upgrade32.php new file mode 100644 index 00000000..4d2a2a6c --- /dev/null +++ b/src/Upgrades/Upgrade32.php @@ -0,0 +1,19 @@ +getPDO(); + + $pdo->exec(' + UPDATE snapshots SET + data = REPLACE(data, \'"category":null\', \'"category":"default"\'), + dataDifference = REPLACE(dataDifference, \'"category",null\', \'"category","default"\')'); + + $pdo->exec('UPDATE tags SET category = \'default\' WHERE category IS NULL'); + $pdo->exec('ALTER TABLE tags CHANGE category category VARCHAR(25) NOT NULL DEFAULT \'default\''); + } +} diff --git a/src/di.php b/src/di.php index c9b90ac1..4180a7fe 100644 --- a/src/di.php +++ b/src/di.php @@ -48,6 +48,7 @@ return [ $container->get(\Szurubooru\Upgrades\Upgrade29::class), $container->get(\Szurubooru\Upgrades\Upgrade30::class), $container->get(\Szurubooru\Upgrades\Upgrade31::class), + $container->get(\Szurubooru\Upgrades\Upgrade32::class), ]; }), diff --git a/tests/Dao/TagDaoFilterTest.php b/tests/Dao/TagDaoFilterTest.php index f228a772..e6209a09 100644 --- a/tests/Dao/TagDaoFilterTest.php +++ b/tests/Dao/TagDaoFilterTest.php @@ -16,7 +16,6 @@ final class TagDaoFilterTest extends AbstractDatabaseTestCase $tag1 = $this->getTestTag('test 1'); $tag2 = $this->getTestTag('test 2'); $tag3 = $this->getTestTag('test 3'); - $tag1->setCategory(null); $tag2->setCategory('misc'); $tag3->setCategory('other'); $tagDao = $this->getTagDao(); @@ -40,7 +39,6 @@ final class TagDaoFilterTest extends AbstractDatabaseTestCase $tag1 = $this->getTestTag('test 1'); $tag2 = $this->getTestTag('test 2'); $tag3 = $this->getTestTag('test 3'); - $tag1->setCategory(null); $tag2->setCategory('misc'); $tag3->setCategory('other'); $tagDao = $this->getTagDao();