Skip to content
Snippets Groups Projects
Unverified Commit 3c78116c authored by Arthur Schiwon's avatar Arthur Schiwon
Browse files

do not create folder just to delete it afterwards

parent 009c2dfb
No related branches found
No related tags found
No related merge requests found
......@@ -167,16 +167,19 @@ class PhotoCache {
}
/**
* @param int $addressBookId
* @param string $cardUri
* @return ISimpleFolder
* @throws NotFoundException
* @throws NotPermittedException
*/
private function getFolder($addressBookId, $cardUri) {
private function getFolder(int $addressBookId, string $cardUri, bool $createIfNotExists = true): ISimpleFolder {
$hash = md5($addressBookId . ' ' . $cardUri);
try {
return $this->appData->getFolder($hash);
} catch (NotFoundException $e) {
return $this->appData->newFolder($hash);
if($createIfNotExists) {
return $this->appData->newFolder($hash);
} else {
throw $e;
}
}
}
......@@ -271,9 +274,14 @@ class PhotoCache {
/**
* @param int $addressBookId
* @param string $cardUri
* @throws NotPermittedException
*/
public function delete($addressBookId, $cardUri) {
$folder = $this->getFolder($addressBookId, $cardUri);
$folder->delete();
try {
$folder = $this->getFolder($addressBookId, $cardUri, false);
$folder->delete();
} catch (NotFoundException $e) {
// that's OK, nothing to do
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment