/** * Adds object $contentObject to the search database. * * @param \eZContentObject $contentObject Object to add to search engine * @param bool $commit Whether to commit after adding the object * * @return bool True if the operation succeeded. */ public function addObject($contentObject, $commit = true) { // Indexing is not implemented in eZ Publish 5 legacy search engine if ($this->searchHandler instanceof LegacyHandler) { $searchEngine = new eZSearchEngine(); $searchEngine->addObject($contentObject, $commit); return true; } try { // If the method is called for restoring from trash we'll be inside a transaction, // meaning created Location(s) will not be visible outside of it. // We check that Content's Locations are visible from the new stack, if not Content // will be registered for indexing. foreach ($contentObject->assignedNodes() as $node) { $this->persistenceHandler->locationHandler()->load($node->attribute('node_id')); } $content = $this->persistenceHandler->contentHandler()->load((int) $contentObject->attribute('id'), (int) $contentObject->attribute('current_version')); } catch (NotFoundException $e) { $pendingAction = new eZPendingActions(array('action' => 'index_object', 'created' => time(), 'param' => (int) $contentObject->attribute('id'))); $pendingAction->store(); return true; } $this->searchHandler->indexContent($content); if ($commit) { $this->commit(); } return true; }
/** * Adds object $contentObject to the search database. * * @param \eZContentObject $contentObject Object to add to search engine * @param bool $commit Whether to commit after adding the object * * @return bool True if the operation succeeded. */ public function addObject($contentObject, $commit = true) { // Indexing is not implemented in eZ Publish 5 legacy search engine if ($this->searchEngine == 'legacy') { $searchEngine = new eZSearchEngine(); $searchEngine->addObject($contentObject, $commit); } else { $content = $this->persistenceHandler->contentHandler()->load((int) $contentObject->attribute('id'), (int) $contentObject->attribute('current_version')); $this->searchHandler->indexContent($content); } if ($commit) { $this->commit(); } return true; }
/** * Removes a relation of type COMMON from a draft. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent */ public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) { $sourceVersion = $this->loadVersionInfoById($sourceVersion->contentInfo->id, $sourceVersion->versionNo); if ($sourceVersion->status !== APIVersionInfo::STATUS_DRAFT) { throw new BadStateException('$sourceVersion', 'Relations of type common can only be removed from versions of status draft'); } if (!$this->repository->canUser('content', 'edit', $sourceVersion)) { throw new UnauthorizedException('content', 'edit', array('contentId' => $sourceVersion->contentInfo->id)); } $spiRelations = $this->persistenceHandler->contentHandler()->loadRelations($sourceVersion->getContentInfo()->id, $sourceVersion->versionNo, APIRelation::COMMON); if (empty($spiRelations)) { throw new InvalidArgumentException('$sourceVersion', 'There are no relations of type COMMON for the given destination'); } // there should be only one relation of type COMMON for each destination, // but in case there were ever more then one, we will remove them all // @todo: alternatively, throw BadStateException? $this->repository->beginTransaction(); try { foreach ($spiRelations as $spiRelation) { if ($spiRelation->destinationContentId == $destinationContent->id) { $this->persistenceHandler->contentHandler()->removeRelation($spiRelation->id, APIRelation::COMMON); } } $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { @trigger_error(sprintf('%s is deprecated since 6.7. Use ezplatform:reindex command instead', $this->getName()), E_USER_DEPRECATED); $bulkCount = $input->getArgument('bulk_count'); // Indexing Content $totalCount = $this->getContentObjectsTotalCount($this->databaseHandler, ContentInfo::STATUS_PUBLISHED); $query = $this->databaseHandler->createSelectQuery(); $query->select('id', 'current_version')->from('ezcontentobject')->where($query->expr->eq('status', ContentInfo::STATUS_PUBLISHED)); $stmt = $query->prepare(); $stmt->execute(); $this->searchHandler->purgeIndex(); $output->writeln('Indexing Content...'); /* @var \Symfony\Component\Console\Helper\ProgressHelper $progress */ $progress = $this->getHelperSet()->get('progress'); $progress->start($output, $totalCount); $i = 0; do { $contentObjects = []; for ($k = 0; $k <= $bulkCount; ++$k) { if (!($row = $stmt->fetch(PDO::FETCH_ASSOC))) { break; } try { $contentObjects[] = $this->persistenceHandler->contentHandler()->load($row['id'], $row['current_version']); } catch (NotFoundException $e) { $this->logWarning($output, $progress, "Could not load current version of Content with id {$row['id']}, so skipped for indexing. Full exception: " . $e->getMessage()); } } $this->searchHandler->bulkIndex($contentObjects, function (Content $content, NotFoundException $e) use($output, $progress) { $this->logWarning($output, $progress, 'Content with id ' . $content->versionInfo->id . ' has missing data, so skipped for indexing. Full exception: ' . $e->getMessage()); }); $progress->advance($k); } while (($i += $bulkCount) < $totalCount); $progress->finish(); }
/** * Get RelationProcessor. * * * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. * * @return \eZ\Publish\Core\Repository\Helper\DomainMapper */ protected function getDomainMapper() { if ($this->domainMapper !== null) { return $this->domainMapper; } $this->domainMapper = new Helper\DomainMapper($this->persistenceHandler->contentHandler(), $this->persistenceHandler->locationHandler(), $this->persistenceHandler->contentTypeHandler(), $this->persistenceHandler->contentLanguageHandler(), $this->getFieldTypeRegistry()); return $this->domainMapper; }
/** * Persists relation data for a content version. * * This method creates new relations and deletes removed relations. * * @param array $inputRelations * @param mixed $sourceContentId * @param mixed $sourceContentVersionNo * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $existingRelations An array of existing relations for Content version (empty when creating new content) * * @return void */ public function processFieldRelations(array $inputRelations, $sourceContentId, $sourceContentVersionNo, ContentType $contentType, array $existingRelations = array()) { // Map existing relations for easier handling $mappedRelations = array(); foreach ($existingRelations as $relation) { if ($relation->type === Relation::FIELD) { $fieldDefinitionId = $contentType->getFieldDefinition($relation->sourceFieldDefinitionIdentifier)->id; $mappedRelations[$relation->type][$fieldDefinitionId][$relation->destinationContentInfo->id] = $relation; } // Using bitwise AND as Legacy Stack stores COMMON, LINK and EMBED relation types // in the same entry using bitmask if ($relation->type & Relation::LINK) { $mappedRelations[Relation::LINK][$relation->destinationContentInfo->id] = $relation; } if ($relation->type & Relation::EMBED) { $mappedRelations[Relation::EMBED][$relation->destinationContentInfo->id] = $relation; } } // Add new relations foreach ($inputRelations as $relationType => $relationData) { if ($relationType === Relation::FIELD) { foreach ($relationData as $fieldDefinitionId => $contentIds) { foreach (array_keys($contentIds) as $destinationContentId) { if (isset($mappedRelations[$relationType][$fieldDefinitionId][$destinationContentId])) { unset($mappedRelations[$relationType][$fieldDefinitionId][$destinationContentId]); } else { $this->persistenceHandler->contentHandler()->addRelation(new SPIRelationCreateStruct(array("sourceContentId" => $sourceContentId, "sourceContentVersionNo" => $sourceContentVersionNo, "sourceFieldDefinitionId" => $fieldDefinitionId, "destinationContentId" => $destinationContentId, "type" => $relationType))); } } } } else { if ($relationType === Relation::LINK || $relationType === Relation::EMBED) { foreach (array_keys($relationData) as $destinationContentId) { if (isset($mappedRelations[$relationType][$destinationContentId])) { unset($mappedRelations[$relationType][$destinationContentId]); } else { $this->persistenceHandler->contentHandler()->addRelation(new SPIRelationCreateStruct(array("sourceContentId" => $sourceContentId, "sourceContentVersionNo" => $sourceContentVersionNo, "sourceFieldDefinitionId" => null, "destinationContentId" => $destinationContentId, "type" => $relationType))); } } } } } // Remove relations not present in input set foreach ($mappedRelations as $relationType => $relationData) { foreach ($relationData as $relationEntry) { switch ($relationType) { case Relation::FIELD: foreach ($relationEntry as $relation) { $this->persistenceHandler->contentHandler()->removeRelation($relation->id, $relationType); } break; case Relation::LINK: case Relation::EMBED: $this->persistenceHandler->contentHandler()->removeRelation($relationEntry->id, $relationType); } } } }