/** * 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); }
/** * 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); } }
/** * 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); }
/** * 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; }
/** * 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); }
/** * 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; }
/** * Update content objects * * Updates content objects, depending on the changed field definitions. * * A content type has a state which tells if its content objects yet have * been adapted. * * Flags the content type as updated. * * @param mixed $contentTypeId * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If type with $contentTypeId and Type::STATUS_DRAFT is not found * * @return void */ public function publish($contentTypeId) { $draftType = $this->load($contentTypeId, Type::STATUS_DRAFT); try { $publishedType = $this->load($contentTypeId); } catch (NotFound $e) { // No published version of type, jump to last section where draft is promoted to defined goto updateType; } // @todo update content based on new type data change (field/scheme changes from $publishedType to $draftType) $this->backend->deleteByMatch('Content\\Type', array('id' => $contentTypeId, 'status' => Type::STATUS_DEFINED)); $this->backend->deleteByMatch('Content\\Type\\FieldDefinition', array('_typeId' => $contentTypeId, '_status' => Type::STATUS_DEFINED)); updateType: $this->backend->updateByMatch('Content\\Type', array('id' => $contentTypeId, 'status' => Type::STATUS_DRAFT), array('status' => Type::STATUS_DEFINED)); $this->backend->updateByMatch('Content\\Type\\FieldDefinition', array('_typeId' => $contentTypeId, '_status' => Type::STATUS_DRAFT), array('_status' => Type::STATUS_DEFINED)); }
/** * 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; }
/** * 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); }
/** * Test deleting content which does not exist * * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException * @covers eZ\Publish\Core\Persistence\InMemory\Backend::delete * @group inMemoryBackend */ public function testDeleteNotFound() { $this->backend->delete("Content\\VersionInfo", 999); }
/** * @see eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler */ public function deleteTrashItem($trashedId) { $vo = $this->loadTrashItem($trashedId); $this->handler->contentHandler()->deleteContent($vo->contentId); $this->backend->delete('Content\\Location\\Trashed', $trashedId); }
/** * Number of content assignments a Section has * * @param mixed $sectionId * * @return int */ public function assignmentsCount($sectionId) { return $this->backend->count('Content\\ContentInfo', array('sectionId' => $sectionId)); }
/** * 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; }
/** * Rollback transaction * * Rollback transaction, or throw exceptions if no transactions has been started. * * @throws \RuntimeException If no transaction has been started */ public function rollback() { $this->backend->rollback(); }