protected function execute(InputInterface $input, OutputInterface $output)
 {
     $client = new \Solarium\Client($this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
     try {
         $output->writeln("Creating a new Article and do commit.");
         $repository = $this->getContainer()->get('ezpublish.solrapi.repository');
         $contentService = $repository->getContentService();
         $locationService = $repository->getLocationService();
         $contentTypeService = $repository->getContentTypeService();
         $repository->setCurrentUser($repository->getUserService()->loadUser(14));
         $parentLocationId = 2;
         // instantiate a location create struct from the parent location
         $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);
         $contentTypeIdentifier = "s_artikel";
         $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'ger-DE');
         $titel = "Ein neuer Artikel " . rand(2, 9876987);
         $veroeffentlichungsdatum = 1409131877;
         $vorspann = "<p>Dieser Artikel hat einen relativ langen Vorspann. Wie eigentlich auch immer.</p>";
         $haupttext = "<p>Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext.\nDieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext.\nDieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. \nDieser Artikel hat einen relativ <b>kurzen</b> Haupttext. \n</p>";
         $schlagwoerter = array("Solr", "neuer Artikel", "Gewitter");
         $rubriken = array("Nachrichten", "Meinung");
         $url = "http://www.test.de/Nachrichten/Lokales/Hannover";
         $contentCreateStruct->setField('titel', $titel);
         $contentCreateStruct->setField('veroeffentlichungsdatum', $veroeffentlichungsdatum);
         $contentCreateStruct->setField('vorspann', $vorspann);
         $contentCreateStruct->setField('haupttext', $haupttext);
         $contentCreateStruct->setField('schlagwoerter', $schlagwoerter);
         $contentCreateStruct->setField('rubriken', $rubriken);
         $contentCreateStruct->setField('url', $url);
         $draft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
         $update = $client->createUpdate();
         $update->addCommit();
         $result = $client->update($update);
         #$content = $contentService->publishVersion( $draft->versionInfo );
         $output->writeln("Done.");
     } catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentValidationException $e) {
         $output->writeln($e->getMessage());
     }
 }
Пример #2
0
<?php

