Skip to content

Commit 76c0b7e

Browse files
authored
Merge pull request #84 from LibreCodeCoop/fix/repair-fetch-column-compat
fix: make orphaned value repair query cursor compatible across Nextcloud versions
2 parents 53ff9ad + ccb0504 commit 76c0b7e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/Db/FieldValueMapper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
1414
use OCP\AppFramework\Db\QBMapper;
1515
use OCP\IDBConnection;
16+
use PDO;
1617

1718
/** @template-extends QBMapper<FieldValue> */
1819
class FieldValueMapper extends QBMapper {
@@ -98,7 +99,7 @@ public function findDistinctUserUids(): array {
9899
->orderBy('user_uid', 'ASC');
99100

100101
$cursor = $qb->executeQuery();
101-
$userUids = $cursor->fetchFirstColumn();
102+
$userUids = $cursor->fetchAll(PDO::FETCH_COLUMN);
102103
$cursor->closeCursor();
103104

104105
return array_values(array_map(static fn (mixed $uid): string => (string)$uid, $userUids));
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Feature: orphaned profile field value repair
2+
Background:
3+
Given user "repairuser" exists
4+
And run the command "profile_fields:developer:reset --all" with result code 0
5+
6+
Scenario: maintenance:repair removes values for deleted users without errors
7+
Given as user "admin"
8+
When sending "post" to ocs "/apps/profile_fields/api/v1/definitions"
9+
| fieldKey | repair_test_field |
10+
| label | Repair test |
11+
| type | text |
12+
| editPolicy | users |
13+
| exposurePolicy | private |
14+
| sortOrder | 10 |
15+
| active | true |
16+
Then the response should have a status code 201
17+
And fetch field "(REPAIR_FIELD_ID)(jq).ocs.data.id" from previous JSON response
18+
When sending "put" to ocs "/apps/profile_fields/api/v1/users/repairuser/values/<REPAIR_FIELD_ID>"
19+
| value | orphaned |
20+
Then the response should have a status code 200
21+
And run the command "user:delete repairuser" with result code 0
22+
And run the command "maintenance:repair" with result code 0
23+
And the output of the last command should contain the following text:
24+
"""
25+
Repair orphaned profile field values
26+
"""

0 commit comments

Comments
 (0)