remove the detour trough node and work with path directly
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
451c8761a7
commit
15a21ee19a
|
@ -102,25 +102,6 @@ class CustomPropertiesBackend implements BackendInterface {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function propFind($path, PropFind $propFind) {
|
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();
|
$requestedProps = $propFind->get404Properties();
|
||||||
|
|
||||||
// these might appear
|
// these might appear
|
||||||
|
@ -153,7 +134,7 @@ class CustomPropertiesBackend implements BackendInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$props = $this->getProperties($node, $requestedProps);
|
$props = $this->getProperties($path, $requestedProps);
|
||||||
foreach ($props as $propName => $propValue) {
|
foreach ($props as $propName => $propValue) {
|
||||||
$propFind->set($propName, $propValue);
|
$propFind->set($propName, $propValue);
|
||||||
}
|
}
|
||||||
|
@ -168,13 +149,8 @@ class CustomPropertiesBackend implements BackendInterface {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function propPatch($path, PropPatch $propPatch) {
|
public function propPatch($path, PropPatch $propPatch) {
|
||||||
$node = $this->tree->getNodeForPath($path);
|
$propPatch->handleRemaining(function ($changedProps) use ($path) {
|
||||||
if (!($node instanceof INode)) {
|
return $this->updateProperties($path, $changedProps);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$propPatch->handleRemaining(function ($changedProps) use ($node) {
|
|
||||||
return $this->updateProperties($node, $changedProps);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +189,7 @@ class CustomPropertiesBackend implements BackendInterface {
|
||||||
/**
|
/**
|
||||||
* Returns a list of properties for this nodes.;
|
* Returns a list of properties for this nodes.;
|
||||||
*
|
*
|
||||||
* @param Node $node
|
* @param string $path
|
||||||
* @param array $requestedProperties requested properties or empty array for "all"
|
* @param array $requestedProperties requested properties or empty array for "all"
|
||||||
* @return array
|
* @return array
|
||||||
* @note The properties list is a list of propertynames the client
|
* @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
|
* http://www.example.org/namespace#author If the array is empty, all
|
||||||
* properties should be returned
|
* properties should be returned
|
||||||
*/
|
*/
|
||||||
private function getProperties(INode $node, array $requestedProperties) {
|
private function getProperties(string $path, array $requestedProperties) {
|
||||||
$path = $node->getPath();
|
|
||||||
if (isset($this->cache[$path])) {
|
if (isset($this->cache[$path])) {
|
||||||
return $this->cache[$path];
|
return $this->cache[$path];
|
||||||
}
|
}
|
||||||
|
@ -260,13 +235,12 @@ class CustomPropertiesBackend implements BackendInterface {
|
||||||
/**
|
/**
|
||||||
* Update properties
|
* 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
|
* @param array $properties array of properties to update
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function updateProperties(INode $node, array $properties) {
|
private function updateProperties(string $path, array $properties) {
|
||||||
$path = $node->getPath();
|
|
||||||
|
|
||||||
$deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
|
$deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
|
||||||
' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
|
' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
|
||||||
|
@ -278,7 +252,7 @@ class CustomPropertiesBackend implements BackendInterface {
|
||||||
' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
|
' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
|
||||||
|
|
||||||
// TODO: use "insert or update" strategy ?
|
// TODO: use "insert or update" strategy ?
|
||||||
$existing = $this->getProperties($node, []);
|
$existing = $this->getProperties($path, []);
|
||||||
$this->connection->beginTransaction();
|
$this->connection->beginTransaction();
|
||||||
foreach ($properties as $propertyName => $propertyValue) {
|
foreach ($properties as $propertyName => $propertyValue) {
|
||||||
// If it was null, we need to delete the property
|
// If it was null, we need to delete the property
|
||||||
|
|
|
@ -52,9 +52,6 @@ class CustomPropertiesBackendTest extends TestCase {
|
||||||
/** @var CustomPropertiesBackend | \PHPUnit_Framework_MockObject_MockObject */
|
/** @var CustomPropertiesBackend | \PHPUnit_Framework_MockObject_MockObject */
|
||||||
private $backend;
|
private $backend;
|
||||||
|
|
||||||
/** @var (Node | \PHPUnit_Framework_MockObject_MockObject)[] */
|
|
||||||
private $nodes = [];
|
|
||||||
|
|
||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -71,38 +68,6 @@ class CustomPropertiesBackendTest extends TestCase {
|
||||||
$this->user
|
$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 {
|
protected function tearDown(): void {
|
||||||
|
@ -170,7 +135,6 @@ class CustomPropertiesBackendTest extends TestCase {
|
||||||
$db->expects($this->never())
|
$db->expects($this->never())
|
||||||
->method($this->anything());
|
->method($this->anything());
|
||||||
|
|
||||||
$this->addNode('foo_bar_path_1337_0');
|
|
||||||
$backend->propFind('foo_bar_path_1337_0', $propFind);
|
$backend->propFind('foo_bar_path_1337_0', $propFind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,8 +176,6 @@ class CustomPropertiesBackendTest extends TestCase {
|
||||||
$setProps[$name] = $value;
|
$setProps[$name] = $value;
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->addNode('calendars/foo/bar_path_1337_0');
|
|
||||||
|
|
||||||
$this->backend->propFind('calendars/foo/bar_path_1337_0', $propFind);
|
$this->backend->propFind('calendars/foo/bar_path_1337_0', $propFind);
|
||||||
$this->assertEquals($props, $setProps);
|
$this->assertEquals($props, $setProps);
|
||||||
}
|
}
|
||||||
|
@ -223,7 +185,6 @@ class CustomPropertiesBackendTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
public function testPropPatch(string $path, array $existing, array $props, array $result) {
|
public function testPropPatch(string $path, array $existing, array $props, array $result) {
|
||||||
$this->insertProps($this->user->getUID(), $path, $existing);
|
$this->insertProps($this->user->getUID(), $path, $existing);
|
||||||
$this->addNode($path);
|
|
||||||
$propPatch = new PropPatch($props);
|
$propPatch = new PropPatch($props);
|
||||||
|
|
||||||
$this->backend->propPatch($path, $propPatch);
|
$this->backend->propPatch($path, $propPatch);
|
||||||
|
|
Loading…
Reference in New Issue