require __DIR__ . '/init.php';
htmlHeader();
// create a client instance
$client = new Solarium\Client($config);
// get an update query instance
$update = $client->createUpdate();
// create a new document for the data
$doc1 = $update->createDocument();
$doc1->id = 123;
$doc1->name = 'testdoc-1';
$doc1->price = 364;
// and a second one
$doc2 = $update->createDocument();
$doc2->id = 124;
$doc2->name = 'testdoc-2';
$doc2->price = 340;
// add the documents and a commit command to the update query
$update->addDocuments(array($doc1, $doc2));
$update->addCommit();
// this executes the query and returns the result
$result = $client->update($update);
echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus() . '<br/>';
echo 'Query time: ' . $result->getQueryTime();
htmlFooter();
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $client = new \Solarium\Client($this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
     try {
         $output->writeln("Start...");
         $this->startTiming("start");
         #$update = $client->createUpdate();
         #$update->addCommit();
         #$result = $client->update($update);
         #die("Alles committed");
         #$update = $client->createUpdate();
         #$update->addDeleteQuery('meta_class_name_ms:"Video"');
         #$update->addDeleteQuery('*:*');
         #$update->addCommit();
         #$result = $client->update($update);
         #die("alles is weck");
         #$output->writeln( "Time until solr cleaned:" . $this->getTimingToNow( "start" ) );
         /** @var $repository \eZ\Publish\API\Repository\Repository */
         #$repository = $this->getContainer()->get( 'ezpublish.api.repository' );
         $repository = $this->getContainer()->get('ezpublish.solrapi.repository');
         $output->writeln("Time until repo loaded:" . $this->getTimingToNow("start"));
         $contentService = $repository->getContentService();
         $locationService = $repository->getLocationService();
         $contentTypeService = $repository->getContentTypeService();
         $repository->setCurrentUser($repository->getUserService()->loadUser(14));
         $parentLocationId = 2;
         // instantiate a location create struct from the parent location
         $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);
         $this->startTiming("contentcreation_all");
         $onlycreatemilliseconds = 0;
         for ($i = 1; $i <= 10; $i++) {
             $this->startTiming("contentcreation_item");
             $contentTypeIdentifier = "s_artikel";
             $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
             $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'ger-DE');
             $titel = "Titel neuer Solr Artikel Nr. {$i} " . rand(2, 9876987);
             $veroeffentlichungsdatum = 1409131877;
             $vorspann = "<p>Dieser Artikel hat einen relativ langen Vorspann. Wie eigentlich auch immer.</p>";
             $haupttext = "<p>Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext.\nDieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext.\nDieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. Dieser Artikel hat einen relativ <b>kurzen</b> Haupttext. \nDieser Artikel hat einen relativ <b>kurzen</b> Haupttext. \n</p>";
             $schlagwoerter = array("Solr", "neuer Artikel", "Gewitter");
             $rubriken = array("Nachrichten", "Meinung");
             $url = "http://www.test.de/Nachrichten/Lokales/Hannover";
             $contentCreateStruct->setField('titel', $titel);
             $contentCreateStruct->setField('veroeffentlichungsdatum', $veroeffentlichungsdatum);
             $contentCreateStruct->setField('vorspann', $vorspann);
             $contentCreateStruct->setField('haupttext', $haupttext);
             $contentCreateStruct->setField('schlagwoerter', $schlagwoerter);
             $contentCreateStruct->setField('rubriken', $rubriken);
             $contentCreateStruct->setField('url', $url);
             #$contentCreateStruct->setField( 'my_integer', rand(2, 9876987) );
             #$contentCreateStruct->setField( 'my_xml', $meinXML );
             #$contentCreateStruct->setField( 'my_text', $body );
             #$contentCreateStruct->setField( 'my_int', 12 );
             #$contentCreateStruct->setField( 'my_keyword', array("Nachrichten","Gewitter" ));
             #$contentCreateStruct->setField( 'my_boolean', true );
             #$contentCreateStruct->setField( 'my_time', 1245253245 );
             #$contentCreateStruct->setField( 'my_datetime', 326325600 );
             #$contentCreateStruct->setField( 'my_float', 5.2214 );
             #$contentCreateStruct->setField( 'my_geo', array( "longitude" => 42.117629, "latitude" => -70.956766, "address" => "Abington, MA" ));
             // create a draft using the content and location create struct and publish it
             $startmillimeasure = microtime(true);
             $draft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
             $endmillimeasure = microtime(true);
             $onlycreatemilliseconds = $onlycreatemilliseconds + ($endmillimeasure - $startmillimeasure) * 1000;
             $output->writeln("Time for item " . $i . " :" . $this->getTimingToNow("contentcreation_item"));
         }
         $output->writeln("Time for contentcreation:" . $this->getTimingToNow("contentcreation_all"));
         $this->startTiming("addcommitattheend");
         $update = $client->createUpdate();
         $update->addCommit();
         $result = $client->update($update);
         $output->writeln("Time for COMMIT:" . $this->getTimingToNow("addcommitattheend"));
         $output->writeln("Time until end:" . $this->getTimingToNow("start"));
         $output->writeln("Time only for create:" . number_format($onlycreatemilliseconds / 1000, 1, '.', '') . " sec");
         # We do not publish, creation is done while creating draft since NO versioning
         #$content = $contentService->publishVersion( $draft->versionInfo );
     } catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentValidationException $e) {
         $output->writeln($e->getMessage());
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $client = new \Solarium\Client($this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
     try {
         $repository = $this->getContainer()->get('ezpublish.solrapi.repository');
         $contentService = $repository->getContentService();
         $locationService = $repository->getLocationService();
         $contentTypeService = $repository->getContentTypeService();
         $repository->setCurrentUser($repository->getUserService()->loadUser(14));
         $parentLocationId = 2;
         // instantiate a location create struct from the parent location
         $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);
         # Creating s_artikel
         $output->writeln("Creating a new Article and do commit.");
         $contentTypeIdentifier = "s_artikel";
         $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'ger-DE');
         $titel = "Circus Halligalli " . rand(2, 9876987);
         $veroeffentlichungsdatum = 1409131877;
         $vorspann = "<p>Es war einmal in einem tiefen dunklen Wald..</p>";
         $haupttext = "<p>Hier lebte die Bärenfamilie..</p>";
         $schlagwoerter = array("Bär", "Wald");
         $rubriken = array("News", "Winter");
         $url = "http://www.halligalli.de/Nachrichten/Lokales/";
         $contentCreateStruct->setField('titel', $titel);
         $contentCreateStruct->setField('veroeffentlichungsdatum', $veroeffentlichungsdatum);
         $contentCreateStruct->setField('vorspann', $vorspann);
         $contentCreateStruct->setField('haupttext', $haupttext);
         $contentCreateStruct->setField('schlagwoerter', $schlagwoerter);
         $contentCreateStruct->setField('rubriken', $rubriken);
         $contentCreateStruct->setField('url', $url);
         $draft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
         $update = $client->createUpdate();
         $update->addCommit();
         $result = $client->update($update);
         $output->writeln("Artikel erzeugt.");
         # Creating s_artikel
         $output->writeln("Creating a new Foto and do commit.");
         $contentTypeIdentifier = "s_foto";
         $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'ger-DE');
         $data = array();
         $data["veroeffentlichungsdatum"] = 1409141879;
         $data["titel"] = "Ein neues Foto Nr." . rand(2, 9876987);
         $data["schlagwoerter"] = array("Fotolia", "Wald");
         $data["rubriken"] = array("Fotostrecke", "Sommer");
         $data["url"] = "http://www.xrow.de/Keyword";
         $contentCreateStruct->setField('veroeffentlichungsdatum', $data["veroeffentlichungsdatum"]);
         $contentCreateStruct->setField('titel', $data["titel"]);
         $contentCreateStruct->setField('schlagwoerter', $data["schlagwoerter"]);
         $contentCreateStruct->setField('rubriken', $data["rubriken"]);
         $contentCreateStruct->setField('url', $data["url"]);
         $draft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
         $update = $client->createUpdate();
         $update->addCommit();
         $result = $client->update($update);
         $output->writeln("Foto erzeugt erzeugt.");
         # Creating s_artikel
         $output->writeln("Creating a new Veranstaltung and do commit.");
         $contentTypeIdentifier = "s_veranstaltung";
         $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'ger-DE');
         $data = array();
         $data["veranstaltungsbeginn"] = 1409141879;
         $data["veranstaltungsende"] = 1409241879;
         $data["titel"] = "Eine neue Veranstaltung Nr." . rand(2, 9876987);
         $data["teaser"] = "Veranstaltung im neuen Rathaus";
         $data["haupttext"] = "<p>Im neuen Rathaus findet am 3.10.2014 eine ganz tolle Veranstaltung statt. Seien Sie dabei.</p>";
         $data["homepage_veranstaltung"] = "http://www.hannover.de";
         $data["homepage_staette"] = "http://www.neuesrathaus-hannover.de";
         $data["staette"] = array("Neues Rathaus");
         $data["stadt"] = "Hannover";
         $data["geodaten"] = array("longitude" => 42.117629, "latitude" => -70.956766, "address" => "Abington, MA");
         $data["rubriken"] = array("Veranstaltung", "Herbst");
         $data["url"] = "http://www.veranstaltung.de";
         $data["bild_url"] = "http://upload.wikimedia.org/wikipedia/commons/c/ce/Neues_Rathaus_Hannover_001.JPG";
         $contentCreateStruct->setField('veranstaltungsbeginn', $data["veranstaltungsbeginn"]);
         $contentCreateStruct->setField('veranstaltungsende', $data["veranstaltungsende"]);
         $contentCreateStruct->setField('titel', $data["titel"]);
         $contentCreateStruct->setField('teaser', $data["teaser"]);
         $contentCreateStruct->setField('haupttext', $data["haupttext"]);
         $contentCreateStruct->setField('homepage_veranstaltung', $data["homepage_veranstaltung"]);
         $contentCreateStruct->setField('homepage_staette', $data["homepage_staette"]);
         $contentCreateStruct->setField('staette', $data["staette"]);
         $contentCreateStruct->setField('stadt', $data["stadt"]);
         $contentCreateStruct->setField('geodaten', $data["geodaten"]);
         $contentCreateStruct->setField('rubriken', $data["rubriken"]);
         $contentCreateStruct->setField('url', $data["url"]);
         $contentCreateStruct->setField('bild_url', $data["bild_url"]);
         $draft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
         $update = $client->createUpdate();
         $update->addCommit();
         $result = $client->update($update);
         $output->writeln("Veranstaltung erzeugt erzeugt.");
         $output->writeln("Done.");
     } catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentValidationException $e) {
         $output->writeln($e->getMessage());
     }
 }
 /**
  * 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 );
             */
 }
 /**
  * Executes the command
  * 
  * @param InputInterface $input            
  * @param OutputInterface $output            
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $sourcefile = $input->getOption('source');
     $contentTypeIdentifier = $input->getOption('class');
     $limitopt = $input->getOption('limit');
     $offsetopt = $input->getOption('offset');
     try {
         $startzeit = microtime(true);
         $output->writeln("Starting Import");
         $output->writeln("---------------");
         $output->writeln("");
         // PREPARING
         $repository = $this->getContainer()->get('ezpublish.solrapi.repository');
         $repository1 = $this->getContainer()->get('ezpublish.solrapi.repository');
         $repository2 = $this->getContainer()->get('ezpublish.solrapi.repository');
         $contentTypeService = $repository->getContentTypeService();
         $locationService = $repository->getLocationService();
         $parentLocationId = 2;
         $location = $locationService->newLocationCreateStruct($parentLocationId);
         $location1 = $locationService->newLocationCreateStruct($parentLocationId);
         $location2 = $locationService->newLocationCreateStruct($parentLocationId);
         $ContentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         $ContentType1 = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         $ContentType2 = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         // IMPORTING NOW
         $offset = 0;
         $limit = 2000;
         if ($offsetopt !== null) {
             $offset = $offsetopt;
         }
         if ($limitopt !== null) {
             $limit = $limitopt;
         }
         // test to see if threading is available
         if (!Core_Thread::available()) {
             die('Threads not supported');
         }
         #var_dump(self::paralel(10, "t1"));
         // create 2 thread objects
         $t1 = new Core_Thread(array('xrow\\EzPublishSolrDocsBundle\\Command\\OdataImportCommand', '_doImport'));
         $t2 = new Core_Thread(array('xrow\\EzPublishSolrDocsBundle\\Command\\OdataImportCommand', '_doImport'));
         // start them
         $t1->start($sourcefile, 0, 10, $location1, $ContentType1, $repository1, $output, $startzeit);
         $t2->start($sourcefile, 11, 10, $location2, $ContentType2, $repository2, $output, $startzeit);
         // keep the program running until the threads finish
         while ($t1->isAlive() && $t2->isAlive()) {
         }
         #self::_doImport($sourcefile, $offset, $limit, $location, $ContentType, $repository, $output, $startzeit);
         /*
                     $source = new OData\Source( $sourcefile, $offset, $limit);
                     
                     $output->writeln("Sourced " . $sourcefile);
                     $output->writeln("---------------");
                     $output->writeln("");
                     
                     $import = new Import\Process( $location, $ContentType, $source, $repository );
         $output->writeln("Validate and go");
                     $output->writeln("---------------");
                     $output->writeln("");
                     
                     if($import->validate( $source ))
                     {
                         $output->writeln("Import is valid.");
                         $output->writeln("Rows: " . $source->count());
                         $import->import($source);
                     }
                     else
                     {
                         $output->writeln("Import is NOT valid.");
                     }
                     $output->writeln("");
                     $output->writeln("---------------");
                     $output->writeln("Finished Import.");
                     
                     // ECHO TIMING
                     $durationInMilliseconds = (microtime(true) - $startzeit) * 1000;
                     $timing = number_format($durationInMilliseconds, 3, '.', '') . "ms";
                     if($durationInMilliseconds > 1000)
                     {
                         $timing = number_format($durationInMilliseconds / 1000, 1, '.', '') . "sec";
                     }
                     $output->writeln("Dauer: " . $timing);
         */
         // DOING COMMIT
         $client = new \Solarium\Client($this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
         $update = $client->createUpdate();
         $update->addCommit();
         $result = $client->update($update);
         $output->writeln("");
         $output->writeln("COMMIT done");
     } catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentValidationException $e) {
         $output->writeln($e->getMessage());
     }
 }
