Skip to content

Commit

Permalink
Fix Fatal Error in Album setCollaborator function - redefining comput…
Browse files Browse the repository at this point in the history
…eKey

When calling setCollaborator function two times after another, computeKey is redefined and leads to a fatal error. Fixed by defining it as an anonymous function instead :)

Signed-off-by: Frederik Berg <83548283+frederikb96@users.noreply.github.com>
  • Loading branch information
frederikb96 committed Jan 25, 2024
1 parent bac24f8 commit c77b904
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,12 @@ public function setCollaborators(int $albumId, array $collaborators): void {
$existingCollaborators = $this->getCollaborators($albumId);

// Different behavior if type is link to prevent creating multiple link.
function computeKey($c) {
return ($c['type'] === AlbumMapper::TYPE_LINK ? '' : $c['id']).$c['type'];
}
$computeKey = function ($c) {
return ($c['type'] === AlbumMapper::TYPE_LINK ? '' : $c['id']) . $c['type'];
};

$collaboratorsToAdd = array_udiff($collaborators, $existingCollaborators, fn ($a, $b) => strcmp(computeKey($a), computeKey($b)));
$collaboratorsToRemove = array_udiff($existingCollaborators, $collaborators, fn ($a, $b) => strcmp(computeKey($a), computeKey($b)));
$collaboratorsToAdd = array_udiff($collaborators, $existingCollaborators, fn ($a, $b) => strcmp($computeKey($a), $computeKey($b)));
$collaboratorsToRemove = array_udiff($existingCollaborators, $collaborators, fn ($a, $b) => strcmp($computeKey($a), $computeKey($b)));

$this->connection->beginTransaction();

Expand Down

0 comments on commit c77b904

Please sign in to comment.