Browse Source

do not create folder just to delete it afterwards

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
tags/v17.0.0beta1
Arthur Schiwon 5 years ago
parent
commit
3c78116cf8
No account linked to committer's email address
1 changed files with 15 additions and 7 deletions
  1. 15
    7
      apps/dav/lib/CardDAV/PhotoCache.php

+ 15
- 7
apps/dav/lib/CardDAV/PhotoCache.php View File

@@ -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
}
}
}

Loading…
Cancel
Save