Skip to content

Commit ab4c1f9

Browse files
feat: oc11 (#1229)
1 parent bc5b42d commit ab4c1f9

12 files changed

Lines changed: 75 additions & 77 deletions

.drone.star

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ config = {
6060
"multipleVersions": {
6161
"phpVersions": [
6262
DEFAULT_PHP_VERSION,
63-
"7.3",
6463
],
6564
},
6665
},

appinfo/Migrations/Version20161122092159.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Doctrine\DBAL\Platforms\OraclePlatform;
66
use Doctrine\DBAL\Schema\Schema;
77
use Doctrine\DBAL\Types\Type;
8+
use Doctrine\DBAL\Types\Types;
89
use OCP\Migration\ISchemaMigration;
910

1011
class Version20161122092159 implements ISchemaMigration {
@@ -18,15 +19,17 @@ public function changeSchema(Schema $schema, array $options) {
1819
$table = $schema->getTable($tableName);
1920
// we only apply this step if the columns is not yet a CLOB
2021
/* @phan-suppress-next-line PhanDeprecatedClassConstant */
21-
if ($table->getColumn('subjectparams')->getType() === Type::getType(Type::TEXT)) {
22+
if ($table->getColumn('subjectparams')->getType() === Type::getType(Types::TEXT)) {
2223
return;
2324
}
2425

2526
if (\OC::$server->getDatabaseConnection()->getDatabasePlatform() instanceof OraclePlatform) {
2627
return;
2728
}
2829
$table = $schema->getTable($tableName);
30+
/* @phan-suppress-next-line PhanDeprecatedFunction */
2931
$table->changeColumn('subjectparams', ['type' => Type::getType('text')]);
32+
/* @phan-suppress-next-line PhanDeprecatedFunction */
3033
$table->changeColumn('messageparams', ['type' => Type::getType('text')]);
3134
}
3235
}

appinfo/Migrations/Version20170724182159.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\DBAL\Schema\Schema;
66
use Doctrine\DBAL\Types\Type;
7+
use Doctrine\DBAL\Types\Types;
78
use OCP\Migration\ISchemaMigration;
89

910
/**
@@ -20,27 +21,26 @@ public function changeSchema(Schema $schema, array $options) {
2021

2122
$activityTable = $schema->getTable("{$prefix}activity");
2223
$activityIdColumn = $activityTable->getColumn('activity_id');
23-
/* @phan-suppress-next-line PhanDeprecatedClassConstant */
24-
if ($activityIdColumn->getType()->getName() !== Type::BIGINT) {
25-
/* @phan-suppress-next-line PhanDeprecatedClassConstant */
26-
$activityIdColumn->setType(Type::getType(Type::BIGINT));
24+
/* @phan-suppress-next-line PhanDeprecatedFunction */
25+
if ($activityIdColumn->getType()->getName() !== Types::BIGINT) {
26+
$activityIdColumn->setType(Type::getType(Types::BIGINT));
2727
$activityIdColumn->setOptions(['length' => 20]);
2828
}
2929

3030
$objectIdColumn = $activityTable->getColumn('object_id');
31-
/* @phan-suppress-next-line PhanDeprecatedClassConstant */
32-
if ($objectIdColumn->getType()->getName() !== Type::BIGINT) {
33-
/* @phan-suppress-next-line PhanDeprecatedClassConstant */
34-
$objectIdColumn->setType(Type::getType(Type::BIGINT));
31+
/* @phan-suppress-next-line PhanDeprecatedFunction */
32+
if ($objectIdColumn->getType()->getName() !== Types::BIGINT) {
33+
/* @phan-suppress-next-line PhanDeprecatedFunction */
34+
$objectIdColumn->setType(Type::getType(Types::BIGINT));
3535
$objectIdColumn->setOptions(['length' => 20]);
3636
}
3737

3838
$activityMqTable = $schema->getTable("{$prefix}activity_mq");
3939
$mailIdColumn = $activityMqTable->getColumn('mail_id');
40-
/* @phan-suppress-next-line PhanDeprecatedClassConstant */
41-
if ($mailIdColumn->getType()->getName() !== Type::BIGINT) {
42-
/* @phan-suppress-next-line PhanDeprecatedClassConstant */
43-
$mailIdColumn->setType(Type::getType(Type::BIGINT));
40+
/* @phan-suppress-next-line PhanDeprecatedFunction */
41+
if ($mailIdColumn->getType()->getName() !== Types::BIGINT) {
42+
/* @phan-suppress-next-line PhanDeprecatedFunction */
43+
$mailIdColumn->setType(Type::getType(Types::BIGINT));
4444
$mailIdColumn->setOptions(['length' => 20]);
4545
}
4646
}

appinfo/Migrations/Version20181022150134.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace OCA\activity\Migrations;
2323

2424
use OCP\Migration\ISqlMigration;
25-
use Doctrine\DBAL\Platforms\MySqlPlatform;
25+
use Doctrine\DBAL\Platforms\MySQLPlatform;
2626
use OCP\IDBConnection;
2727

2828
/**
@@ -41,7 +41,7 @@ public function sql(IDBConnection $connection) {
4141
$tableName = "*PREFIX*activity";
4242
$tableName = $connection->getDatabasePlatform()->quoteIdentifier($tableName);
4343

44-
if ($platform instanceof MySqlPlatform) {
44+
if ($platform instanceof MySQLPlatform) {
4545
$sqls = [
4646
"ALTER TABLE $tableName MODIFY COLUMN `subjectparams` LONGTEXT NOT NULL",
4747
"ALTER TABLE $tableName MODIFY COLUMN `messageparams` LONGTEXT NULL",

appinfo/info.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Never again miss an important event related to content in ownCloud and always be
1515
</description>
1616
<licence>AGPL</licence>
1717
<author>Thomas Müller, Frank Karlitschek, Joas Schilling, Tom Needham, Vincent Petry</author>
18-
<version>2.7.3</version>
18+
<version>2.8.0</version>
1919
<default_enable/>
2020
<types>
2121
<filesystem/>
@@ -30,8 +30,7 @@ Never again miss an important event related to content in ownCloud and always be
3030
<screenshot>https://raw.githubusercontent.com/owncloud/screenshots/68550c2b7c53e6309132ca1c7b177adca976db0b/activity/activity.png</screenshot>
3131
<category>tools</category>
3232
<dependencies>
33-
<owncloud min-version="10.11" max-version="10" />
34-
<php min-version="7.4" />
33+
<owncloud min-version="10.15" max-version="11" />
3534
</dependencies>
3635
<background-jobs>
3736
<job>OCA\Activity\BackgroundJob\EmailNotification</job>

lib/Api.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ protected static function getSinceFromOffset($user, $offset) {
8484
->setMaxResults(1);
8585

8686
$result = $query->execute();
87-
/* @phan-suppress-next-line PhanDeprecatedFunction */
88-
$row = $result->fetch();
89-
/* @phan-suppress-next-line PhanDeprecatedFunction */
90-
$result->closeCursor();
87+
$row = $result->fetchAssociative();
88+
$result->free();
9189

9290
if ($row) {
9391
return (int) $row['activity_id'];

lib/Data.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
namespace OCA\Activity;
2525

26-
use Doctrine\DBAL\Platforms\MySqlPlatform;
26+
use Doctrine\DBAL\ArrayParameterType;
27+
use Doctrine\DBAL\Platforms\MySQLPlatform;
2728
use OCP\Activity\IEvent;
2829
use OCP\Activity\IExtension;
2930
use OCP\Activity\IManager;
@@ -207,7 +208,7 @@ public function get(GroupHelper $groupHelper, UserSettings $userSettings, $user,
207208
->from('activity');
208209

209210
$query->where($query->expr()->eq('affecteduser', $query->createNamedParameter($user)))
210-
->andWhere($query->expr()->in('type', $query->createNamedParameter($enabledNotifications, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)));
211+
->andWhere($query->expr()->in('type', $query->createNamedParameter($enabledNotifications, ArrayParameterType::STRING)));
211212
if ($filter === 'self') {
212213
$query->andWhere($query->expr()->eq('user', $query->createNamedParameter($user)));
213214
} elseif ($filter === 'by') {
@@ -273,7 +274,7 @@ public function get(GroupHelper $groupHelper, UserSettings $userSettings, $user,
273274
$result = $query->execute();
274275
$hasMore = false;
275276
/* @phan-suppress-next-line PhanDeprecatedFunction */
276-
while ($row = $result->fetch()) {
277+
while ($row = $result->fetchAssociative()) {
277278
if ($limit === 0) {
278279
$hasMore = true;
279280
break;
@@ -282,8 +283,7 @@ public function get(GroupHelper $groupHelper, UserSettings $userSettings, $user,
282283
$groupHelper->addActivity($row);
283284
$limit--;
284285
}
285-
/* @phan-suppress-next-line PhanDeprecatedFunction */
286-
$result->closeCursor();
286+
$result->free();
287287

288288
return ['data' => $groupHelper->getActivities(), 'has_more' => $hasMore, 'headers' => $headers];
289289
}
@@ -305,10 +305,8 @@ protected function setOffsetFromSince(IQueryBuilder $query, $user, $since, $sort
305305
->from('activity')
306306
->where($queryBuilder->expr()->eq('activity_id', $queryBuilder->createNamedParameter((int) $since)));
307307
$result = $queryBuilder->execute();
308-
/* @phan-suppress-next-line PhanDeprecatedFunction */
309-
$activity = $result->fetch();
310-
/* @phan-suppress-next-line PhanDeprecatedFunction */
311-
$result->closeCursor();
308+
$activity = $result->fetchAssociative();
309+
$result->free();
312310

313311
if ($activity) {
314312
if ($activity['affecteduser'] !== $user) {
@@ -337,10 +335,8 @@ protected function setOffsetFromSince(IQueryBuilder $query, $user, $since, $sort
337335
->orderBy('timestamp', $sort)
338336
->setMaxResults(1);
339337
$result = $fetchQuery->execute();
340-
/* @phan-suppress-next-line PhanDeprecatedFunction */
341-
$activity = $result->fetch();
342-
/* @phan-suppress-next-line PhanDeprecatedFunction */
343-
$result->closeCursor();
338+
$activity = $result->fetchAssociative();
339+
$result->free();
344340

345341
if ($activity !== false) {
346342
return [
@@ -414,22 +410,21 @@ public function deleteActivities($conditions) {
414410

415411
// Add galera safe delete chunking if using mysql
416412
// Stops us hitting wsrep_max_ws_rows when large row counts are deleted
417-
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
413+
if ($this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
418414
// Then use chunked delete
419415
$max = 100000;
420416
$query = $this->connection->prepare(
421417
'DELETE FROM `*PREFIX*activity`' . $sqlWhere . " LIMIT " . $max
422418
);
423419
do {
424-
$query->execute($sqlParameters);
425-
$deleted = $query->rowCount();
420+
$deleted = $query->executeStatement($sqlParameters);
426421
} while ($deleted === $max);
427422
} else {
428-
// Dont use chunked delete - let the DB handle the large row count natively
423+
// Don't use chunked delete - let the DB handle the large row count natively
429424
$query = $this->connection->prepare(
430425
'DELETE FROM `*PREFIX*activity`' . $sqlWhere
431426
);
432-
$query->execute($sqlParameters);
427+
$query->executeStatement($sqlParameters);
433428
}
434429
return null;
435430
}

lib/MailQueueHandler.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ public function getAffectedUsers($limit, $latestSend) {
122122
. ' ORDER BY `amq_trigger_time` ASC',
123123
$limit
124124
);
125-
$query->execute([$latestSend]);
125+
$result = $query->executeQuery([$latestSend]);
126126

127127
$affectedUsers = [];
128-
/* @phan-suppress-next-line PhanDeprecatedFunction */
129-
while ($row = $query->fetch()) {
128+
while ($row = $result->fetchAssociative()) {
130129
$affectedUsers[] = [
131130
'uid' => $row['amq_affecteduser'],
132131
'email' => $row['email']
133132
];
134133
}
134+
$result->free();
135135

136136
return $affectedUsers;
137137
}
@@ -153,13 +153,13 @@ protected function getItemsForUser($affectedUser, $maxTime, $maxNumItems = self:
153153
. ' ORDER BY `amq_timestamp` ASC',
154154
$maxNumItems
155155
);
156-
$query->execute([(int) $maxTime, $affectedUser]);
156+
$result = $query->executeQuery([(int) $maxTime, $affectedUser]);
157157

158158
$activities = [];
159-
/* @phan-suppress-next-line PhanDeprecatedFunction */
160-
while ($row = $query->fetch()) {
159+
while ($row = $result->fetchAssociative()) {
161160
$activities[] = $row;
162161
}
162+
$result->free();
163163

164164
if (isset($activities[$maxNumItems - 1])) {
165165
// Reached the limit, run a query to get the actual count.
@@ -169,14 +169,14 @@ protected function getItemsForUser($affectedUser, $maxTime, $maxNumItems = self:
169169
. ' WHERE `amq_timestamp` <= ? '
170170
. ' AND `amq_affecteduser` = ?'
171171
);
172-
$query->execute([(int) $maxTime, $affectedUser]);
172+
$result = $query->executeQuery([(int) $maxTime, $affectedUser]);
173173

174-
/* @phan-suppress-next-line PhanDeprecatedFunction */
175-
$row = $query->fetch();
174+
$row = $result->fetchAssociative();
175+
$result->free();
176176
return [$activities, $row['actual_count'] - $maxNumItems];
177-
} else {
178-
return [$activities, 0];
179177
}
178+
179+
return [$activities, 0];
180180
}
181181

182182
/**
@@ -327,7 +327,7 @@ public function deleteSentItems(array $affectedUsers, $maxTime) {
327327
. ' WHERE `amq_timestamp` <= ? '
328328
. ' AND `amq_affecteduser` IN (' . $placeholders . ')'
329329
);
330-
$query->execute($queryParams);
330+
$query->executeStatement($queryParams);
331331
}
332332

333333
/**
@@ -348,17 +348,18 @@ public function getAllUsers($limit) {
348348
. ' ORDER BY `amq_trigger_time` ASC',
349349
$limit
350350
);
351-
$query->execute();
351+
$result = $query->executeQuery();
352352

353353
$allUsers = [];
354354
/* @phan-suppress-next-line PhanDeprecatedFunction */
355-
while ($row = $query->fetch()) {
355+
while ($row = $result->fetchAssociative()) {
356356
$allUsers[] = [
357357
'uid' => $row['amq_affecteduser'],
358358
'email' => $row['email'],
359359
'max_mail_id' => $row['max_mail_id'],
360360
];
361361
}
362+
$result->free();
362363

363364
return $allUsers;
364365
}
@@ -417,6 +418,6 @@ public function deleteAllSentItems(array $affectedUsers) {
417418
$query = $this->connection->prepare(
418419
'DELETE FROM `*PREFIX*activity_mq` WHERE ' . $queryParts
419420
);
420-
$query->execute($queryParams);
421+
$query->executeStatement($queryParams);
421422
}
422423
}

tests/unit/ConsumerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ protected function tearDown(): void {
9999
}
100100

101101
protected function deleteTestActivities() {
102-
$query = DB::prepare('DELETE FROM `*PREFIX*activity` WHERE `app` = ?');
103-
$query->execute(['test']);
104-
$query = DB::prepare('DELETE FROM `*PREFIX*activity_mq` WHERE `amq_appid` = ?');
105-
$query->execute(['test']);
102+
$db = \OC::$server->getDatabaseConnection();
103+
$query = $db->prepare('DELETE FROM `*PREFIX*activity` WHERE `app` = ?');
104+
$query->executeStatement(['test']);
105+
$query = $db->prepare('DELETE FROM `*PREFIX*activity_mq` WHERE `amq_appid` = ?');
106+
$query->executeStatement(['test']);
106107
}
107108

108109
public function receiveData() {

tests/unit/DataDeleteActivitiesTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
namespace OCA\Activity\Tests\Unit;
2323

24-
use Doctrine\DBAL\Driver\Statement;
25-
use Doctrine\DBAL\Platforms\MySqlPlatform;
24+
use Doctrine\DBAL\Statement;
25+
use Doctrine\DBAL\Platforms\MySQLPlatform;
2626
use Doctrine\DBAL\Platforms\SqlitePlatform;
2727
use OCA\Activity\Data;
2828
use OCP\Activity\IExtension;
@@ -110,14 +110,14 @@ protected function assertUserActivities($expected) {
110110
$this->assertTableKeys($expected, $query, 'affecteduser');
111111
}
112112

113-
protected function assertTableKeys($expected, Statement $query, $keyName) {
114-
$query->execute();
113+
protected function assertTableKeys($expected, \Doctrine\DBAL\Statement $query, $keyName) {
114+
$result = $query->executeQuery();
115115

116116
$users = [];
117-
while ($row = $query->fetch()) {
117+
while ($row = $result->fetchAssociative()) {
118118
$users[] = $row[$keyName];
119119
}
120-
$query->closeCursor();
120+
$result->free();
121121
$users = \array_unique($users);
122122
\sort($users);
123123
\sort($expected);
@@ -135,7 +135,7 @@ public function testChunkingDeleteNotUsedWhenNotOnMysql() {
135135

136136
$statement = $this->createMock(Statement::class);
137137
// Wont chunk
138-
$statement->expects($this->exactly(0))->method('rowCount')->willReturnOnConsecutiveCalls(100000, 50);
138+
$statement->expects($this->once())->method('executeStatement')->willReturnOnConsecutiveCalls(100050);
139139
$connection->expects($this->once())->method('prepare')->willReturn($statement);
140140

141141
$userSession = $this->createMock(\OCP\IUserSession::class);
@@ -150,12 +150,12 @@ public function testDeleteActivitiesIsChunkedOnMysql() {
150150
$timelimit = \time() - $ttl;
151151
$activityManager = $this->createMock(\OCP\Activity\IManager::class);
152152
$connection = $this->createMock(\OCP\IDBConnection::class);
153-
$platform = $this->createMock(MySqlPlatform::class);
153+
$platform = $this->createMock(MySQLPlatform::class);
154154
$connection->expects($this->once())->method('getDatabasePlatform')->willReturn($platform);
155155

156156
$statement = $this->createMock(Statement::class);
157157
// Will chunk
158-
$statement->expects($this->exactly(2))->method('rowCount')->willReturnOnConsecutiveCalls(100000, 50);
158+
$statement->expects($this->exactly(2))->method('executeStatement')->willReturnOnConsecutiveCalls(100000, 50);
159159
$connection->expects($this->once())->method('prepare')->willReturn($statement);
160160

161161
$userSession = $this->createMock(\OCP\IUserSession::class);

0 commit comments

Comments
 (0)