Catch exceptions and use as many results as possible
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
7d416ac1dd
commit
29f2088a7b
|
@ -22,7 +22,10 @@
|
||||||
*/
|
*/
|
||||||
namespace OC\Share20;
|
namespace OC\Share20;
|
||||||
|
|
||||||
|
use OCP\Files\InvalidPathException;
|
||||||
use OCP\Files\Node;
|
use OCP\Files\Node;
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
|
use OCP\Files\NotPermittedException;
|
||||||
use OCP\Share\IManager;
|
use OCP\Share\IManager;
|
||||||
use OCP\Share\IShareHelper;
|
use OCP\Share\IShareHelper;
|
||||||
|
|
||||||
|
@ -62,7 +65,11 @@ class ShareHelper implements IShareHelper {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getPathsForUsers(Node $node, array $users) {
|
protected function getPathsForUsers(Node $node, array $users) {
|
||||||
$byId = $results = [];
|
/** @var array[] $byId */
|
||||||
|
$byId = [];
|
||||||
|
/** @var array[] $results */
|
||||||
|
$results = [];
|
||||||
|
|
||||||
foreach ($users as $uid => $info) {
|
foreach ($users as $uid => $info) {
|
||||||
if (!isset($byId[$info['node_id']])) {
|
if (!isset($byId[$info['node_id']])) {
|
||||||
$byId[$info['node_id']] = [];
|
$byId[$info['node_id']] = [];
|
||||||
|
@ -70,12 +77,18 @@ class ShareHelper implements IShareHelper {
|
||||||
$byId[$info['node_id']][$uid] = $info['node_path'];
|
$byId[$info['node_id']][$uid] = $info['node_path'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
if (isset($byId[$node->getId()])) {
|
if (isset($byId[$node->getId()])) {
|
||||||
foreach ($byId[$node->getId()] as $uid => $path) {
|
foreach ($byId[$node->getId()] as $uid => $path) {
|
||||||
$results[$uid] = $path;
|
$results[$uid] = $path;
|
||||||
}
|
}
|
||||||
unset($byId[$node->getId()]);
|
unset($byId[$node->getId()]);
|
||||||
}
|
}
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
return $results;
|
||||||
|
} catch (InvalidPathException $e) {
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($byId)) {
|
if (empty($byId)) {
|
||||||
return $results;
|
return $results;
|
||||||
|
@ -84,6 +97,7 @@ class ShareHelper implements IShareHelper {
|
||||||
$item = $node;
|
$item = $node;
|
||||||
$appendix = '/' . $node->getName();
|
$appendix = '/' . $node->getName();
|
||||||
while (!empty($byId)) {
|
while (!empty($byId)) {
|
||||||
|
try {
|
||||||
/** @var Node $item */
|
/** @var Node $item */
|
||||||
$item = $item->getParent();
|
$item = $item->getParent();
|
||||||
|
|
||||||
|
@ -95,6 +109,13 @@ class ShareHelper implements IShareHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
$appendix = '/' . $item->getName() . $appendix;
|
$appendix = '/' . $item->getName() . $appendix;
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
return $results;
|
||||||
|
} catch (InvalidPathException $e) {
|
||||||
|
return $results;
|
||||||
|
} catch (NotPermittedException $e) {
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
@ -106,7 +127,11 @@ class ShareHelper implements IShareHelper {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getPathsForRemotes(Node $node, array $remotes) {
|
protected function getPathsForRemotes(Node $node, array $remotes) {
|
||||||
$byId = $results = [];
|
/** @var array[] $byId */
|
||||||
|
$byId = [];
|
||||||
|
/** @var array[] $results */
|
||||||
|
$results = [];
|
||||||
|
|
||||||
foreach ($remotes as $cloudId => $info) {
|
foreach ($remotes as $cloudId => $info) {
|
||||||
if (!isset($byId[$info['node_id']])) {
|
if (!isset($byId[$info['node_id']])) {
|
||||||
$byId[$info['node_id']] = [];
|
$byId[$info['node_id']] = [];
|
||||||
|
@ -116,6 +141,7 @@ class ShareHelper implements IShareHelper {
|
||||||
|
|
||||||
$item = $node;
|
$item = $node;
|
||||||
while (!empty($byId)) {
|
while (!empty($byId)) {
|
||||||
|
try {
|
||||||
if (!empty($byId[$item->getId()])) {
|
if (!empty($byId[$item->getId()])) {
|
||||||
$path = $this->getMountedPath($item);
|
$path = $this->getMountedPath($item);
|
||||||
foreach ($byId[$item->getId()] as $uid => $token) {
|
foreach ($byId[$item->getId()] as $uid => $token) {
|
||||||
|
@ -126,7 +152,16 @@ class ShareHelper implements IShareHelper {
|
||||||
}
|
}
|
||||||
unset($byId[$item->getId()]);
|
unset($byId[$item->getId()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var Node $item */
|
||||||
$item = $item->getParent();
|
$item = $item->getParent();
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
return $results;
|
||||||
|
} catch (InvalidPathException $e) {
|
||||||
|
return $results;
|
||||||
|
} catch (NotPermittedException $e) {
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
|
Loading…
Reference in New Issue