Пример #7
0
        }
        //$ch = curl_init("http://en.wikipedia.org/w/api.php?action=parse&pageid=".$id."&format=json&prop=text");
        $ch = curl_init("http://en.wikipedia.org/w/api.php?action=query&pageids=" . $id . "&format=json&prop=extracts");
        curl_setopt($ch, CURLOPT_HTTPGET, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
        $result = curl_exec($ch);
        curl_close($ch);
        $darr = json_decode($result);
        $obj = $darr->query->pages;
        foreach ($obj as $key => $val) {
            $title = $val->title;
            $summary = $val->extract;
        }
        $wikiclient = new \Solarium\Client(Config::get('solr'));
        $update = $wikiclient->createUpdate();
        $doc = $update->createDocument();
        $doc->id = $id;
        $doc->title = $title;
        $doc->revision = $id;
        $doc->author = "DYNAMIC";
        $doc->authorid = "1010";
        $doc->timestamp = gmdate('Y-m-d\\TH:i:s\\Z', time());
        $doc->content = $summary;
        $update->addDocument($doc);
        $update->addCommit();
        $result = $wikiclient->update($update);
        ?>
					<article>
					<div class="postloopBig">
						<div class="loopBigThumb" style="height:350px;background-color:#000000;">
 /**
  * Executes the command
  * 
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $sourcefile = $input->getOption('source');
     $contentTypeIdentifier = $input->getOption('class');
     $limitopt = $input->getOption('limit');
     $offsetopt = $input->getOption('offset');
     $processesopt = $input->getOption('conc');
     // Check Cleaning before import
     switch ($input->getOption('clean')) {
         case "no":
             $output->writeln("Not cleaning");
             break;
         case "all":
             $output->writeln("CLEANING ALL!");
             $client = new \Solarium\Client($this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
             $update = $client->createUpdate();
             #$update->addDeleteQuery('meta_class_name_ms:"Video"');
             $update->addDeleteQuery('*:*');
             $update->addCommit();
             $result = $client->update($update);
             break;
         case "class":
             $output->writeln("CLEANING CLASS: " . $contentTypeIdentifier);
             $client = new \Solarium\Client($this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
             $update = $client->createUpdate();
             $update->addDeleteQuery('meta_class_identifier_ms:"' . trim($contentTypeIdentifier) . '"');
             $update->addCommit();
             $result = $client->update($update);
             break;
         case "location":
             $output->writeln("CLEANING Location: " . $input->getOption('location'));
             $client = new \Solarium\Client($this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
             $url = trim($input->getOption('location'), '/');
             $url_array = explode("/", $url);
             $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;
             }
             $update = $client->createUpdate();
             $update->addDeleteQuery('meta_parent_url_alias_ms:"' . array_pop($url_alias_cats) . '"');
             $update->addCommit();
             $result = $client->update($update);
             break;
         default:
             $output->writeln("CLEANING anything since no vaild option.");
     }
     try {
         $startzeit = microtime(true);
         $output->writeln("Starting Import...");
         $output->writeln("------------------");
         $output->writeln("");
         // PREPARING
         $repository = $this->getContainer()->get('ezpublish.solrapi.repository');
         $repository->setCurrentUser($repository->getUserService()->loadUser(14));
         $contentTypeService = $repository->getContentTypeService();
         $locationService = $repository->getLocationService();
         $parentLocation = $input->getOption('location');
         #$parentLocationId = 2;
         $location = $locationService->newLocationCreateStruct($parentLocation);
         $ContentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
         $classes = $this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solr_classes');
         $contentTypeIdentifierarray = $classes[$contentTypeIdentifier];
         // IMPORTING NOW
         try {
             $source = new OData\Source($sourcefile, $offsetopt, $limitopt, $contentTypeIdentifierarray);
         } catch (\Exception $e) {
             $output->writeln("Error: " . $e->getMessage());
             $output->writeln("Import stops here.");
             exit;
         }
         $output->writeln("Sourced: " . $sourcefile);
         #$output->writeln("---------------");
         $output->writeln("");
         $import = new Import\Process($location, $ContentType, $source, $repository, $processesopt);
         $output->writeln("Validating...");
         #$output->writeln("---------------");
         $output->writeln("");
         if ($import->validate($sourcefile)) {
             $output->writeln("");
             $output->writeln("Rows in total: " . $source->count());
             $import->import($source);
         } else {
             $output->writeln("Import is NOT valid.");
         }
         $output->writeln("");
         $output->writeln("---------------");
         $output->writeln("Finished Import.");
         // ECHO TIMING
         $durationInMilliseconds = (microtime(true) - $startzeit) * 1000;
         $timing = number_format($durationInMilliseconds, 3, '.', '') . "ms";
         if ($durationInMilliseconds > 1000) {
             $timing = number_format($durationInMilliseconds / 1000, 1, '.', '') . "sec";
         }
         $output->writeln("Dauer: " . $timing);
         // DOING COMMIT
         $client = new \Solarium\Client($this->getContainer()->getParameter('xrow_ez_publish_solr_docs.solrserverconfig'));
         $update = $client->createUpdate();
         $update->addCommit();
         $result = $client->update($update);
         $output->writeln("");
         $output->writeln("COMMIT done");
     } catch (\eZ\Publish\API\Repository\Exceptions\NotFoundException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e) {
         $output->writeln($e->getMessage());
     } catch (\eZ\Publish\API\Repository\Exceptions\ContentValidationException $e) {
         $output->writeln($e->getMessage());
     }
 }