public function boot()
 {
     // Set some static globals
     Globals::setSolrServerConfig($this->container->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
     Globals::setSolrClassesConfig($this->container->getParameter('xrow_ez_publish_solr_docs.solr_classes'));
     Globals::setSolrGlobalConfig($this->container->getParameter('xrow_ez_publish_solr_docs.solrglobalconfig'));
 }
 /**
  * Get a Content Type object by identifier
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If content type with the given identifier and status DEFINED can not be found
  *
  * @param string $identifier
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType
  */
 public function loadContentTypeByIdentifier($identifier)
 {
     if (!is_string($identifier)) {
         throw new InvalidArgumentValue('$identifier', $identifier);
     }
     #$solrserverconfig = Globals::getSolrServerConfig();
     $solrclasses = Globals::getSolrClassesConfig();
     if (array_key_exists($identifier, $solrclasses)) {
         $fieldDefinitions = array();
         foreach ($solrclasses[$identifier]["fields"] as $solrclassatt) {
             $fieldDefinitions[] = new \eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition(array("id" => $solrclassatt["id"], "identifier" => $solrclassatt["identifier"], "fieldTypeIdentifier" => $solrclassatt["fieldTypeIdentifier"], "names" => $solrclassatt["names"], "descriptions" => $solrclassatt["descriptions"], "fieldGroup" => $solrclassatt["fieldGroup"], "position" => (int) $solrclassatt["position"], "isTranslatable" => $solrclassatt["isTranslatable"], "isRequired" => $solrclassatt["isRequired"], "isInfoCollector" => $solrclassatt["isInfoCollector"], "isSearchable" => $solrclassatt["isSearchable"]));
         }
         $selfCreatedContentType = new ContentType(array("names" => $solrclasses[$identifier]["names"], "descriptions" => $solrclasses[$identifier]["descriptions"], "contentTypeGroups" => $solrclasses[$identifier]["contentTypeGroups"], "fieldDefinitions" => $fieldDefinitions, "id" => $solrclasses[$identifier]["id"], "status" => $solrclasses[$identifier]["status"], "identifier" => $solrclasses[$identifier]["identifier"], "creationDate" => $solrclasses[$identifier]["creationDate"], "modificationDate" => $solrclasses[$identifier]["modificationDate"], "creatorId" => $solrclasses[$identifier]["creatorId"], "modifierId" => $solrclasses[$identifier]["modifierId"], "remoteId" => $solrclasses[$identifier]["remoteId"], "urlAliasSchema" => $solrclasses[$identifier]["urlAliasSchema"], "nameSchema" => $solrclasses[$identifier]["nameSchema"], "isContainer" => $solrclasses[$identifier]["isContainer"], "mainLanguageCode" => $solrclasses[$identifier]["mainLanguageCode"], "defaultAlwaysAvailable" => $solrclasses[$identifier]["defaultAlwaysAvailable"], "defaultSortField" => $solrclasses[$identifier]["defaultSortField"], "defaultSortOrder" => $solrclasses[$identifier]["defaultSortOrder"]));
         return $selfCreatedContentType;
     }
     $spiContentType = $this->contentTypeHandler->loadByIdentifier($identifier);
     return $this->buildContentTypeDomainObject($spiContentType);
 }
 /**
  * Finds content objects for the given query.
  *
  * @todo define structs for the field filters
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid
  *
  * @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>.
  * @param boolean $filterOnUserPermissions if true only the objects which is the user allowed to read are returned.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 public function findContent(Query $query, array $fieldFilters = array(), $filterOnUserPermissions = true)
 {
     $solrserverconfig = Globals::getSolrServerConfig();
     $solrglobalconfig = Globals::getSolrGlobalConfig();
     $client = new \Solarium\Client($solrserverconfig);
     $query = clone $query;
     $query->filter = $query->filter ?: new Criterion\MatchAll();
     $this->validateContentCriteria(array($query->query), "\$query");
     $this->validateContentCriteria(array($query->filter), "\$query");
     $this->validateContentSortClauses($query);
     $this->validateSortClauses($query);
     if ($query->limit === null) {
         $query->limit = 2;
     }
     $criterion = $query->query;
     $queries = array("" . $criterion->value);
     foreach ($criterion->boost as $field => $boost) {
         $fields = $this->fieldMap->getFieldTypes($criterion);
         if (!isset($fields[$field])) {
             continue;
         }
         foreach ($fields[$field] as $fieldNames) {
             foreach ($fieldNames as $fieldName) {
                 $queries[] = $fieldName . ":" . $criterion->value . "^" . $boost;
             }
         }
     }
     $abfrage = "(" . implode(') OR (', array_map(function ($search) use($criterion) {
         return $search . ($criterion->fuzziness < 1 ? sprintf("~%.1f", $criterion->fuzziness) : "");
     }, $queries)) . ")";
     if ($query->offset !== null) {
         $parameters["start"] = $query->offset;
     }
     if ($query->limit !== null) {
         $parameters["rows"] = $query->limit;
     }
     // @todo: Extract method
     $solrquery = $client->createQuery($client::QUERY_SELECT);
     $solrquery->createFilterQuery('solrdocs')->setQuery("is_solrdoc_b:true AND " . $abfrage);
     $result = $client->select($solrquery);
     // @todo: Extract method
     $result = new SearchResult(array('time' => $data->responseHeader->QTime / 1000, 'maxScore' => $data->response->maxScore, 'totalCount' => $data->response->numFound));
     foreach ($result as $doc) {
         $searchHit = new SearchHit(array('score' => $doc->score, 'valueObject' => $doc));
         #'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);
         }
     }
     var_dump($result);
     die("Stop");
     return $result;
 }
 /**
  * Creates a new content draft assigned to the authenticated user.
  *
  * If a different userId is given in $contentCreateStruct it is assigned to the given user
  * but this required special rights for the authenticated user
  * (this is useful for content staging where the transfer process does not
  * have to authenticate with the user which created the content object in the source server).
  * The user has to publish the draft if it should be visible.
  * In 4.x at least one location has to be provided in the location creation array.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system
  *                                                                        or there is no location provided (4.x) or multiple locations
  *                                                                        are under the same parent or if the a field value is not accepted by the field type
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value
  *
  * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct
  * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
  */
 public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array())
 {
     #$startzeit=microtime(true);
     if ($contentCreateStruct->mainLanguageCode === null) {
         throw new InvalidArgumentException("\$contentCreateStruct", "'mainLanguageCode' property must be set");
     }
     if ($contentCreateStruct->contentType === null) {
         throw new InvalidArgumentException("\$contentCreateStruct", "'contentType' property must be set");
     }
     $contentCreateStruct = clone $contentCreateStruct;
     if ($contentCreateStruct->ownerId === null) {
         $contentCreateStruct->ownerId = $this->repository->getCurrentUser()->id;
     }
     if ($contentCreateStruct->alwaysAvailable === null) {
         $contentCreateStruct->alwaysAvailable = false;
     }
     $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType($contentCreateStruct->contentType->id);
     $contentCreateStruct->sectionId = 1;
     if (empty($contentCreateStruct->sectionId)) {
         if (isset($locationCreateStructs[0])) {
             $location = $this->repository->getLocationService()->loadLocation($locationCreateStructs[0]->parentLocationId);
             $contentCreateStruct->sectionId = $location->contentInfo->sectionId;
         } else {
             $contentCreateStruct->sectionId = 1;
         }
     }
     /*
     if ( !$this->repository->canUser( 'content', 'create', $contentCreateStruct, $locationCreateStructs ) )
     {
         throw new UnauthorizedException( 'content', 'create' );
     }
     */
     /*
     if ( !empty( $contentCreateStruct->remoteId ) )
     {
         try
         {
             $this->loadContentByRemoteId( $contentCreateStruct->remoteId );
     
             throw new InvalidArgumentException(
                 "\$contentCreateStruct",
                 "Another content with remoteId '{$contentCreateStruct->remoteId}' exists"
             );
         }
         catch ( APINotFoundException $e )
         {
             // Do nothing
         }
     }
     else
     {
         $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash( $contentCreateStruct );
     }
     */
     #Expect RemoteID is unique
     $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentCreateStruct);
     $spiLocationCreateStructs = $this->buildSPILocationCreateStructs($locationCreateStructs);
     $languageCodes = $this->getLanguageCodesForCreate($contentCreateStruct);
     $fields = $this->mapFieldsForCreate($contentCreateStruct);
     $fieldValues = array();
     $SolrDocFields = array();
     $spiFields = array();
     $allFieldErrors = array();
     $inputRelations = array();
     $locationIdToContentIdMapping = array();
     foreach ($contentCreateStruct->contentType->getFieldDefinitions() as $fieldDefinition) {
         /** @var $fieldType \eZ\Publish\Core\FieldType\FieldType */
         $fieldType = $this->repository->getFieldTypeService()->buildFieldType($fieldDefinition->fieldTypeIdentifier);
         foreach ($languageCodes as $languageCode) {
             $isEmptyValue = false;
             $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreateStruct->mainLanguageCode;
             $isLanguageMain = $languageCode === $contentCreateStruct->mainLanguageCode;
             if (isset($fields[$fieldDefinition->identifier][$valueLanguageCode])) {
                 $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value;
             } else {
                 $fieldValue = $fieldDefinition->defaultValue;
             }
             $fieldValue = $fieldType->acceptValue($fieldValue);
             if ($fieldType->isEmptyValue($fieldValue)) {
                 $isEmptyValue = true;
                 if ($fieldDefinition->isRequired) {
                     throw new ContentValidationException("Value for required field definition '{$fieldDefinition->identifier}' with language '{$languageCode}' is empty");
                 }
             } else {
                 $fieldErrors = $fieldType->validate($fieldDefinition, $fieldValue);
                 if (!empty($fieldErrors)) {
                     $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors;
                 }
             }
             if (!empty($allFieldErrors)) {
                 continue;
             }
             $this->relationProcessor->appendFieldRelations($inputRelations, $locationIdToContentIdMapping, $fieldType, $fieldValue, $fieldDefinition->id);
             $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue;
             // Only non-empty value for: translatable field or in main language
             if (!$isEmptyValue && $fieldDefinition->isTranslatable || !$isEmptyValue && $isLanguageMain) {
                 $spiFields[] = new SPIField(array("id" => null, "fieldDefinitionId" => $fieldDefinition->id, "type" => $fieldDefinition->fieldTypeIdentifier, "value" => $fieldType->toPersistenceValue($fieldValue), "languageCode" => $languageCode, "versionNo" => null));
                 $SolrDocFields[] = array("identifier" => $fieldDefinition->identifier, "type" => $fieldDefinition->fieldTypeIdentifier, "value" => $fields[$fieldDefinition->identifier][$valueLanguageCode]->value, "data" => $fieldType->toPersistenceValue($fieldValue)->data, "sortkey" => $fieldType->toPersistenceValue($fieldValue)->sortKey, "languageCode" => $languageCode, "searchable" => $fieldDefinition->isSearchable);
             }
         }
     }
     if (!empty($allFieldErrors)) {
         throw new ContentFieldValidationException($allFieldErrors);
     }
     $spiContentCreateStruct = new SPIContentCreateStruct(array("name" => $this->nameSchemaService->resolve($contentCreateStruct->contentType->nameSchema, $contentCreateStruct->contentType, $fieldValues, $languageCodes), "typeId" => $contentCreateStruct->contentType->id, "sectionId" => $contentCreateStruct->sectionId, "ownerId" => $contentCreateStruct->ownerId, "locations" => $spiLocationCreateStructs, "fields" => $spiFields, "alwaysAvailable" => $contentCreateStruct->alwaysAvailable, "remoteId" => $contentCreateStruct->remoteId, "modified" => isset($contentCreateStruct->modificationDate) ? $contentCreateStruct->modificationDate->getTimestamp() : time(), "initialLanguageId" => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode($contentCreateStruct->mainLanguageCode)->id));
     if (!is_numeric($spiContentCreateStruct->locations[0]->parentId) && $spiContentCreateStruct->locations[0]->parentId != "") {
         $url = trim($spiContentCreateStruct->locations[0]->parentId, '/');
         $url_array = explode("/", $url);
         $url_array[] = $spiContentCreateStruct->remoteId;
         $url_alias_cats = array();
         foreach ($url_array as $depth => $part) {
             $fullpart = "";
             for ($i = 0; $i <= $depth; $i++) {
                 $fullpart .= $url_array[$i] . "/";
             }
             $url_alias_cats[] = $depth . "/" . $fullpart;
         }
         $url_alias = $url_alias_cats;
         $lasturlelement = array_pop($url_alias_cats);
         $parent_url_alias = $url_alias_cats;
     } else {
         $url_alias_cats = array("0/" . $spiContentCreateStruct->locations[0]->parentId, "1/" . $spiContentCreateStruct->locations[0]->parentId . "/" . $spiContentCreateStruct->remoteId);
         $url_alias = $url_alias_cats;
         $lasturlelement = array_pop($url_alias_cats);
         $parent_url_alias = $url_alias_cats;
     }
     # we ommit defaultObjectStates!!!!
     #$defaultObjectStates = $this->getDefaultObjectStates();
     #This is the point where a new version is created
     #We create a version 1 of solrDoc
     #$spiContent = $this->persistenceHandler->contentHandler()->create( $spiContentCreateStruct );
     #$startzeit=microtime(true);
     $solrserverconfig = Globals::getSolrServerConfig();
     $solrglobalconfig = Globals::getSolrGlobalConfig();
     $client = new \Solarium\Client($solrserverconfig);
     $update = $client->createUpdate();
     $doc1 = $update->createDocument();
     $doc1->meta_installation_id_ms = $solrglobalconfig["meta_installation_id_ms"];
     $doc1->meta_guid_ms = $spiContentCreateStruct->remoteId;
     $doc1->meta_name_t = $spiContentCreateStruct->name["ger-DE"];
     $doc1->meta_sort_name_ms = $spiContentCreateStruct->name["ger-DE"];
     $doc1->meta_remote_id_ms = $spiContentCreateStruct->remoteId;
     $doc1->meta_current_version_si = 1;
     $doc1->meta_class_identifier_ms = $contentCreateStruct->contentType->identifier;
     $doc1->meta_class_name_ms = $contentCreateStruct->contentType->names["ger-DE"];
     $doc1->meta_contentclass_id_si = $spiContentCreateStruct->typeId;
     $doc1->meta_url_alias_ms = $url_alias;
     $doc1->meta_parent_url_alias_ms = array_pop($parent_url_alias);
     $doc1->meta_main_url_alias_ms = array_pop($url_alias);
     $doc1->meta_language_code_ms = $solrglobalconfig["meta_language_code_ms"];
     $date = new DateTime();
     $date->setTimestamp($spiContentCreateStruct->modified);
     $doc1->meta_published_dt = $date->format("Y-m-d\\TH:i:s\\Z");
     $doc1->timestamp = $date->format("Y-m-d\\TH:i:s\\Z");
     $doc1->meta_id_si = 0;
     /*
             // is that really nessecary?
             #$doc1->meta_main_parent_node_id_si= 61;
             #$doc1->meta_node_id_si=array( 68 );
             $doc1->is_solrdoc_b = true;
             $doc1->meta_installation_url_ms = $solrglobalconfig["meta_installation_id_ms"];
             $doc1->meta_id_si = 0;
             $doc1->meta_section_id_si = $spiContentCreateStruct->sectionId;
             $doc1->meta_owner_id_si = $spiContentCreateStruct->ownerId;
             $doc1->meta_modified_dt=$date->format( "Y-m-d\\TH:i:s\\Z" );
             $doc1->meta_is_hidden_b=array( false );
             $doc1->meta_is_invisible_b=array( false );
             $doc1->meta_always_available_b = $contentCreateStruct->alwaysAvailable;
             $doc1->meta_sort_field_ms=array( "1" );
             $doc1->meta_sort_order_ms=array( "1");
             $doc1->meta_priority_si=array( 0 );
             $doc1->meta_view_count_si=array(0);
             $doc1->meta_owner_name_t = $solrglobalconfig["meta_owner_name_t"];
             $doc1->meta_owner_group_id_si = array( $solrglobalconfig["meta_owner_group_id_si"] );
             $doc1->meta_object_states_si=array( $solrglobalconfig["meta_object_states_si"] );
     */
     // LoopThroughFields
     #var_dump(count($SolrDocFields));
     #var_dump($SolrDocFields);
     #die("sdkfj");
     foreach ($SolrDocFields as $solrField) {
         if ($solrField["type"] == "eztext") {
             $ident = "attr_" . $solrField["identifier"] . "_t";
             $solrvalue = $solrField["value"];
         }
         if ($solrField["type"] == "ezstring") {
             $ident = "attr_" . $solrField["identifier"] . "_s";
             $solrvalue = $solrField["value"];
         }
         if ($solrField["type"] == "ezboolean") {
             $ident = "attr_" . $solrField["identifier"] . "_b";
             $solrvalue = $solrField["value"];
         }
         if ($solrField["type"] == "ezinteger") {
             $ident = "attr_" . $solrField["identifier"] . "_si";
             $solrvalue = $solrField["value"];
         }
         if ($solrField["type"] == "ezfloat") {
             $ident = "attr_" . $solrField["identifier"] . "_f";
             $solrvalue = (double) $solrField["value"];
         }
         if ($solrField["type"] == "ezkeyword") {
             $ident = "attr_" . $solrField["identifier"] . "____k";
             $solrvalue = $solrField["value"];
         }
         if ($solrField["type"] == "ezurl") {
             $ident = "attr_" . $solrField["identifier"] . "_ms";
             $solrvalue = $solrField["value"];
         }
         if ($solrField["type"] == "ezdatetime" or $solrField["type"] == "ezdate") {
             $ident = "attr_" . $solrField["identifier"] . "_dt";
             $date = new DateTime();
             $date->setTimestamp((int) $solrField["value"]);
             $solrvalue = $date->format("Y-m-d\\TH:i:s\\Z");
         }
         if ($solrField["type"] == "ezxmltext") {
             $ident = "attr_" . $solrField["identifier"] . "_ms";
             $textcontent = $solrField["data"]->textContent;
             $solrvalue = $solrField["value"];
             $tident = "attr_" . $solrField["identifier"] . "_s";
             $doc1->{$tident} = $textcontent;
         }
         if ($solrField["type"] == "ezgmaplocation") {
             $ident = "attr_" . $solrField["identifier"] . "_gpt";
             $solrvalue = $solrField["value"]["longitude"] . "," . $solrField["value"]["latitude"];
         }
         $doc1->{$ident} = $solrvalue;
     }
     $update->addDocuments(array($doc1));
     $result = $client->update($update);
     /*
     $durationInMilliseconds = (microtime(true) - $startzeit) * 1000;
     $timing = number_format($durationInMilliseconds, 3, '.', '') . "ms";
     if($durationInMilliseconds > 1000)
     {
         $timing = number_format($durationInMilliseconds / 1000, 1, '.', '') . "sec";
     }
     echo "\nI:" . $timing . "\n";
     */
     /* Orig creation
             
             $this->repository->beginTransaction();
             try
             {
                 $spiContent = $this->persistenceHandler->contentHandler()->create( $spiContentCreateStruct );
                 $this->relationProcessor->processFieldRelations(
                     $inputRelations,
                     $spiContent->versionInfo->contentInfo->id,
                     $spiContent->versionInfo->versionNo,
                     $contentCreateStruct->contentType
                 );
     
                 foreach ( $defaultObjectStates as $objectStateGroupId => $objectState )
                 {
                     $this->persistenceHandler->objectStateHandler()->setContentState(
                         $spiContent->versionInfo->contentInfo->id,
                         $objectStateGroupId,
                         $objectState->id
                     );
                 }
     
                 $this->repository->commit();
             }
             catch ( Exception $e )
             {
                 $this->repository->rollback();
                 throw $e;
             }
         
             return $this->domainMapper->buildContentDomainObject( $spiContent );
             */
 }