コード例 #1
0
 /**
  * @see eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler
  * @todo Handle field types actions
  */
 public function trashSubtree($locationId)
 {
     $location = $this->handler->locationHandler()->load($locationId);
     $subtreeLocations = $this->backend->find('Content\\Location', array('pathString' => $location->pathString . '%'));
     $isLocationRemoved = false;
     $parentLocationId = null;
     $subtreeLocations[] = $location;
     foreach ($subtreeLocations as $location) {
         if ($location->id == $locationId) {
             $parentLocationId = $location->parentId;
         }
         if (count($this->backend->find('Content\\Location', array('contentId' => $location->contentId))) == 1) {
             $this->backend->delete('Content\\Location', $location->id);
             $this->backend->create('Content\\Location\\Trashed', (array) $location, false);
         } else {
             if ($location->id == $locationId) {
                 $isLocationRemoved = true;
             }
             $this->backend->delete('Content\\Location', $location->id);
             $remainingLocations = $this->backend->find('Content\\Location', array('contentId' => $location->contentId));
             $this->backend->update('Content\\ContentInfo', $location->contentId, array('mainLocationId' => $remainingLocations[0]->id));
         }
     }
     return $isLocationRemoved ? null : $this->loadTrashItem($locationId);
 }
コード例 #2
0
 /**
  * Test finding content with results using join and deep matching where there are several sub elements
  *
  * @covers eZ\Publish\Core\Persistence\InMemory\Backend::find
  * @group inMemoryBackend
  */
 public function testFindJoinDeepMatchWithSeveral()
 {
     // Create a new location on content object 1 so it has 2
     $location = new LocationCreateStruct();
     $location->contentId = 1;
     $location->contentVersion = 1;
     $location->parentId = 1;
     $location->remoteId = 'string';
     $location->pathIdentificationString = '/1/3/';
     $location->sortField = Location::SORT_FIELD_MODIFIED;
     $location->sortOrder = Location::SORT_ORDER_DESC;
     $this->backend->create('Content\\Location', (array) $location);
     /**
      * @var \eZ\Publish\SPI\Persistence\Content[] $list
      */
     $list = $this->backend->find('Content', array("versionInfo" => array('id' => 2)), array('versionInfo' => array('type' => 'Content\\VersionInfo', 'match' => array('_contentId' => 'id', 'versionNo' => '_currentVersionNo'), 'single' => true, 'sub' => array('contentInfo' => array('type' => 'Content\\ContentInfo', 'match' => array('id' => '_contentId'), 'single' => true)))));
     $this->assertEquals(1, count($list));
     foreach ($list as $content) {
         $this->assertTrue($content instanceof Content);
         $this->assertEquals(1, $content->versionInfo->contentInfo->id);
         $this->assertEquals(1, $content->versionInfo->contentInfo->sectionId);
         $locations = $this->backend->find('Content\\Location', array('contentId' => $content->versionInfo->contentInfo->id));
         $this->assertEquals(2, count($locations));
         foreach ($locations as $location) {
             $this->assertTrue($location instanceof Location);
             $this->assertEquals(1, $location->contentId);
         }
     }
 }
コード例 #3
0
 /**
  * Test creating multiple content
  *
  * @covers eZ\Publish\Core\Persistence\InMemory\Backend::create
  */
 public function testCreateMultiple()
 {
     for ($i = 1; $i <= 10; ++$i) {
         $content = $this->backend->create("Content\\ContentInfo", array("sectionId" => 2), true);
         $this->assertEquals($i, $content->id);
     }
 }
