Browse Source
Add objectExists to objectstore interface
Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/13032/head
Robin Appelman
7 years ago
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
6 changed files with
47 additions and
0 deletions
-
lib/private/Files/ObjectStore/Azure.php
-
lib/private/Files/ObjectStore/S3ObjectTrait.php
-
lib/private/Files/ObjectStore/StorageObjectStore.php
-
lib/private/Files/ObjectStore/Swift.php
-
lib/public/Files/ObjectStore/IObjectStore.php
-
tests/lib/Files/ObjectStore/ObjectStoreTest.php
|
|
|
@ -115,4 +115,17 @@ class Azure implements IObjectStore { |
|
|
|
public function deleteObject($urn) { |
|
|
|
$this->getBlobClient()->deleteBlob($this->containerName, $urn); |
|
|
|
} |
|
|
|
|
|
|
|
public function objectExists($urn) { |
|
|
|
try { |
|
|
|
$this->getBlobClient()->getBlobMetadata($this->containerName, $urn); |
|
|
|
return true; |
|
|
|
} catch (ServiceException $e) { |
|
|
|
if ($e->getCode() === 404) { |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
throw $e; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -90,4 +90,8 @@ trait S3ObjectTrait { |
|
|
|
'Key' => $urn |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
public function objectExists($urn) { |
|
|
|
return $this->getConnection()->doesObjectExist($this->bucket, $urn); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -89,4 +89,7 @@ class StorageObjectStore implements IObjectStore { |
|
|
|
$this->storage->unlink($urn); |
|
|
|
} |
|
|
|
|
|
|
|
public function objectExists($urn) { |
|
|
|
return $this->storage->file_exists($urn); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -128,4 +128,7 @@ class Swift implements IObjectStore { |
|
|
|
$this->getContainer()->delete(); |
|
|
|
} |
|
|
|
|
|
|
|
public function objectExists($urn) { |
|
|
|
return $this->getContainer()->objectExists($urn); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -63,4 +63,13 @@ interface IObjectStore { |
|
|
|
* @since 7.0.0 |
|
|
|
*/ |
|
|
|
public function deleteObject($urn); |
|
|
|
|
|
|
|
/** |
|
|
|
* Check if an object exists in the object store |
|
|
|
* |
|
|
|
* @param string $urn |
|
|
|
* @return bool |
|
|
|
* @since 16.0.0 |
|
|
|
*/ |
|
|
|
public function objectExists($urn); |
|
|
|
} |
|
|
|
@ -94,4 +94,19 @@ abstract class ObjectStoreTest extends TestCase { |
|
|
|
$this->assertEquals(1, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function testExists() { |
|
|
|
$stream = $this->stringToStream('foobar'); |
|
|
|
|
|
|
|
$instance = $this->getInstance(); |
|
|
|
$this->assertFalse($instance->objectExists('2')); |
|
|
|
|
|
|
|
$instance->writeObject('2', $stream); |
|
|
|
|
|
|
|
$this->assertTrue($instance->objectExists('2')); |
|
|
|
|
|
|
|
$instance->deleteObject('2'); |
|
|
|
|
|
|
|
$this->assertFalse($instance->objectExists('2')); |
|
|
|
} |
|
|
|
} |