/**
  * 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.");
 }
示例#2
0
 /**
  *
  *
  * @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.");
 }
 /**
  * @param \eZ\Publish\Core\FieldType\Relation\Value $value
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition
  * @param string $languageCode
  *
  * @return string
  */
 public function getFieldName(SPIValue $value, FieldDefinition $fieldDefinition, $languageCode)
 {
     if (empty($value->destinationContentId)) {
         return '';
     }
     try {
         $contentInfo = $this->handler->loadContentInfo($value->destinationContentId);
         $versionInfo = $this->handler->loadVersionInfo($value->destinationContentId, $contentInfo->currentVersionNo);
     } catch (NotFoundException $e) {
         return '';
     }
     if (isset($versionInfo->names[$languageCode])) {
         return $versionInfo->names[$languageCode];
     }
     return $versionInfo->names[$contentInfo->mainLanguageCode];
 }
示例#4
0
 /**
  * Finds content objects for the given query.
  *
  * @todo define structs for the field filters
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query $query
  * @param array $fieldFilters - a map of filters for the returned fields.
  *        Currently supported: <code>array("languages" => array(<language1>,..))</code>.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 public function findContent(Query $query, array $fieldFilters = array())
 {
     $parameters = array("q" => $this->criterionVisitor->visit($query->query), "fq" => $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);
     // @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->contentHandler->load($doc->id, $doc->version_id)));
         $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;
 }
 /**
  * Builds domain location object from provided persistence location
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location $spiLocation
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location
  */
 public function buildLocationDomainObject(SPILocation $spiLocation)
 {
     // TODO: this is hardcoded workaround for missing ContentInfo on root location
     if ($spiLocation->id == 1) {
         $contentInfo = new ContentInfo(array('id' => 0, 'name' => 'Top Level Nodes', 'sectionId' => 1, 'mainLocationId' => 1, 'contentTypeId' => 1));
     } else {
         $contentInfo = $this->buildContentInfoDomainObject($this->contentHandler->loadContentInfo($spiLocation->contentId));
     }
     return new Location(array('contentInfo' => $contentInfo, 'id' => $spiLocation->id, 'priority' => $spiLocation->priority, 'hidden' => $spiLocation->hidden, 'invisible' => $spiLocation->invisible, 'remoteId' => $spiLocation->remoteId, 'parentLocationId' => $spiLocation->parentId, 'pathString' => $spiLocation->pathString, 'depth' => $spiLocation->depth, 'sortField' => $spiLocation->sortField, 'sortOrder' => $spiLocation->sortOrder));
 }
 /**
  * Builds domain location object from provided persistence location.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location $spiLocation
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location
  */
 public function buildLocationDomainObject(SPILocation $spiLocation)
 {
     // TODO: this is hardcoded workaround for missing ContentInfo on root location
     if ($spiLocation->id == 1) {
         $legacyDateTime = $this->getDateTime(1030968000);
         //  first known commit of eZ Publish 3.x
         $contentInfo = new ContentInfo(array('id' => 0, 'name' => 'Top Level Nodes', 'sectionId' => 1, 'mainLocationId' => 1, 'contentTypeId' => 1, 'currentVersionNo' => 1, 'published' => 1, 'ownerId' => 14, 'modificationDate' => $legacyDateTime, 'publishedDate' => $legacyDateTime, 'alwaysAvailable' => 1, 'remoteId' => null, 'mainLanguageCode' => 'eng-GB'));
     } else {
         $contentInfo = $this->buildContentInfoDomainObject($this->contentHandler->loadContentInfo($spiLocation->contentId));
     }
     return new Location(array('contentInfo' => $contentInfo, 'id' => $spiLocation->id, 'priority' => $spiLocation->priority, 'hidden' => $spiLocation->hidden, 'invisible' => $spiLocation->invisible, 'remoteId' => $spiLocation->remoteId, 'parentLocationId' => $spiLocation->parentId, 'pathString' => $spiLocation->pathString, 'depth' => $spiLocation->depth, 'sortField' => $spiLocation->sortField, 'sortOrder' => $spiLocation->sortOrder));
 }