コード例 #4
0
 /**
  * Notifies the underlying engine that a location has moved.
  *
  * This method triggers the creation of the autogenerated aliases for the copied locations
  *
  * @param mixed $locationId
  * @param mixed $oldParentId
  * @param mixed $newParentId
  */
 public function locationCopied($locationId, $oldParentId, $newParentId)
 {
     // Get url alias for location
     $list = $this->backend->find('Content\\UrlAlias', array('destination' => $locationId, 'type' => URLAlias::LOCATION, 'isHistory' => false, 'isCustom' => false));
     if (isset($list[1])) {
         throw new \RuntimeException('Found more then 1 url alias pointing to same location: ' . $locationId);
     } else {
         if (empty($list)) {
             throw new \RuntimeException("Did not find any url alias for location:  {$locationId}");
         }
     }
     // Use pathData from existing location
     /** @var \eZ\Publish\SPI\Persistence\Content\UrlAlias[] $list */
     $pathItem = array_pop($list[0]->pathData);
     // Get url alias for new parent location
     $list = $this->backend->find('Content\\UrlAlias', array('destination' => $newParentId, 'type' => URLAlias::LOCATION, 'isHistory' => false, 'isCustom' => false));
     if (isset($list[1])) {
         throw new \RuntimeException('Found more then 1 url alias pointing to same location: ' . $newParentId);
     } else {
         if (empty($list)) {
             throw new \RuntimeException("Did not find any url alias for new parent location: {$newParentId}");
         }
     }
     // Make path data based on new location and the original
     $pathData = $list[0]->pathData;
     $pathData[] = $pathItem;
     $pathIndex = count($pathData) - 1;
     // Create the new url alias object
     $this->backend->create('Content\\UrlAlias', array('parent' => $list[0]->id["link"], 'link' => $this->getNextLinkId(), 'type' => URLAlias::LOCATION, 'destination' => $locationId, 'pathData' => $pathData, 'languageCodes' => array_keys($pathData[$pathIndex]['translations']), 'alwaysAvailable' => $pathData[$pathIndex]['always-available'], 'isHistory' => false, 'isCustom' => false, 'forward' => false));
 }
コード例 #5
0
 /**
  * Adds a new field definition to an existing Type.
  *
  * This method creates a new version of the Type with the $fieldDefinition
  * added. It does not update existing content objects depending on the
  * field (default) values.
  *
  * @param mixed $contentTypeId
  * @param int $status One of Type::STATUS_DEFINED|Type::STATUS_DRAFT|Type::STATUS_MODIFIED
  * @param \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition $fieldDefinition
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If type is not found
  * @todo Add FieldDefintion\CreateStruct?
  */
 public function addFieldDefinition($contentTypeId, $status, FieldDefinition $fieldDefinition)
 {
     $list = $this->backend->find('Content\\Type', array('id' => $contentTypeId, 'status' => $status));
     if (!isset($list[0])) {
         throw new NotFound('Content\\Type', "{$contentTypeId}' and status '{$status}");
     }
     $fieldDefinitionArr = (array) $fieldDefinition;
     $fieldDefinitionArr['_typeId'] = $contentTypeId;
     $fieldDefinitionArr['_status'] = $status;
     return $this->backend->create('Content\\Type\\FieldDefinition', $fieldDefinitionArr);
 }
コード例 #6
0
 /**
  * Creates a new object state in the given group.
  * The new state gets the last priority.
  * Note: in current kernel: If it is the first state all content objects will
  * set to this state.
  *
  * @param mixed $groupId
  * @param \eZ\Publish\SPI\Persistence\Content\ObjectState\InputStruct $input
  *
  * @return \eZ\Publish\SPI\Persistence\Content\ObjectState
  */
 public function create($groupId, InputStruct $input)
 {
     $inputData = $this->getInputData($input);
     $newPriority = 0;
     $objectStates = $this->loadObjectStates($groupId);
     if (!empty($objectStates)) {
         $newPriority = $objectStates[count($objectStates) - 1]->priority + 1;
     }
     $inputData["groupId"] = (int) $groupId;
     $inputData["priority"] = $newPriority;
     $createdState = $this->backend->create('Content\\ObjectState', $inputData);
     if ($newPriority == 0) {
         $allContentInfos = $this->backend->find("Content\\ContentInfo");
         $allContentIds = array_map(function (ContentInfo $contentInfo) {
             return $contentInfo->id;
         }, $allContentInfos);
         $this->backend->update("Content\\ObjectState", $createdState->id, array("_contentId" => $allContentIds));
     }
     return $createdState;
 }
コード例 #7
0
 /**
  * Creates a relation between $sourceContentId in $sourceContentVersionNo
  * and $destinationContentId with a specific $type.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct $relation
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Relation
  */
 public function addRelation(RelationCreateStruct $relation)
 {
     // Ensure source content exists
     $sourceContent = $this->backend->find('Content\\ContentInfo', array("id" => $relation->sourceContentId));
     if (empty($sourceContent)) {
         throw new NotFoundException('Content\\ContentInfo', "contentId: {$relation->sourceContentId}");
     }
     // Ensure source content exists if version is specified
     if ($relation->sourceContentVersionNo !== null) {
         $version = $this->backend->find("Content\\VersionInfo", array("_contentId" => $relation->sourceContentId, "versionNo" => $relation->sourceContentVersionNo));
         if (empty($version)) {
             throw new NotFoundException("Content\\VersionInfo", "contentId: {$relation->sourceContentId}, versionNo: {$relation->sourceContentVersionNo}");
         }
     }
     // Ensure destination content exists
     $destinationContent = $this->backend->find('Content\\ContentInfo', array("id" => $relation->destinationContentId));
     if (empty($destinationContent)) {
         throw new NotFoundException('Content\\ContentInfo', "contentId: {$relation->destinationContentId}");
     }
     return $this->backend->create("Content\\Relation", (array) $relation);
 }
