diff --git a/lib/Db/FieldValueMapper.php b/lib/Db/FieldValueMapper.php index e1053b0..ee69d21 100644 --- a/lib/Db/FieldValueMapper.php +++ b/lib/Db/FieldValueMapper.php @@ -13,6 +13,7 @@ use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\QBMapper; use OCP\IDBConnection; +use PDO; /** @template-extends QBMapper */ class FieldValueMapper extends QBMapper { @@ -98,7 +99,7 @@ public function findDistinctUserUids(): array { ->orderBy('user_uid', 'ASC'); $cursor = $qb->executeQuery(); - $userUids = $cursor->fetchFirstColumn(); + $userUids = $cursor->fetchAll(PDO::FETCH_COLUMN); $cursor->closeCursor(); return array_values(array_map(static fn (mixed $uid): string => (string)$uid, $userUids)); diff --git a/tests/integration/features/api/repair.feature b/tests/integration/features/api/repair.feature new file mode 100644 index 0000000..de01b93 --- /dev/null +++ b/tests/integration/features/api/repair.feature @@ -0,0 +1,26 @@ +Feature: orphaned profile field value repair + Background: + Given user "repairuser" exists + And run the command "profile_fields:developer:reset --all" with result code 0 + + Scenario: maintenance:repair removes values for deleted users without errors + Given as user "admin" + When sending "post" to ocs "/apps/profile_fields/api/v1/definitions" + | fieldKey | repair_test_field | + | label | Repair test | + | type | text | + | editPolicy | users | + | exposurePolicy | private | + | sortOrder | 10 | + | active | true | + Then the response should have a status code 201 + And fetch field "(REPAIR_FIELD_ID)(jq).ocs.data.id" from previous JSON response + When sending "put" to ocs "/apps/profile_fields/api/v1/users/repairuser/values/" + | value | orphaned | + Then the response should have a status code 200 + And run the command "user:delete repairuser" with result code 0 + And run the command "maintenance:repair" with result code 0 + And the output of the last command should contain the following text: + """ + Repair orphaned profile field values + """