do not create folder just to delete it afterwards
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
aa91b0ab3c
commit
2f0055455d
|
@ -167,16 +167,19 @@ class PhotoCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $addressBookId
|
* @throws NotFoundException
|
||||||
* @param string $cardUri
|
* @throws NotPermittedException
|
||||||
* @return ISimpleFolder
|
|
||||||
*/
|
*/
|
||||||
private function getFolder($addressBookId, $cardUri) {
|
private function getFolder(int $addressBookId, string $cardUri, bool $createIfNotExists = true): ISimpleFolder {
|
||||||
$hash = md5($addressBookId . ' ' . $cardUri);
|
$hash = md5($addressBookId . ' ' . $cardUri);
|
||||||
try {
|
try {
|
||||||
return $this->appData->getFolder($hash);
|
return $this->appData->getFolder($hash);
|
||||||
} catch (NotFoundException $e) {
|
} 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 int $addressBookId
|
||||||
* @param string $cardUri
|
* @param string $cardUri
|
||||||
|
* @throws NotPermittedException
|
||||||
*/
|
*/
|
||||||
public function delete($addressBookId, $cardUri) {
|
public function delete($addressBookId, $cardUri) {
|
||||||
$folder = $this->getFolder($addressBookId, $cardUri);
|
try {
|
||||||
$folder->delete();
|
$folder = $this->getFolder($addressBookId, $cardUri, false);
|
||||||
|
$folder->delete();
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
// that's OK, nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue