コード例 #1
0
 /**
  * Loads all url wild card (paged)
  *
  * @param int $offset
  * @param int $limit
  *
  * @return \eZ\Publish\SPI\Persistence\Content\UrlWildcard[]
  */
 public function loadAll($offset = 0, $limit = -1)
 {
     $list = $this->backend->find('Content\\UrlWildcard');
     if (empty($list) || $offset === 0 && $limit === -1) {
         return $list;
     }
     return array_slice($list, $offset, $limit === -1 ? null : $limit);
 }
コード例 #2
0
 /**
  * Get section data by identifier
  *
  * @param string $identifier
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If section is not found
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Section
  */
 public function loadByIdentifier($identifier)
 {
     $list = $this->backend->find('Content\\Section', array('identifier' => $identifier));
     if (empty($list)) {
         throw new NotFound('Section', $identifier);
     }
     if (isset($list[1])) {
         throw new LogicException('Several Sections with same identifier');
     }
     return $list[0];
 }
コード例 #3
0
 /**
  * Delete a language
  *
  * @throws \LogicException If language could not be deleted
  *
  * @param mixed $id
  */
 public function delete($id)
 {
     $versions = $this->backend->find('Content\\VersionInfo', array('languageIds' => $id));
     if (!empty($versions)) {
         throw new LogicException("Deleting language logic error, some content still references that language and therefore it can't be deleted");
     }
     $this->backend->delete('Content\\Language', $id);
 }
コード例 #4
0
 /**
  * Test finding content with wildcard
  *
  * @covers \eZ\Publish\Core\Persistence\InMemory\Backend::find
  * @group inMemoryBackend
  */
 public function testFindWildcard()
 {
     $list = $this->backend->find('Content\\Language', array('name' => "lang%"));
     $this->assertEquals(10, count($list));
     foreach ($list as $vo) {
         self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Language', $vo);
         self::assertTrue(strpos($vo->name, 'lang') === 0);
     }
 }
コード例 #5
0
 /**
  * Returns max found link id incremented by 1
  *
  * @return int
  */
 protected function getNextLinkId()
 {
     $list = $this->backend->find('Content\\UrlAlias');
     $id = 0;
     foreach ($list as $alias) {
         $id = max($id, $alias->id["link"]);
     }
     return $id + 1;
 }
コード例 #6
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);
 }
コード例 #7
0
 /**
  * Returns last version number for content identified by $contentId
  *
  * @param int $contentId
  *
  * @return int
  */
 private function getLastVersionNumber($contentId)
 {
     $versionNumbers = array();
     $allVersions = $this->backend->find('Content\\VersionInfo', array('_contentId' => $contentId));
     if (empty($allVersions)) {
         throw new NotFoundException("Version", "contentId: {$contentId}");
     }
     foreach ($allVersions as $version) {
         $versionNumbers[] = $version->versionNo;
     }
     return max($versionNumbers);
 }
コード例 #8
0
 /**
  * Gets a mapping array of all content and states they belong to
  *
  * This method serves as a hack because InMemory storage is unable to
  * store M:N relations between content and object states as there's no
  * value object for the link
  *
  * @return array
  */
 protected function getContentToStateMap()
 {
     $contentToStateMap = array();
     $contentInfoArray = $this->backend->find("Content\\ContentInfo");
     foreach ($contentInfoArray as $contentInfo) {
         $objectStates = $this->backend->find("Content\\ObjectState", array("_contentId" => $contentInfo->id));
         foreach ($objectStates as $objectState) {
             $contentToStateMap[$contentInfo->id][] = $objectState->id;
         }
     }
     return $contentToStateMap;
 }
コード例 #9
0
 /**
  * @see eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler
  */
 public function emptyTrash()
 {
     $trashedIds = array();
     $contentIds = array();
     foreach ($this->backend->find('Content\\Location\\Trashed') as $trashed) {
         $trashedIds[] = $trashed->id;
         $contentIds[] = $trashed->contentId;
     }
     if (!empty($trashedIds)) {
         // Remove associated content for trashed locations
         foreach ($contentIds as $contentId) {
             $this->handler->contentHandler()->deleteContent($contentId);
         }
         // Remove trashed locations
         $this->backend->deleteByMatch('Content\\Location\\Trashed', array('id' => $trashedIds));
     }
 }
