/**
  * 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;
     }
 }
    /**
     * Finds Locations for the given query.
     *
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid
     *
     * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query
     * @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 findLocations( LocationQuery $query, $filterOnUserPermissions = true )
    {
        $query = clone $query;
        $query->filter = $query->filter ?: new Criterion\MatchAll();

        $this->validateSortClauses( $query );

        if ( $filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion( $query->filter ) )
        {
            return new SearchResult( array( 'time' => 0, 'totalCount' => 0 ) );
        }

        if ( $query->limit === null )
        {
            $query->limit = self::MAX_LIMIT;
        }

        $result = $this->locationSearchHandler->findLocations( $query );

        foreach ( $result->searchHits as $hit )
        {
            $hit->valueObject = $this->domainMapper->buildLocationDomainObject(
                $hit->valueObject
            );
        }

        return $result;
    }
Пример #3
0
 /**
  * Finds Locations for the given query.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid
  *
  * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query
  * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on.
  *        Currently supports: <code>array("languages" => array(<language1>,..), "useAlwaysAvailable" => bool)</code>
  *                            useAlwaysAvailable defaults to true to avoid exceptions on missing translations
  * @param bool $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 findLocations(LocationQuery $query, array $languageFilter = array(), $filterOnUserPermissions = true)
 {
     if (!is_int($query->offset)) {
         throw new InvalidArgumentType('$query->offset', 'integer', $query->offset);
     }
     if (!is_int($query->limit)) {
         throw new InvalidArgumentType('$query->limit', 'integer', $query->limit);
     }
     $query = clone $query;
     $query->filter = $query->filter ?: new Criterion\MatchAll();
     if ($filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion($query->filter)) {
         return new SearchResult(array('time' => 0, 'totalCount' => 0));
     }
     $result = $this->searchHandler->findLocations($query, $languageFilter);
     foreach ($result->searchHits as $hit) {
         $hit->valueObject = $this->domainMapper->buildLocationDomainObject($hit->valueObject);
     }
     return $result;
 }
 /**
  * Test for the getPermissionsCriterion() method.
  *
  * @dataProvider providerForTestGetPermissionsCriterionBooleanPermissionSets
  */
 public function testGetPermissionsCriterionBooleanPermissionSets($permissionSets)
 {
     $repositoryMock = $this->getRepositoryMock();
     $repositoryMock->expects($this->once())->method("hasAccess")->with($this->equalTo("testModule"), $this->equalTo("testFunction"))->will($this->returnValue($permissionSets));
     $handler = new PermissionsCriterionHandler($this->getRepositoryMock());
     $permissionsCriterion = $handler->getPermissionsCriterion("testModule", "testFunction");
     $this->assertEquals($permissionSets, $permissionsCriterion);
 }