Skip to content

Commit

Permalink
Restored AuditReader::getAuditsCount() which was removed by error i…
Browse files Browse the repository at this point in the history
…n `3.2.0`
  • Loading branch information
DamienHarper committed Dec 2, 2019
1 parent e3309cb commit 6bfc118
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.2.1] - 2019-12-02

### Changes
* Restored `AuditReader::getAuditsCount()` which was removed by error in `3.2.0`


## [3.2.0] - 2019-12-02

### Changes
Expand Down
26 changes: 26 additions & 0 deletions src/DoctrineAuditBundle/Reader/AuditReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ public function getAuditsPager(string $entity, $id = null, int $page = 1, int $p
];
}

/**
* Returns the amount of audited entries/operations.
*
* @param string $entity
* @param null|int|string $id
*
* @throws AccessDeniedException
* @throws InvalidArgumentException
*
* @return int
*/
public function getAuditsCount(string $entity, $id = null): int
{
$queryBuilder = $this->getAuditsQueryBuilder($entity, $id);

$result = $queryBuilder
->resetQueryPart('select')
->resetQueryPart('orderBy')
->select('COUNT(id)')
->execute()
->fetchColumn(0)
;

return false === $result ? 0 : $result;
}

/**
* @param string $entity
* @param string $id
Expand Down
10 changes: 10 additions & 0 deletions tests/DoctrineAuditBundle/Reader/AuditReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ public function testGetAuditsPager(): void
self::assertTrue($pager['haveToPaginate'], 'pager has to paginate.');
}

public function testGetAuditsCount(): void
{
$reader = $this->getReader($this->getAuditConfiguration());

/** @var AuditEntry[] $audits */
$count = $reader->getAuditsCount(Author::class, null);

self::assertSame(5, $count, 'count is ok.');
}

/**
* @depends testGetAudits
*/
Expand Down

0 comments on commit 6bfc118

Please sign in to comment.