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
|
||||
*/
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue