/** * * * @throws \RuntimeException If search $hit could not be handled * * @param mixed $hit * * @return \eZ\Publish\API\Repository\Values\ValueObject */ public function extractHit($hit) { if ($hit->_type === "content") { return $this->contentHandler->loadContentInfo($hit->_id); } if ($hit->_type === "location") { return $this->locationHandler->load($hit->_id); } throw new RuntimeException("Could not extract: document of type '{$hit->_type}' is not handled."); }
/** * Extracts value object from $hit returned by Solr backend. * * @throws \RuntimeException If search $hit could not be handled * * @param mixed $hit * * @return \eZ\Publish\API\Repository\Values\ValueObject */ public function extractHit($hit) { if ($hit->document_type_id === 'content') { return $this->contentHandler->loadContentInfo($hit->content_id); } if ($hit->document_type_id === 'location') { return $this->locationHandler->load($hit->location_id); } throw new RuntimeException("Could not extract: document of type '{$hit->document_type_id}' is not handled."); }
/** * Finds Location objects for the given query. * * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query * * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult */ public function findLocations(LocationQuery $query) { $parameters = array("q" => 'document_type_id:"location" AND ' . $this->criterionVisitor->visit($query->query), "fq" => 'document_type_id:"location" AND ' . $this->criterionVisitor->visit($query->filter), "sort" => implode(", ", array_map(array($this->sortClauseVisitor, "visit"), $query->sortClauses)), "fl" => "*,score", "wt" => "json"); if ($query->offset !== null) { $parameters["start"] = $query->offset; } if ($query->limit !== null) { $parameters["rows"] = $query->limit; } // @todo: Extract method $response = $this->client->request('GET', '/solr/select?' . http_build_query($parameters) . (count($query->facetBuilders) ? '&facet=true&facet.sort=count&' : '') . implode('&', array_map(array($this->facetBuilderVisitor, 'visit'), $query->facetBuilders))); // @todo: Error handling? $data = json_decode($response->body); if (!isset($data->response)) { throw new \Exception('->response not set: ' . var_export(array($data, $parameters), true)); } // @todo: Extract method $result = new SearchResult(array('time' => $data->responseHeader->QTime / 1000, 'maxScore' => $data->response->maxScore, 'totalCount' => $data->response->numFound)); foreach ($data->response->docs as $doc) { $searchHit = new SearchHit(array('score' => $doc->score, 'valueObject' => $this->locationHandler->load(substr($doc->id, 8)))); $result->searchHits[] = $searchHit; } if (isset($data->facet_counts)) { foreach ($data->facet_counts->facet_fields as $field => $facet) { $result->facets[] = $this->facetBuilderVisitor->map($field, $facet); } } return $result; }
/** * Clear all content persistence cache, or by locationIds (legacy content/cache mechanism is location based). * * Either way all location and urlAlias cache is cleared as well. * * @param int|int[]|null $locationIds Ids of location we need to purge content cache for. Purges all content cache if null * * @return array|int|\int[]|null * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType On invalid $id type */ public function content($locationIds = null) { if ($this->allCleared === true || $this->enabled === false) { return; } if ($locationIds === null) { $this->cache->clear('content'); goto relatedCache; } else { if (!is_array($locationIds)) { $locationIds = array($locationIds); } } foreach ($locationIds as $id) { if (!is_scalar($id)) { throw new InvalidArgumentType("\$id", "int[]|null", $id); } try { $location = $this->locationHandler->load($id); $this->cache->clear('content', $location->contentId); $this->cache->clear('content', 'info', $location->contentId); $this->cache->clear('content', 'info', 'remoteId'); $this->cache->clear('content', 'locations', $location->contentId); $this->cache->clear('user', 'role', 'assignments', 'byGroup', $location->contentId); $this->cache->clear('user', 'role', 'assignments', 'byGroup', 'inherited', $location->contentId); } catch (NotFoundException $e) { $this->logger->notice("Unable to load the location with the id '{$id}' to clear its cache"); } } // clear content related cache as well relatedCache: $this->cache->clear('urlAlias'); $this->cache->clear('location'); return $locationIds; }
/** * Returns Content ids of all ancestor Locations of all Locations * of a Content with given $contentId. * * Used to determine user groups of a user with $contentId. * * @param int|string $contentId * * @return array */ protected function getAncestorLocationsContentIds( $contentId ) { $locations = $this->locationHandler->loadLocationsByContent( $contentId ); $ancestorLocationContentIds = array(); $ancestorLocationIds = array(); foreach ( $locations as $location ) { $locationIds = explode( "/", trim( $location->pathString, "/" ) ); // Remove Location of Content with $contentId array_pop( $locationIds ); // Remove Root Location id (id==1 in legacy DB) array_shift( $locationIds ); $ancestorLocationIds = array_merge( $ancestorLocationIds, $locationIds ); } foreach ( array_unique( $ancestorLocationIds ) as $locationId ) { $location = $this->locationHandler->load( $locationId ); $ancestorLocationContentIds[$location->contentId] = true; } return array_keys( $ancestorLocationContentIds ); }