Added removal of unused tags
This commit is contained in:
parent
76d9e95e4b
commit
5bc73d220e
5 changed files with 46 additions and 4 deletions
1
TODO
1
TODO
|
@ -26,7 +26,6 @@ everything related to users:
|
||||||
- removing
|
- removing
|
||||||
|
|
||||||
everything related to tags:
|
everything related to tags:
|
||||||
- automatic removal of unused tags in backend
|
|
||||||
- tags.json refresh when editing post
|
- tags.json refresh when editing post
|
||||||
- basic tags
|
- basic tags
|
||||||
- mass tag
|
- mass tag
|
||||||
|
|
|
@ -31,4 +31,9 @@ class TagDao extends AbstractDao implements ICrudDao
|
||||||
$arrayEntities = iterator_to_array($query);
|
$arrayEntities = iterator_to_array($query);
|
||||||
return $this->arrayToEntities($arrayEntities);
|
return $this->arrayToEntities($arrayEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteUnused()
|
||||||
|
{
|
||||||
|
$this->deleteBy('usages', 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,10 @@ class PostService
|
||||||
$this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($savedPost));
|
$this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($savedPost));
|
||||||
return $savedPost;
|
return $savedPost;
|
||||||
};
|
};
|
||||||
return $this->transactionManager->commit($transactionFunc);
|
$ret = $this->transactionManager->commit($transactionFunc);
|
||||||
|
$this->tagService->deleteUnusedTags();
|
||||||
|
$this->tagService->exportJson();
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updatePost(\Szurubooru\Entities\Post $post, \Szurubooru\FormData\PostEditFormData $formData)
|
public function updatePost(\Szurubooru\Entities\Post $post, \Szurubooru\FormData\PostEditFormData $formData)
|
||||||
|
@ -167,7 +170,10 @@ class PostService
|
||||||
$this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($post));
|
$this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($post));
|
||||||
return $this->postDao->save($post);
|
return $this->postDao->save($post);
|
||||||
};
|
};
|
||||||
return $this->transactionManager->commit($transactionFunc);
|
$ret = $this->transactionManager->commit($transactionFunc);
|
||||||
|
$this->tagService->deleteUnusedTags();
|
||||||
|
$this->tagService->exportJson();
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updatePostSafety(\Szurubooru\Entities\Post $post, $newSafety)
|
private function updatePostSafety(\Szurubooru\Entities\Post $post, $newSafety)
|
||||||
|
@ -271,7 +277,6 @@ class PostService
|
||||||
$tags[] = $tag;
|
$tags[] = $tag;
|
||||||
}
|
}
|
||||||
$tags = $this->tagService->createTags($tags);
|
$tags = $this->tagService->createTags($tags);
|
||||||
$this->tagService->exportJson();
|
|
||||||
$post->setTags($tags);
|
$post->setTags($tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,15 @@ class TagService
|
||||||
$this->fileService->save('tags.json', $json);
|
$this->fileService->save('tags.json', $json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteUnusedTags()
|
||||||
|
{
|
||||||
|
$transactionFunc = function()
|
||||||
|
{
|
||||||
|
$this->tagDao->deleteUnused();
|
||||||
|
};
|
||||||
|
$this->transactionManager->commit($transactionFunc);
|
||||||
|
}
|
||||||
|
|
||||||
public function createTags(array $tags)
|
public function createTags(array $tags)
|
||||||
{
|
{
|
||||||
$transactionFunc = function() use ($tags)
|
$transactionFunc = function() use ($tags)
|
||||||
|
|
|
@ -35,6 +35,30 @@ final class TagDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
$this->assertEntitiesEqual($expected, $actual);
|
$this->assertEntitiesEqual($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRemovingUnused()
|
||||||
|
{
|
||||||
|
$tag1 = new \Szurubooru\Entities\Tag();
|
||||||
|
$tag1->setName('test1');
|
||||||
|
$tag1->setCreationTime(date('c'));
|
||||||
|
$tag2 = new \Szurubooru\Entities\Tag();
|
||||||
|
$tag2->setName('test2');
|
||||||
|
$tag2->setCreationTime(date('c'));
|
||||||
|
$tagDao = $this->getTagDao();
|
||||||
|
$tagDao->save($tag1);
|
||||||
|
$tagDao->save($tag2);
|
||||||
|
$pdo = $this->databaseConnection->getPDO();
|
||||||
|
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (1, 2)');
|
||||||
|
$tag1 = $tagDao->findById($tag1->getId());
|
||||||
|
$tag2 = $tagDao->findById($tag2->getId());
|
||||||
|
$this->assertEquals(2, count($tagDao->findAll()));
|
||||||
|
$this->assertEquals(0, $tag1->getUsages());
|
||||||
|
$this->assertEquals(1, $tag2->getUsages());
|
||||||
|
$tagDao->deleteUnused();
|
||||||
|
$this->assertEquals(1, count($tagDao->findAll()));
|
||||||
|
$this->assertNull($tagDao->findById($tag1->getId()));
|
||||||
|
$this->assertEntitiesEqual($tag2, $tagDao->findById($tag2->getId()));
|
||||||
|
}
|
||||||
|
|
||||||
private function getTagDao()
|
private function getTagDao()
|
||||||
{
|
{
|
||||||
return new \Szurubooru\Dao\TagDao($this->databaseConnection);
|
return new \Szurubooru\Dao\TagDao($this->databaseConnection);
|
||||||
|
|
Loading…
Reference in a new issue