add path to all scopes

This commit is contained in:
Robin Appelman 2017-02-02 18:09:53 +01:00
commit 7621e3d43d
2 changed files with 15 additions and 5 deletions

View file

@ -126,8 +126,11 @@ class SearchPlugin extends ServerPlugin {
$query = $xml['{DAV:}basicsearch']; $query = $xml['{DAV:}basicsearch'];
$response->setStatus(207); $response->setStatus(207);
$response->setHeader('Content-Type', 'application/xml; charset="utf-8"'); $response->setHeader('Content-Type', 'application/xml; charset="utf-8"');
foreach ($query->from as $scope) {
$scope->path = $this->getPathFromUri($scope->href);
}
$results = $this->searchBackend->search($query); $results = $this->searchBackend->search($query);
$data = $this->server->generateMultiStatus($this->getPropertiesIteratorResults($results, $query->select), false); $data = $this->server->generateMultiStatus(iterator_to_array($this->getPropertiesIteratorResults($results, $query->select)), false);
$response->setBody($data); $response->setBody($data);
return false; return false;
case '{DAV:}query-schema-discovery': case '{DAV:}query-schema-discovery':
@ -138,9 +141,9 @@ class SearchPlugin extends ServerPlugin {
$query = $xml['{DAV:}basicsearch']; $query = $xml['{DAV:}basicsearch'];
$scopes = $query->from; $scopes = $query->from;
$results = array_map(function (Scope $scope) { $results = array_map(function (Scope $scope) {
$scopePath = $this->getPathFromUri($scope->href); $scope->path = $this->getPathFromUri($scope->href);
if ($this->searchBackend->isValidScope($scope->href, $scope->depth, $scopePath)) { if ($this->searchBackend->isValidScope($scope->href, $scope->depth, $scope->path)) {
$searchProperties = $this->searchBackend->getPropertyDefinitionsForScope($scope->href, $scopePath); $searchProperties = $this->searchBackend->getPropertyDefinitionsForScope($scope->href, $scope->path);
$searchSchema = $this->getBasicSearchForProperties($searchProperties); $searchSchema = $this->getBasicSearchForProperties($searchProperties);
return new QueryDiscoverResponse($scope->href, $searchSchema, 200); return new QueryDiscoverResponse($scope->href, $searchSchema, 200);
} else { } else {
@ -171,7 +174,7 @@ class SearchPlugin extends ServerPlugin {
* @param int $depth * @param int $depth
* @return \Iterator * @return \Iterator
*/ */
function getPropertiesIteratorResults(array $results, $propertyNames = [], $depth = 0) { function getPropertiesIteratorResults($results, $propertyNames = [], $depth = 0) {
$propFindType = $propertyNames ? PropFind::NORMAL : PropFind::ALLPROPS; $propFindType = $propertyNames ? PropFind::NORMAL : PropFind::ALLPROPS;
foreach ($results as $result) { foreach ($results as $result) {

View file

@ -43,6 +43,13 @@ class Scope implements XmlDeserializable {
*/ */
public $depth; public $depth;
/**
* @var string|null
*
* the path of the search scope relative to the dav server, or null if the scope is outside the dav server
*/
public $path;
/** /**
* @param string $href * @param string $href
* @param int|string $depth * @param int|string $depth