示例#7
0
 /**
  * Deletes a location from the index.
  *
  * @param mixed $locationId
  * @param mixed $contentId
  */
 public function deleteLocation($locationId, $contentId)
 {
     $this->gateway->deleteByQuery("content_id:{$contentId}");
     // TODO it seems this part of location deletion (not last location) misses integration tests
     try {
         $contentInfo = $this->contentHandler->loadContentInfo($contentId);
     } catch (NotFoundException $e) {
         return;
     }
     $content = $this->contentHandler->load($contentId, $contentInfo->currentVersionNo);
     $this->bulkIndexContent(array($content));
 }
 /**
  * @param \eZ\Publish\Core\FieldType\RelationList\Value $value
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition
  * @param string $languageCode
  *
  * @return string
  */
 public function getFieldName(SPIValue $value, FieldDefinition $fieldDefinition, $languageCode)
 {
     if (empty($value->destinationContentIds)) {
         return '';
     }
     $names = [];
     foreach ($value->destinationContentIds as $contentId) {
         try {
             $contentInfo = $this->handler->loadContentInfo($contentId);
             $versionInfo = $this->handler->loadVersionInfo($contentId, $contentInfo->currentVersionNo);
         } catch (NotFoundException $e) {
             continue;
         }
         if (isset($versionInfo->names[$languageCode])) {
             $names[] = $versionInfo->names[$languageCode];
         } else {
             $names[] = $versionInfo->names[$contentInfo->mainLanguageCode];
         }
     }
     return implode(' ', $names);
 }
 /**
  * @param $locationId
  */
 protected function updateAllElementsWithAdditionalLocation($locationId)
 {
     $query = $this->prepareQuery();
     $query->filter = new Criterion\LogicalAnd([$this->allItemsWithinLocation($locationId), $this->allItemsWithinLocationWithAdditionalLocation($locationId)]);
     $searchResult = $this->resultExtractor->extract($this->gateway->searchAllEndpoints($query));
     $contentItems = [];
     foreach ($searchResult->searchHits as $searchHit) {
         try {
             $contentInfo = $this->contentHandler->loadContentInfo($searchHit->valueObject->id);
         } catch (NotFoundException $e) {
             continue;
         }
         $contentItems[] = $this->contentHandler->load($contentInfo->id, $contentInfo->currentVersionNo);
     }
     $this->bulkIndexContent($contentItems);
 }
 public function mapLocation(Location $location)
 {
     $contentInfo = $this->contentHandler->loadContentInfo($location->contentId);
     $content = $this->contentHandler->load($location->contentId, $contentInfo->currentVersionNo);
     $section = $this->sectionHandler->load($content->versionInfo->contentInfo->sectionId);
     $fields = array(new Field('location', $location->id, new FieldType\IdentifierField()), new Field('document_type', 'location', new FieldType\IdentifierField()), new Field('priority', $location->priority, new FieldType\IntegerField()), new Field('hidden', $location->hidden, new FieldType\BooleanField()), new Field('invisible', $location->invisible, new FieldType\BooleanField()), new Field('remote_id', $location->remoteId, new FieldType\IdentifierField()), new Field('parent_id', $location->parentId, new FieldType\IdentifierField()), new Field('path_string', $location->pathString, new FieldType\IdentifierField()), new Field('depth', $location->depth, new FieldType\IntegerField()), new Field('sort_field', $location->sortField, new FieldType\IdentifierField()), new Field('sort_order', $location->sortOrder, new FieldType\IdentifierField()), new Field('is_main_location', $location->id == $content->versionInfo->contentInfo->mainLocationId, new FieldType\BooleanField()));
     // UserGroups and Users are Content, but permissions cascade is achieved through
     // Locations hierarchy. We index all ancestor Location Content ids of all
     // Locations of an owner.
     $ancestorLocationsContentIds = $this->getAncestorLocationsContentIds($contentInfo->ownerId);
     // Add owner user id as it can also be considered as user group.
     $ancestorLocationsContentIds[] = $contentInfo->ownerId;
     $fields[] = new Field('content_owner_user_group', $ancestorLocationsContentIds, new FieldType\MultipleIdentifierField());
     $fields[] = new Field('content_id', $content->versionInfo->contentInfo->id, new FieldType\IdentifierField());
     $fields[] = new Field('content_type', $content->versionInfo->contentInfo->contentTypeId, new FieldType\IdentifierField());
     $fields[] = new Field('content_version', $content->versionInfo->versionNo, new FieldType\IdentifierField());
     $fields[] = new Field('content_status', $content->versionInfo->status, new FieldType\IdentifierField());
     $fields[] = new Field('content_name', $content->versionInfo->contentInfo->name, new FieldType\StringField());
     $fields[] = new Field('content_creator', $content->versionInfo->creatorId, new FieldType\IdentifierField());
     $fields[] = new Field('content_owner', $content->versionInfo->contentInfo->ownerId, new FieldType\IdentifierField());
     $fields[] = new Field('content_section', $content->versionInfo->contentInfo->sectionId, new FieldType\IdentifierField());
     $fields[] = new Field('content_section_identifier', $section->identifier, new FieldType\IdentifierField());
     $fields[] = new Field('content_section_name', $section->name, new FieldType\StringField());
     $fields[] = new Field('content_remote_id', $content->versionInfo->contentInfo->remoteId, new FieldType\IdentifierField());
     $fields[] = new Field('content_modified', $content->versionInfo->contentInfo->modificationDate, new FieldType\DateField());
     $fields[] = new Field('content_published', $content->versionInfo->contentInfo->publicationDate, new FieldType\DateField());
     $fields[] = new Field('language_code', array_keys($content->versionInfo->names), new FieldType\MultipleStringField());
     $fields[] = new Field('content_always_available', $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField());
     $fields[] = new Field('content_group', $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId)->groupIds, new FieldType\MultipleIdentifierField());
     $fields[] = new Field('content_object_state', $this->getObjectStateIds($content->versionInfo->contentInfo->id), new FieldType\MultipleIdentifierField());
     $contentType = $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId);
     $fieldSets = $this->mapContentFields($content, $contentType, false);
     $documents = array();
     foreach ($fieldSets as $languageCode => $translationFields) {
         $translationFields[] = new Field('meta_indexed_language_code', $languageCode, new FieldType\StringField());
         $translationFields[] = new Field('meta_indexed_is_main_translation', $languageCode === $content->versionInfo->contentInfo->mainLanguageCode, new FieldType\BooleanField());
         $translationFields[] = new Field('meta_indexed_is_main_translation_and_always_available', $languageCode === $content->versionInfo->contentInfo->mainLanguageCode && $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField());
         $isMainTranslation = $content->versionInfo->contentInfo->mainLanguageCode === $languageCode;
         $alwaysAvailable = $isMainTranslation && $content->versionInfo->contentInfo->alwaysAvailable;
         $documents[] = new Document(array("id" => $this->generateLocationDocumentId($location, $languageCode), "languageCode" => $languageCode, "alwaysAvailable" => $alwaysAvailable, "isMainTranslation" => $isMainTranslation, "fields" => array_merge($fields, $translationFields)));
     }
     return $documents;
 }
 /**
  * Maps given Location to a Document.
  *
  * Returned Document represents a "parent" Location document searchable with Location Search.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location $location
  *
  * @return \eZ\Publish\Core\Search\Elasticsearch\Content\Document
  */
 public function mapLocation(Location $location)
 {
     $contentInfo = $this->contentHandler->loadContentInfo($location->contentId);
     $content = $this->contentHandler->load($location->contentId, $contentInfo->currentVersionNo);
     $section = $this->sectionHandler->load($content->versionInfo->contentInfo->sectionId);
     $document = $this->mapContentLocation($location, $content);
     $document->id = $location->id;
     $document->type = "location";
     $document->fields[] = new Field('is_main_location', $location->id == $content->versionInfo->contentInfo->mainLocationId, new FieldType\BooleanField());
     // UserGroups and Users are Content, but permissions cascade is achieved through
     // Locations hierarchy. We index all ancestor Location Content ids of all
     // Locations of an owner.
     $ancestorLocationsContentIds = $this->getAncestorLocationsContentIds($contentInfo->ownerId);
     // Add owner user id as it can also be considered as user group.
     $ancestorLocationsContentIds[] = $contentInfo->ownerId;
     $document->fields[] = new Field('content_owner_user_group', $ancestorLocationsContentIds, new FieldType\MultipleIdentifierField());
     $document->fields[] = new Field('content_id', $content->versionInfo->contentInfo->id, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_type', $content->versionInfo->contentInfo->contentTypeId, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_version', $content->versionInfo->versionNo, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_status', $content->versionInfo->status, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_name', $content->versionInfo->contentInfo->name, new FieldType\StringField());
     $document->fields[] = new Field('content_creator', $content->versionInfo->creatorId, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_owner', $content->versionInfo->contentInfo->ownerId, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_section', $content->versionInfo->contentInfo->sectionId, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_section_identifier', $section->identifier, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_section_name', $section->name, new FieldType\StringField());
     $document->fields[] = new Field('content_remote_id', $content->versionInfo->contentInfo->remoteId, new FieldType\IdentifierField());
     $document->fields[] = new Field('content_modified', $content->versionInfo->contentInfo->modificationDate, new FieldType\DateField());
     $document->fields[] = new Field('content_published', $content->versionInfo->contentInfo->publicationDate, new FieldType\DateField());
     $document->fields[] = new Field('content_language_code', array_keys($content->versionInfo->names), new FieldType\MultipleStringField());
     $document->fields[] = new Field('content_always_available', $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField());
     $contentType = $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId);
     $document->fields[] = new Field('content_group', $contentType->groupIds, new FieldType\MultipleIdentifierField());
     $document->fields[] = new Field('content_object_state', $this->getObjectStateIds($content->versionInfo->contentInfo->id), new FieldType\MultipleIdentifierField());
     return $document;
 }
 public function mapFields(Location $location)
 {
     $contentInfo = $this->contentHandler->loadContentInfo($location->contentId);
     return [new Field('location', $location->id, new FieldType\IdentifierField()), new Field('document_type', DocumentMapper::DOCUMENT_TYPE_IDENTIFIER_LOCATION, new FieldType\IdentifierField()), new Field('priority', $location->priority, new FieldType\IntegerField()), new Field('hidden', $location->hidden, new FieldType\BooleanField()), new Field('invisible', $location->invisible, new FieldType\BooleanField()), new Field('remote_id', $location->remoteId, new FieldType\IdentifierField()), new Field('parent_id', $location->parentId, new FieldType\IdentifierField()), new Field('path_string', $location->pathString, new FieldType\IdentifierField()), new Field('depth', $location->depth, new FieldType\IntegerField()), new Field('sort_field', $location->sortField, new FieldType\IdentifierField()), new Field('sort_order', $location->sortOrder, new FieldType\IdentifierField()), new Field('is_main_location', $location->id == $contentInfo->mainLocationId, new FieldType\BooleanField())];
 }
 protected function assertContentHandlerExpectations($callNo, $persistenceCalled, $contentId, $contentInfo)
 {
     $this->getPersistenceMock()->expects($this->at($callNo + ($persistenceCalled ? 1 : 0)))->method("contentHandler")->will($this->returnValue($this->contentHandlerMock));
     $this->contentHandlerMock->expects($this->at($callNo))->method("loadContentInfo")->with($contentId)->will($this->returnValue($contentInfo));
 }