コード例 #8
0
 /**
  * @see eZ\Publish\SPI\Persistence\Content\Location\Handler
  */
 public function create(CreateStruct $locationStruct)
 {
     $parentId = $locationStruct->parentId;
     $parent = $this->load($parentId);
     $params = (array) $locationStruct;
     $params['parentId'] = $parentId;
     $params['depth'] = $parent->depth + 1;
     $params['hidden'] = (bool) $locationStruct->hidden;
     if (!isset($params['remoteId'])) {
         $params['remoteId'] = md5(uniqid('Content\\Location', true));
     }
     // Creation, then update for pathString/pathIdentificationString/mainLocationId
     $mainLocationId = null;
     $otherLocationsForContent = $this->backend->find('Content\\Location', array('contentId' => $locationStruct->contentId));
     if (!empty($otherLocationsForContent)) {
         $mainLocationId = $otherLocationsForContent[0]->id;
     }
     $vo = $this->backend->create('Content\\Location', $params);
     $pathString = $parent->pathString . $vo->id . '/';
     $this->backend->update('Content\\Location', $vo->id, array('pathString' => $pathString, 'pathIdentificationString' => $this->getPathIdentificationString($vo)));
     $this->backend->update('Content\\ContentInfo', $vo->contentId, array('mainLocationId' => isset($mainLocationId) ? $mainLocationId : $vo->id));
     return $this->load($vo->id);
 }
コード例 #9
0
 /**
  * Assigns role to a user or user group with given limitations
  *
  * The limitation array looks like:
  * <code>
  *  array(
  *      'Subtree' => array(
  *          '/1/2/',
  *          '/1/4/',
  *      ),
  *      'Foo' => array( 'Bar' ),
  *      …
  *  )
  * </code>
  *
  * Where the keys are the limitation identifiers, and the respective values
  * are an array of limitation values. The limitation parameter is optional.
  *
  * @param mixed $contentId The groupId or userId to assign the role to.
  * @param mixed $roleId
  * @param array $limitation
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If group or role is not found
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If group is not of user_group Content Type
  */
 public function assignRole($contentId, $roleId, array $limitation = null)
 {
     $content = $this->backend->load('Content\\ContentInfo', $contentId);
     if (!$content) {
         throw new NotFound('User Group', $contentId);
     }
     $role = $this->backend->load('User\\Role', $roleId);
     if (!$role) {
         throw new NotFound('Role', $roleId);
     }
     // @todo Use eZ Publish settings for this, and maybe a better exception
     if ($content->contentTypeId != 3 && $content->contentTypeId != 4) {
         throw new NotFound("Content", $contentId);
     }
     if (is_array($limitation)) {
         foreach ($limitation as $limitIdentifier => $limitValues) {
             $this->backend->create('User\\RoleAssignment', array('roleId' => $roleId, 'contentId' => $contentId, 'limitationIdentifier' => $limitIdentifier, 'values' => $limitValues));
         }
     } else {
         $this->backend->create('User\\RoleAssignment', array('roleId' => $roleId, 'contentId' => $contentId, 'limitationIdentifier' => null, 'values' => null));
     }
     $role->groupIds[] = $contentId;
     $this->backend->update('User\\Role', $roleId, (array) $role);
 }
コード例 #10
0
 /**
  * @see eZ\Publish\SPI\Persistence\Content\Section\Handler
  */
 public function create($name, $identifier)
 {
     return $this->backend->create('Content\\Section', array('name' => $name, 'identifier' => $identifier));
 }
コード例 #11
0
 /**
  * Creates a new url wildcard
  *
  * @param string $sourceUrl
  * @param string $destinationUrl
  * @param boolean $forward
  *
  * @return \eZ\Publish\SPI\Persistence\Content\UrlWildcard
  */
 public function create($sourceUrl, $destinationUrl, $forward = false)
 {
     return $this->backend->create('Content\\UrlWildcard', array('sourceUrl' => $sourceUrl, 'destinationUrl' => $destinationUrl, 'forward' => (bool) $forward));
 }
コード例 #12
0
 /**
  * Create a new language
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Language\CreateStruct $struct
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Language
  */
 public function create(CreateStruct $struct)
 {
     return $this->backend->create('Content\\Language', (array) $struct);
 }