Added creation time to tags
This commit is contained in:
parent
9379b4945a
commit
731eb6561b
8 changed files with 42 additions and 6 deletions
|
@ -9,6 +9,7 @@ class TagEntityConverter extends AbstractEntityConverter implements IEntityConve
|
||||||
[
|
[
|
||||||
'id' => $entity->getId(),
|
'id' => $entity->getId(),
|
||||||
'name' => $entity->getName(),
|
'name' => $entity->getName(),
|
||||||
|
'creationTime' => $this->entityTimeToDbTime($entity->getCreationTime()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ class TagEntityConverter extends AbstractEntityConverter implements IEntityConve
|
||||||
{
|
{
|
||||||
$entity = new \Szurubooru\Entities\Tag($array['id']);
|
$entity = new \Szurubooru\Entities\Tag($array['id']);
|
||||||
$entity->setName($array['name']);
|
$entity->setName($array['name']);
|
||||||
|
$entity->setCreationTime($this->dbTimeToEntityTime($array['creationTime']));
|
||||||
$entity->setMeta(\Szurubooru\Entities\Tag::META_USAGES, intval($array['usages']));
|
$entity->setMeta(\Szurubooru\Entities\Tag::META_USAGES, intval($array['usages']));
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Szurubooru\Entities;
|
||||||
final class Tag extends Entity
|
final class Tag extends Entity
|
||||||
{
|
{
|
||||||
private $name;
|
private $name;
|
||||||
|
private $creationTime;
|
||||||
|
|
||||||
const META_USAGES = 'usages';
|
const META_USAGES = 'usages';
|
||||||
|
|
||||||
|
@ -17,8 +18,19 @@ final class Tag extends Entity
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCreationTime()
|
||||||
|
{
|
||||||
|
return $this->creationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreationTime($creationTime)
|
||||||
|
{
|
||||||
|
$this->creationTime = $creationTime;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUsages()
|
public function getUsages()
|
||||||
{
|
{
|
||||||
return $this->getMeta(self::META_USAGES);
|
return $this->getMeta(self::META_USAGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ class TagService
|
||||||
{
|
{
|
||||||
$tag = new \Szurubooru\Entities\Tag;
|
$tag = new \Szurubooru\Entities\Tag;
|
||||||
$tag->setName($tagName);
|
$tag->setName($tagName);
|
||||||
|
$tag->setCreationTime($this->timeService->getCurrentTime());
|
||||||
$tagsToCreate[] = $tag;
|
$tagsToCreate[] = $tag;
|
||||||
}
|
}
|
||||||
$createdTags = $this->tagDao->batchSave($tagsToCreate);
|
$createdTags = $this->tagDao->batchSave($tagsToCreate);
|
||||||
|
|
12
src/Upgrades/Upgrade18.php
Normal file
12
src/Upgrades/Upgrade18.php
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Upgrades;
|
||||||
|
|
||||||
|
class Upgrade18 implements IUpgrade
|
||||||
|
{
|
||||||
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
||||||
|
{
|
||||||
|
$pdo = $databaseConnection->getPDO();
|
||||||
|
|
||||||
|
$pdo->exec('ALTER TABLE tags ADD COLUMN creationTime TIMESTAMP NOT NULL DEFAULT 0');
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,6 +33,7 @@ return [
|
||||||
$container->get(\Szurubooru\Upgrades\Upgrade15::class),
|
$container->get(\Szurubooru\Upgrades\Upgrade15::class),
|
||||||
$container->get(\Szurubooru\Upgrades\Upgrade16::class),
|
$container->get(\Szurubooru\Upgrades\Upgrade16::class),
|
||||||
$container->get(\Szurubooru\Upgrades\Upgrade17::class),
|
$container->get(\Szurubooru\Upgrades\Upgrade17::class),
|
||||||
|
$container->get(\Szurubooru\Upgrades\Upgrade18::class),
|
||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
|
@ -143,8 +143,10 @@ final class PostDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
$tag1 = new \Szurubooru\Entities\Tag();
|
$tag1 = new \Szurubooru\Entities\Tag();
|
||||||
$tag1->setName('tag1');
|
$tag1->setName('tag1');
|
||||||
|
$tag1->setCreationTime(date('c'));
|
||||||
$tag2 = new \Szurubooru\Entities\Tag();
|
$tag2 = new \Szurubooru\Entities\Tag();
|
||||||
$tag2->setName('tag2');
|
$tag2->setName('tag2');
|
||||||
|
$tag2->setCreationTime(date('c'));
|
||||||
$this->tagDao->save($tag1);
|
$this->tagDao->save($tag1);
|
||||||
$this->tagDao->save($tag2);
|
$this->tagDao->save($tag2);
|
||||||
$testTags = ['tag1' => $tag1, 'tag2' => $tag2];
|
$testTags = ['tag1' => $tag1, 'tag2' => $tag2];
|
||||||
|
|
|
@ -15,8 +15,8 @@ final class TagDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
$pdo = $this->databaseConnection->getPDO();
|
$pdo = $this->databaseConnection->getPDO();
|
||||||
|
|
||||||
$pdo->exec('INSERT INTO tags(id, name) VALUES (1, \'test1\')');
|
$pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (1, \'test1\', \'2014-10-01 00:00:00\')');
|
||||||
$pdo->exec('INSERT INTO tags(id, name) VALUES (2, \'test2\')');
|
$pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (2, \'test2\', \'2014-10-01 00:00:00\')');
|
||||||
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (5, 1)');
|
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (5, 1)');
|
||||||
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (6, 1)');
|
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (6, 1)');
|
||||||
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (5, 2)');
|
$pdo->exec('INSERT INTO postTags(postId, tagId) VALUES (5, 2)');
|
||||||
|
@ -24,8 +24,11 @@ final class TagDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
|
|
||||||
$tag1 = new \Szurubooru\Entities\Tag(1);
|
$tag1 = new \Szurubooru\Entities\Tag(1);
|
||||||
$tag1->setName('test1');
|
$tag1->setName('test1');
|
||||||
|
$tag1->setCreationTime(date('c', mktime(0, 0, 0, 10, 1, 2014)));
|
||||||
$tag2 = new \Szurubooru\Entities\Tag(2);
|
$tag2 = new \Szurubooru\Entities\Tag(2);
|
||||||
$tag2->setName('test2');
|
$tag2->setName('test2');
|
||||||
|
$tag2->setCreationTime(date('c', mktime(0, 0, 0, 10, 1, 2014)));
|
||||||
|
|
||||||
$expected = [
|
$expected = [
|
||||||
$tag1->getId() => $tag1,
|
$tag1->getId() => $tag1,
|
||||||
$tag2->getId() => $tag2,
|
$tag2->getId() => $tag2,
|
||||||
|
@ -39,6 +42,7 @@ final class TagDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
$tag1 = new \Szurubooru\Entities\Tag();
|
$tag1 = new \Szurubooru\Entities\Tag();
|
||||||
$tag1->setName('test');
|
$tag1->setName('test');
|
||||||
|
$tag1->setCreationTime(date('c'));
|
||||||
$this->fileServiceMock->expects($this->once())->method('save')->with('tags.json', '{"test":0}');
|
$this->fileServiceMock->expects($this->once())->method('save')->with('tags.json', '{"test":0}');
|
||||||
$tagDao = $this->getTagDao();
|
$tagDao = $this->getTagDao();
|
||||||
$tagDao->save($tag1);
|
$tagDao->save($tag1);
|
||||||
|
@ -48,8 +52,10 @@ final class TagDaoTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
$tag1 = new \Szurubooru\Entities\Tag();
|
$tag1 = new \Szurubooru\Entities\Tag();
|
||||||
$tag1->setName('test1');
|
$tag1->setName('test1');
|
||||||
|
$tag1->setCreationTime(date('c'));
|
||||||
$tag2 = new \Szurubooru\Entities\Tag();
|
$tag2 = new \Szurubooru\Entities\Tag();
|
||||||
$tag2->setName('test2');
|
$tag2->setName('test2');
|
||||||
|
$tag2->setCreationTime(date('c'));
|
||||||
$this->fileServiceMock->expects($this->once())->method('save')->with('tags.json', '{"test1":0,"test2":0}');
|
$this->fileServiceMock->expects($this->once())->method('save')->with('tags.json', '{"test1":0,"test2":0}');
|
||||||
$tagDao = $this->getTagDao();
|
$tagDao = $this->getTagDao();
|
||||||
$tagDao->batchSave([$tag1, $tag2]);
|
$tagDao->batchSave([$tag1, $tag2]);
|
||||||
|
|
|
@ -27,8 +27,8 @@ class TagServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
public function testCreatingTagsWhenAllExist()
|
public function testCreatingTagsWhenAllExist()
|
||||||
{
|
{
|
||||||
$pdo = $this->databaseConnection->getPDO();
|
$pdo = $this->databaseConnection->getPDO();
|
||||||
$pdo->exec('INSERT INTO tags(id, name) VALUES (1, \'test1\')');
|
$pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (1, \'test1\', \'2014-10-01 00:00:00\')');
|
||||||
$pdo->exec('INSERT INTO tags(id, name) VALUES (2, \'test2\')');
|
$pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (2, \'test2\', \'2014-10-01 00:00:00\')');
|
||||||
|
|
||||||
$tag1 = new \Szurubooru\Entities\Tag();
|
$tag1 = new \Szurubooru\Entities\Tag();
|
||||||
$tag1->setName('test1');
|
$tag1->setName('test1');
|
||||||
|
@ -47,8 +47,8 @@ class TagServiceTest extends \Szurubooru\Tests\AbstractDatabaseTestCase
|
||||||
public function testCreatingTagsWhenSomeExist()
|
public function testCreatingTagsWhenSomeExist()
|
||||||
{
|
{
|
||||||
$pdo = $this->databaseConnection->getPDO();
|
$pdo = $this->databaseConnection->getPDO();
|
||||||
$pdo->exec('INSERT INTO tags(id, name) VALUES (1, \'test1\')');
|
$pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (1, \'test1\', \'2014-10-01 00:00:00\')');
|
||||||
$pdo->exec('INSERT INTO tags(id, name) VALUES (2, \'test2\')');
|
$pdo->exec('INSERT INTO tags(id, name, creationTime) VALUES (2, \'test2\', \'2014-10-01 00:00:00\')');
|
||||||
|
|
||||||
$tag1 = new \Szurubooru\Entities\Tag();
|
$tag1 = new \Szurubooru\Entities\Tag();
|
||||||
$tag1->setName('test1');
|
$tag1->setName('test1');
|
||||||
|
|
Loading…
Reference in a new issue