summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-02-03 13:37:30 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2020-03-18 13:41:04 +0100
commit15a21ee19a7a0db41a7e20c15eb1943a6f5f37b8 (patch)
tree609417ef31e5ab03994b4dc6ccba3a222840f496 /apps/dav
parent451c8761a710c62bc19b75ceba9de670b95aca9e (diff)
downloadnextcloud-server-15a21ee19a7a0db41a7e20c15eb1943a6f5f37b8.tar.gz
nextcloud-server-15a21ee19a7a0db41a7e20c15eb1943a6f5f37b8.zip
remove the detour trough node and work with path directly
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/DAV/CustomPropertiesBackend.php42
-rw-r--r--apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php39
2 files changed, 8 insertions, 73 deletions
diff --git a/apps/dav/lib/DAV/CustomPropertiesBackend.php b/apps/dav/lib/DAV/CustomPropertiesBackend.php
index 5e0842200b4..8b0408a461b 100644
--- a/apps/dav/lib/DAV/CustomPropertiesBackend.php
+++ b/apps/dav/lib/DAV/CustomPropertiesBackend.php
@@ -102,25 +102,6 @@ class CustomPropertiesBackend implements BackendInterface {
* @return void
*/
public function propFind($path, PropFind $propFind) {
- try {
- $node = $this->tree->getNodeForPath($path);
- if (!($node instanceof INode)) {
- return;
- }
- } catch (ServiceUnavailable $e) {
- // might happen for unavailable mount points, skip
- return;
- } catch (NotFound $e) {
- // in some rare (buggy) cases the node might not be found,
- // we catch the exception to prevent breaking the whole list with a 404
- // (soft fail)
- \OC::$server->getLogger()->warning(
- 'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(),
- ['app' => 'files']
- );
- return;
- }
-
$requestedProps = $propFind->get404Properties();
// these might appear
@@ -153,7 +134,7 @@ class CustomPropertiesBackend implements BackendInterface {
return;
}
- $props = $this->getProperties($node, $requestedProps);
+ $props = $this->getProperties($path, $requestedProps);
foreach ($props as $propName => $propValue) {
$propFind->set($propName, $propValue);
}
@@ -168,13 +149,8 @@ class CustomPropertiesBackend implements BackendInterface {
* @return void
*/
public function propPatch($path, PropPatch $propPatch) {
- $node = $this->tree->getNodeForPath($path);
- if (!($node instanceof INode)) {
- return;
- }
-
- $propPatch->handleRemaining(function ($changedProps) use ($node) {
- return $this->updateProperties($node, $changedProps);
+ $propPatch->handleRemaining(function ($changedProps) use ($path) {
+ return $this->updateProperties($path, $changedProps);
});
}
@@ -213,7 +189,7 @@ class CustomPropertiesBackend implements BackendInterface {
/**
* Returns a list of properties for this nodes.;
*
- * @param Node $node
+ * @param string $path
* @param array $requestedProperties requested properties or empty array for "all"
* @return array
* @note The properties list is a list of propertynames the client
@@ -221,8 +197,7 @@ class CustomPropertiesBackend implements BackendInterface {
* http://www.example.org/namespace#author If the array is empty, all
* properties should be returned
*/
- private function getProperties(INode $node, array $requestedProperties) {
- $path = $node->getPath();
+ private function getProperties(string $path, array $requestedProperties) {
if (isset($this->cache[$path])) {
return $this->cache[$path];
}
@@ -260,13 +235,12 @@ class CustomPropertiesBackend implements BackendInterface {
/**
* Update properties
*
- * @param INode $node node for which to update properties
+ * @param string $path path for which to update properties
* @param array $properties array of properties to update
*
* @return bool
*/
- private function updateProperties(INode $node, array $properties) {
- $path = $node->getPath();
+ private function updateProperties(string $path, array $properties) {
$deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
@@ -278,7 +252,7 @@ class CustomPropertiesBackend implements BackendInterface {
' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
// TODO: use "insert or update" strategy ?
- $existing = $this->getProperties($node, []);
+ $existing = $this->getProperties($path, []);
$this->connection->beginTransaction();
foreach ($properties as $propertyName => $propertyValue) {
// If it was null, we need to delete the property
diff --git a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php
index 9f0fbdc3a01..45aab9af1f5 100644
--- a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php
+++ b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php
@@ -52,9 +52,6 @@ class CustomPropertiesBackendTest extends TestCase {
/** @var CustomPropertiesBackend | \PHPUnit_Framework_MockObject_MockObject */
private $backend;
- /** @var (Node | \PHPUnit_Framework_MockObject_MockObject)[] */
- private $nodes = [];
-
protected function setUp(): void {
parent::setUp();
@@ -71,38 +68,6 @@ class CustomPropertiesBackendTest extends TestCase {
$this->user
);
- $this->tree->method('getNodeForPath')
- ->willReturnCallback(function ($path) {
- if (isset($this->nodes[$path])) {
- return $this->nodes[$path];
- } else {
- throw new NotFound();
- }
- });
- }
-
- /**
- * @param string $path
- * @return INode|\PHPUnit\Framework\MockObject\MockObject
- */
- private function addNode($path) {
- $node = $this->createMock(INode::class);
- $node->method('getPath')
- ->willReturn($path);
- $this->nodes[$path] = $node;
- return $node;
- }
-
- /**
- * @param string $path
- * @return Node|\PHPUnit\Framework\MockObject\MockObject
- */
- private function addCalendar($path) {
- $node = $this->createMock(Node::class);
- $node->method('getPath')
- ->willReturn($path);
- $this->nodes[$path] = $node;
- return $node;
}
protected function tearDown(): void {
@@ -170,7 +135,6 @@ class CustomPropertiesBackendTest extends TestCase {
$db->expects($this->never())
->method($this->anything());
- $this->addNode('foo_bar_path_1337_0');
$backend->propFind('foo_bar_path_1337_0', $propFind);
}
@@ -212,8 +176,6 @@ class CustomPropertiesBackendTest extends TestCase {
$setProps[$name] = $value;
});
- $this->addNode('calendars/foo/bar_path_1337_0');
-
$this->backend->propFind('calendars/foo/bar_path_1337_0', $propFind);
$this->assertEquals($props, $setProps);
}
@@ -223,7 +185,6 @@ class CustomPropertiesBackendTest extends TestCase {
*/
public function testPropPatch(string $path, array $existing, array $props, array $result) {
$this->insertProps($this->user->getUID(), $path, $existing);
- $this->addNode($path);
$propPatch = new PropPatch($props);
$this->backend->propPatch($path, $propPatch);