Skip to content

Commit

Permalink
Fix doctrine compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jan 21, 2021
1 parent 4b8d8dd commit ef4ec43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
5 changes: 2 additions & 3 deletions lib/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@

namespace OCA\Activity;

use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use OCA\Activity\Filter\AllFilter;
use OCP\Activity\IEvent;
use OCP\Activity\IExtension;
use OCP\Activity\IFilter;
use OCP\Activity\IManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IL10N;

/**
* @brief Class for managing the data in the activities
Expand Down Expand Up @@ -371,7 +370,7 @@ public function deleteActivities($conditions) {

// Add galera safe delete chunking if using mysql
// Stops us hitting wsrep_max_ws_rows when large row counts are deleted
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
// Then use chunked delete
$max = 100000;
$query = $this->connection->prepare(
Expand Down
12 changes: 6 additions & 6 deletions tests/DataDeleteActivitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

namespace OCA\Activity\Tests;

use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use OCA\Activity\BackgroundJob\ExpireActivities;
use OCA\Activity\Data;
use OCP\Activity\IExtension;
use OCP\DB\IPreparedStatement;
use OCP\IConfig;
use OCP\IUserSession;
use OCP\Activity\IManager;
Expand Down Expand Up @@ -121,7 +121,7 @@ protected function assertUserActivities(array $expected) {
$this->assertTableKeys($expected, $query, 'affecteduser');
}

protected function assertTableKeys(array $expected, Statement $query, string $keyName): void {
protected function assertTableKeys(array $expected, IPreparedStatement $query, string $keyName): void {
$query->execute();

$users = [];
Expand All @@ -144,7 +144,7 @@ public function testChunkingDeleteNotUsedWhenNotOnMysql(): void {
$platform = $this->createMock(SqlitePlatform::class);
$connection->expects($this->once())->method('getDatabasePlatform')->willReturn($platform);

$statement = $this->createMock(Statement::class);
$statement = $this->createMock(IPreparedStatement::class);
// Wont chunk
$statement->expects($this->exactly(0))->method('rowCount')->willReturnOnConsecutiveCalls(100000, 50);
$connection->expects($this->once())->method('prepare')->willReturn($statement);
Expand All @@ -161,10 +161,10 @@ public function testDeleteActivitiesIsChunkedOnMysql(): void {
$timelimit = time() - $ttl;
$activityManager = $this->createMock(\OCP\Activity\IManager::class);
$connection = $this->createMock(\OCP\IDBConnection::class);
$platform = $this->createMock(MySqlPlatform::class);
$platform = $this->createMock(MySQLPlatform::class);
$connection->expects($this->once())->method('getDatabasePlatform')->willReturn($platform);

$statement = $this->createMock(Statement::class);
$statement = $this->createMock(IPreparedStatement::class);
// Will chunk
$statement->expects($this->exactly(2))->method('rowCount')->willReturnOnConsecutiveCalls(100000, 50);
$connection->expects($this->once())->method('prepare')->willReturn($statement);
Expand Down
8 changes: 3 additions & 5 deletions tests/HooksDeleteUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@

namespace OCA\Activity\Tests;

use Doctrine\DBAL\Driver\Statement;
use OCA\Activity\Data;
use OCA\Activity\Hooks;
use OCP\Activity\IExtension;
use OCP\IUserSession;
use OCP\DB\IPreparedStatement;
use OCP\Activity\IManager;

/**
Expand Down Expand Up @@ -79,8 +78,7 @@ protected function setUp(): void {
protected function tearDown(): void {
$data = new Data(
$this->createMock(IManager::class),
\OC::$server->getDatabaseConnection(),
$this->createMock(IUserSession::class)
\OC::$server->getDatabaseConnection()
);
$data->deleteActivities(array(
'type' => 'test',
Expand Down Expand Up @@ -109,7 +107,7 @@ protected function assertUserMailQueue(array $expected): void {
$this->assertTableKeys($expected, $query, 'amq_affecteduser');
}

protected function assertTableKeys(array $expected, Statement $query, string $keyName): void {
protected function assertTableKeys(array $expected, IPreparedStatement $query, string $keyName): void {
$query->execute();

$users = array();
Expand Down

0 comments on commit ef4ec43

Please sign in to comment.