/** * Appends destination Content ids of given $fieldValue to the $relation array. * * If $fieldValue contains Location ids, the will be converted to the Content id that Location encapsulates. * * @param array $relations * @param array $locationIdToContentIdMapping An array with Location Ids as keys and corresponding Content Id as values * @param \eZ\Publish\SPI\FieldType\FieldType $fieldType * @param \eZ\Publish\Core\FieldType\Value $fieldValue Accepted field value. * @param string $fieldDefinitionId */ public function appendFieldRelations(array &$relations, array &$locationIdToContentIdMapping, SPIFieldType $fieldType, BaseValue $fieldValue, $fieldDefinitionId) { foreach ($fieldType->getRelations($fieldValue) as $relationType => $destinationIds) { if ($relationType === Relation::FIELD) { if (!isset($relations[$relationType][$fieldDefinitionId])) { $relations[$relationType][$fieldDefinitionId] = array(); } $relations[$relationType][$fieldDefinitionId] += array_flip($destinationIds); } elseif ($relationType & (Relation::LINK | Relation::EMBED)) { // Using bitwise operators as Legacy Stack stores COMMON, LINK and EMBED relation types // in the same entry using bitmask if (!isset($relations[$relationType])) { $relations[$relationType] = array(); } if (isset($destinationIds['locationIds'])) { foreach ($destinationIds['locationIds'] as $locationId) { if (!isset($locationIdToContentIdMapping[$locationId])) { $location = $this->persistenceHandler->locationHandler()->load($locationId); $locationIdToContentIdMapping[$locationId] = $location->contentId; } $relations[$relationType][$locationIdToContentIdMapping[$locationId]] = true; } } if (isset($destinationIds['contentIds'])) { $relations[$relationType] += array_flip($destinationIds['contentIds']); } } } }
/** * Appends destination Content ids of given $fieldValue to the $relation array. * * If $fieldValue contains Location ids, the will be converted to the Content id that Location encapsulates. * * @param array $relations * @param array $locationIdToContentIdMapping An array with Location Ids as keys and corresponding Content Id as values * @param \eZ\Publish\SPI\FieldType\FieldType $fieldType * @param \eZ\Publish\Core\FieldType\Value $fieldValue Accepted field value. * @param string $fieldDefinitionId * * @return void */ public function appendFieldRelations(array &$relations, array &$locationIdToContentIdMapping, SPIFieldType $fieldType, BaseValue $fieldValue, $fieldDefinitionId) { foreach ($fieldType->getRelations($fieldValue) as $relationType => $destinationIds) { if ($relationType === Relation::FIELD) { if (!isset($relations[$relationType][$fieldDefinitionId])) { $relations[$relationType][$fieldDefinitionId] = array(); } $relations[$relationType][$fieldDefinitionId] += array_flip($destinationIds); } else { if ($relationType & (Relation::LINK | Relation::EMBED)) { if (!isset($relations[$relationType])) { $relations[$relationType] = array(); } if (isset($destinationIds["locationIds"])) { foreach ($destinationIds["locationIds"] as $locationId) { if (!isset($locationIdToContentIdMapping[$locationId])) { $location = $this->persistenceHandler->locationHandler()->load($locationId); $locationIdToContentIdMapping[$locationId] = $location->contentId; } $relations[$relationType][$locationIdToContentIdMapping[$locationId]] = true; } } if (isset($destinationIds["contentIds"])) { $relations[$relationType] += array_flip($destinationIds["contentIds"]); } } } } }
/** * 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; }
/** * Deletes $location and all its descendants. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to delete this location or a descendant * * @param \eZ\Publish\API\Repository\Values\Content\Location $location */ public function deleteLocation(APILocation $location) { $location = $this->loadLocation($location->id); if (!$this->repository->canUser('content', 'manage_locations', $location->getContentInfo())) { throw new UnauthorizedException('content', 'manage_locations'); } if (!$this->repository->canUser('content', 'remove', $location->getContentInfo(), $location)) { throw new UnauthorizedException('content', 'remove'); } /** Check remove access to descendants * @var boolean|\eZ\Publish\API\Repository\Values\Content\Query\Criterion $contentReadCriterion */ $contentReadCriterion = $this->permissionsCriterionHandler->getPermissionsCriterion('content', 'remove'); if ($contentReadCriterion === false) { throw new UnauthorizedException('content', 'remove'); } else { if ($contentReadCriterion !== true) { // Query if there are any content in subtree current user don't have access to $query = new Query(array('limit' => 0, 'filter' => new CriterionLogicalAnd(array(new CriterionSubtree($location->pathString), new CriterionLogicalNot($contentReadCriterion))))); $result = $this->repository->getSearchService()->findContent($query, array(), false); if ($result->totalCount > 0) { throw new UnauthorizedException('content', 'remove'); } } } $this->repository->beginTransaction(); try { $this->persistenceHandler->locationHandler()->removeSubtree($location->id); $this->persistenceHandler->urlAliasHandler()->locationDeleted($location->id); $this->repository->commit(); } catch (Exception $e) { $this->repository->rollback(); throw $e; } }
/** * Deletes a content object including all its versions and locations including their subtrees. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object) * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */ public function deleteContent( ContentInfo $contentInfo ) { $contentInfo = $this->internalLoadContentInfo( $contentInfo->id ); if ( !$this->repository->canUser( 'content', 'remove', $contentInfo ) ) throw new UnauthorizedException( 'content', 'remove', array( 'contentId' => $contentInfo->id ) ); $this->repository->beginTransaction(); try { // Load Locations first as deleting Content also deletes belonging Locations $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent( $contentInfo->id ); $this->persistenceHandler->contentHandler()->deleteContent( $contentInfo->id ); foreach ( $spiLocations as $spiLocation ) { $this->persistenceHandler->urlAliasHandler()->locationDeleted( $spiLocation->id ); } $this->repository->commit(); } catch ( Exception $e ) { $this->repository->rollback(); throw $e; } }
/** * 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; }