コード例 #10
0
 /**
  * Finds content objects for the given query.
  *
  * @todo define structs for the field filters
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query $query
  * @param array $fieldFilters - a map of filters for the returned fields.
  *        Currently supported: <code>array("languages" => array(<language1>,..))</code>.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 public function findContent(Query $query, array $fieldFilters = array())
 {
     // Only some criteria are supported as getting full support for all in InMemory engine is not a priority
     $match = array();
     $this->generateMatchByCriteria(array($query->criterion), $match);
     if (empty($match)) {
         throw new Exception("Logical error: \$match is empty");
     }
     $list = $this->backend->find('Content', $match, array('locations' => array('type' => 'Content\\Location', 'match' => array('contentId' => 'id'), 'skip' => true), '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))), 'objectStates' => array('type' => 'Content\\ObjectState', 'match' => array('_contentId' => 'id'), 'skip' => true)));
     $resultList = array();
     foreach ($list as $item) {
         if (!$item instanceof Content) {
             throw new \RuntimeException("item is not instance of Content, it is " . var_export($item, true));
         } else {
             if (!$item->versionInfo instanceof VersionInfo) {
                 throw new \RuntimeException("item->versionInfo is not instance of VersionInfo, it is " . var_export($item, true));
             } else {
                 if (!$item->versionInfo->contentInfo instanceof ContentInfo) {
                     throw new \RuntimeException("item->versionInfo->contentInfo is not instance of ContentInfo, it is " . var_export($item, true));
                 } else {
                     $item->fields = $this->backend->find('Content\\Field', array('_contentId' => $item->versionInfo->contentInfo->id, 'versionNo' => $item->versionInfo->contentInfo->currentVersionNo));
                     $resultList[] = $item;
                 }
             }
         }
     }
     $result = new SearchResult();
     $result->time = 0;
     $result->totalCount = count($resultList);
     if (empty($resultList) || $query->limit === null && $query->offset === 0) {
         $result->searchHits = $resultList;
     } else {
         if ($query->limit === null) {
             $result->searchHits = array_slice($resultList, $query->offset);
         } else {
             $result->searchHits = array_slice($resultList, $query->offset, $query->limit);
         }
     }
     $result->searchHits = array_map(function ($content) {
         return new SearchHit(array('valueObject' => $content));
     }, $result->searchHits);
     return $result;
 }
コード例 #11
0
 /**
  * Un-assign a role
  *
  * @param mixed $contentId The user or user group Id to un-assign the role from.
  * @param mixed $roleId
  *
  * @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
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue If group does not contain role
  */
 public function unAssignRole($contentId, $roleId)
 {
     $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("3 or 4", $contentId);
     }
     $roleAssignments = $this->backend->find('User\\RoleAssignment', array('roleId' => $roleId, 'contentId' => $contentId));
     if (empty($roleAssignments)) {
         throw new InvalidArgumentValue('$roleId', $roleId);
     }
     $this->backend->deleteByMatch('User\\RoleAssignment', array('roleId' => $roleId, 'contentId' => $contentId));
     $role->groupIds = array_values(array_diff($role->groupIds, array($contentId)));
     $this->backend->update('User\\Role', $roleId, (array) $role);
 }
コード例 #12
0
 /**
  * Returns stripped content name from location value
  * All downcase, special chars to underscores
  * e.g. my_content_name
  * @param LocationValue $vo
  *
  * @return string
  */
 private function getStrippedContentName(LocationValue $vo)
 {
     $version = $this->backend->find("Content\\VersionInfo", array("contentId" => $vo->contentId, "versionNo" => $this->backend->load('Content\\ContentInfo', $vo->contentId)->currentVersionNo));
     return isset($version[0]->names["eng-GB"]) ? preg_replace('`[^a-z0-9_]`i', '_', strtolower(trim(strtr($version[0]->names["eng-GB"], self::CHARS_ACCENT, self::CHARS_NOACCENT)))) : null;
 }
コード例 #13
0
 /**
  * Test finding content with a wrong type.
  *
  * @param mixed $type Wrong type to find
  *
  * @expectedException eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue
  * @dataProvider providerForWrongType
  * @covers eZ\Publish\Core\Persistence\InMemory\Backend::find
  */
 public function testFindWrongType($type)
 {
     $this->backend->find($type, array());
 }