/**
* @inheritDoc
*/
- public function deleteMessageExpiredAtObject(string $objectType, string $objectId): bool {
+ public function deleteCommentsExpiredAtObject(string $objectType, string $objectId = ''): bool {
$qb = $this->dbConn->getQueryBuilder();
- $affectedRows = $qb->delete('comments')
+ $qb->delete('comments')
->where($qb->expr()->lt('expire_date',
$qb->createNamedParameter($this->timeFactory->getDateTime(), IQueryBuilder::PARAM_DATE)))
- ->andWhere($qb->expr()->eq('object_type', $qb->createNamedParameter($objectType)))
- ->andWhere($qb->expr()->eq('object_id', $qb->createNamedParameter($objectId)))
- ->executeStatement();
+ ->andWhere($qb->expr()->eq('object_type', $qb->createNamedParameter($objectType)));
+
+ if ($objectId !== '') {
+ $qb->andWhere($qb->expr()->eq('object_id', $qb->createNamedParameter($objectId)));
+ }
+
+ $affectedRows = $qb->executeStatement();
$this->commentsCache = [];
$this->assertTrue($wasSuccessful);
}
- public function testDeleteMessageExpiredAtObject(): void {
+ public function testDeleteCommentsExpiredAtObjectTypeAndId(): void {
$ids = [];
$ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours'));
$ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours'));
$this->assertSame($comment->getObjectType(), 'files');
$this->assertSame($comment->getObjectId(), 'file64');
- $deleted = $manager->deleteMessageExpiredAtObject('files', 'file64');
+ $deleted = $manager->deleteCommentsExpiredAtObject('files', 'file64');
$this->assertTrue($deleted);
$deleted = 0;
// actor info is gone from DB, but when database interaction is alright,
// we still expect to get true back
- $deleted = $manager->deleteMessageExpiredAtObject('files', 'file64');
+ $deleted = $manager->deleteCommentsExpiredAtObject('files', 'file64');
+ $this->assertFalse($deleted);
+ }
+
+ public function testDeleteCommentsExpiredAtObjectType(): void {
+ $ids = [];
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file1', new \DateTime('-2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file2', new \DateTime('-2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime('-2 hours'));
+
+ $manager = new Manager(
+ $this->connection,
+ $this->createMock(LoggerInterface::class),
+ $this->createMock(IConfig::class),
+ Server::get(ITimeFactory::class),
+ new EmojiHelper($this->connection),
+ $this->createMock(IInitialStateService::class)
+ );
+
+ $deleted = $manager->deleteCommentsExpiredAtObject('files');
+ $this->assertTrue($deleted);
+
+ $deleted = 0;
+ $exists = 0;
+ foreach ($ids as $id) {
+ try {
+ $manager->get((string) $id);
+ $exists++;
+ } catch (NotFoundException $e) {
+ $deleted++;
+ }
+ }
+ $this->assertSame($exists, 0);
+ $this->assertSame($deleted, 3);
+
+ // actor info is gone from DB, but when database interaction is alright,
+ // we still expect to get true back
+ $deleted = $manager->deleteCommentsExpiredAtObject('files');
$this->assertFalse($deleted);
}