Skip to content

Commit

Permalink
fix(comments): Reference ID column is now added on upgrade and theref…
Browse files Browse the repository at this point in the history
…ore can be removed

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Dec 13, 2023
1 parent cdc197a commit 09afaa2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
14 changes: 0 additions & 14 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@
use OCP\AppFramework\App;
use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\DB\Events\AddMissingColumnsEvent;
use OCP\DB\Events\AddMissingIndicesEvent;
use OCP\DB\Events\AddMissingPrimaryKeyEvent;
use OCP\DB\Types;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\User\Events\BeforeUserDeletedEvent;
use OCP\User\Events\UserDeletedEvent;
Expand Down Expand Up @@ -300,18 +298,6 @@ public function __construct() {
);
});

$eventDispatcher->addListener(AddMissingColumnsEvent::class, function (AddMissingColumnsEvent $event) {
$event->addMissingColumn(
'comments',
'reference_id',
Types::STRING,
[
'notnull' => false,
'length' => 64,
]
);
});

$eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
$eventDispatcher->addServiceListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
Expand Down
8 changes: 7 additions & 1 deletion tests/lib/Comments/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function testSettersValidInput() {
$creationDT = new \DateTime();
$latestChildDT = new \DateTime('yesterday');
$object = ['type' => 'files', 'id' => 'file64'];
$referenceId = sha1('referenceId');
$metaData = json_encode(['last_edit_actor_id' => 'admin']);

$comment
->setId($id)
Expand All @@ -34,7 +36,9 @@ public function testSettersValidInput() {
->setActor($actor['type'], $actor['id'])
->setCreationDateTime($creationDT)
->setLatestChildDateTime($latestChildDT)
->setObject($object['type'], $object['id']);
->setObject($object['type'], $object['id'])
->setReferenceId($referenceId)
->setMetaData($metaData);

$this->assertSame($id, $comment->getId());
$this->assertSame($parentId, $comment->getParentId());
Expand All @@ -48,6 +52,8 @@ public function testSettersValidInput() {
$this->assertSame($latestChildDT, $comment->getLatestChildDateTime());
$this->assertSame($object['type'], $comment->getObjectType());
$this->assertSame($object['id'], $comment->getObjectId());
$this->assertSame($referenceId, $comment->getReferenceId());
$this->assertSame($metaData, $comment->getMetaData());
}


Expand Down
7 changes: 6 additions & 1 deletion tests/lib/Comments/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ protected function addDatabaseEntry($parentId, $topmostParentId, $creationDT = n
'object_type' => $qb->createNamedParameter('files'),
'object_id' => $qb->createNamedParameter($objectId),
'expire_date' => $qb->createNamedParameter($expireDate, 'datetime'),
'reference_id' => $qb->createNamedParameter('referenceId'),
'meta_data' => $qb->createNamedParameter(json_encode(['last_edit_actor_id' => 'admin'])),
])
->execute();

Expand Down Expand Up @@ -119,6 +121,8 @@ public function testGetComment() {
'latest_child_timestamp' => $qb->createNamedParameter($latestChildDT, 'datetime'),
'object_type' => $qb->createNamedParameter('files'),
'object_id' => $qb->createNamedParameter('file64'),
'reference_id' => $qb->createNamedParameter('referenceId'),
'meta_data' => $qb->createNamedParameter(json_encode(['last_edit_actor_id' => 'admin'])),
])
->execute();

Expand All @@ -137,7 +141,8 @@ public function testGetComment() {
$this->assertSame($comment->getObjectType(), 'files');
$this->assertSame($comment->getObjectId(), 'file64');
$this->assertEquals($comment->getCreationDateTime()->getTimestamp(), $creationDT->getTimestamp());
$this->assertEquals($comment->getLatestChildDateTime(), $latestChildDT);
$this->assertEquals($comment->getReferenceId(), 'referenceId');
$this->assertEquals($comment->getMetaData(), json_encode(['last_edit_actor_id' => 'admin']));
}


Expand Down

0 comments on commit 09afaa2

Please sign in to comment.