mirror of https://github.com/nextcloud/photos
Require user when querying album name from DB
Signed-off-by: Christian McHugh <mchugh19@hotmail.com>
This commit is contained in:
parent
7b9c80e63e
commit
e388b708fe
|
@ -113,16 +113,18 @@ class AlbumMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $albumName
|
* @param string $albumName
|
||||||
|
* @param string $userName
|
||||||
* @return AlbumInfo
|
* @return AlbumInfo
|
||||||
*/
|
*/
|
||||||
public function getByName(string $albumName): ?AlbumInfo {
|
public function getByName(string $albumName, string $userName): ?AlbumInfo {
|
||||||
$query = $this->connection->getQueryBuilder();
|
$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")
|
->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();
|
$row = $query->executeQuery()->fetch();
|
||||||
if ($row) {
|
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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ class AlbumAddCommand extends Command {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$album = $this->albumMapper->getByName($albumString);
|
$album = $this->albumMapper->getByName($albumString, $userString);
|
||||||
if (!$album) {
|
if (!$album) {
|
||||||
throw new \Exception("Album $albumString was not found");
|
throw new \Exception("Album $albumString was not found");
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ class AlbumCreateCommand extends Command {
|
||||||
}
|
}
|
||||||
$userID = $user->getUID();
|
$userID = $user->getUID();
|
||||||
|
|
||||||
$album = $this->albumMapper->getByName($albumString);
|
$album = $this->albumMapper->getByName($albumString, $userString);
|
||||||
if ($album) {
|
if ($album) {
|
||||||
throw new \Exception("Album $albumString already exists and cannot be created.");
|
throw new \Exception("Album $albumString already exists and cannot be created.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue