Skip to content

Commit

Permalink
Require user when querying album name from DB
Browse files Browse the repository at this point in the history
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
  • Loading branch information
mchugh19 committed Dec 7, 2023
1 parent 7b9c80e commit e388b70
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,18 @@ public function getForUser(string $userId): array {

/**
* @param string $albumName
* @param string $userName
* @return AlbumInfo
*/
public function getByName(string $albumName): ?AlbumInfo {
public function getByName(string $albumName, string $userName): ?AlbumInfo {
$query = $this->connection->getQueryBuilder();
$query->select("album_id", "user", "location", "created", "last_added_photo")
$query->select("album_id", "location", "created", "last_added_photo")
->from("photos_albums")
->where($query->expr()->eq('name', $query->createNamedParameter($albumName)));
->where($query->expr()->eq('name', $query->createNamedParameter($albumName)))
->andWhere($query->expr()->eq('user', $query->createNamedParameter($userName)));
$row = $query->executeQuery()->fetch();
if ($row) {
return new AlbumInfo((int)$row['album_id'], $row['user'], $albumName, $row['location'], (int)$row['created'], (int)$row['last_added_photo']);
return new AlbumInfo((int)$row['album_id'], $userName, $albumName, $row['location'], (int)$row['created'], (int)$row['last_added_photo']);
} else {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/AlbumAddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$album = $this->albumMapper->getByName($albumString);
$album = $this->albumMapper->getByName($albumString, $userString);
if (!$album) {
throw new \Exception("Album $albumString was not found");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/AlbumCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$userID = $user->getUID();

$album = $this->albumMapper->getByName($albumString);
$album = $this->albumMapper->getByName($albumString, $userString);
if ($album) {
throw new \Exception("Album $albumString already exists and cannot be created.");
}
Expand Down

0 comments on commit e388b70

Please sign in to comment.