/** * @see eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler * @todo Handle field types actions */ public function recover($trashedId, $newParentId) { $trashedLocation = $this->loadTrashItem($trashedId); $newParent = $this->handler->locationHandler()->load($newParentId); // Restore location under $newParent $struct = new CreateStruct(); foreach ($struct as $property => $value) { if (isset($trashedLocation->{$property})) { $struct->{$property} = $trashedLocation->{$property}; } } $struct->parentId = $newParent->id; return $this->handler->locationHandler()->create($struct)->id; }
/** * Returns the user policies associated with the user (including inherited policies from user groups) * * @param mixed $userId * * @return \eZ\Publish\SPI\Persistence\User\Policy[] * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If user (it's content object atm) is not found * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If user is not of user Content Type */ public function loadPoliciesByUserId($userId) { $list = $this->backend->find('Content', array('id' => $userId), 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))))); if (!$list) { throw new NotFound('User', $userId); } $policies = array(); $this->getPermissionsForObject($list[0], 4, $policies); // crawl up path on all locations $locations = $this->handler->locationHandler()->loadLocationsByContent($list[0]->versionInfo->contentInfo->id); foreach ($locations as $location) { $parentIds = array_reverse(explode('/', trim($location->pathString, '/'))); foreach ($parentIds as $parentId) { if ($parentId == $location->id) { continue; } $location = $this->backend->load('Content\\Location', $parentId); $list2 = $this->backend->find('Content', array('id' => $location->contentId), 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))))); if (isset($list2[1])) { throw new LogicException("'content tree' logic error, there is more than one item with parentId: {$parentId}"); } if ($list2) { $this->getPermissionsForObject($list2[0], 3, $policies); } } } return array_values($policies); }
/** * @see \eZ\Publish\SPI\Persistence\Content\Handler * @todo add deleting of relations */ public function deleteContent($contentId) { $this->backend->delete('Content', $contentId); $this->backend->delete('Content\\ContentInfo', $contentId); $versions = $this->backend->find('Content\\VersionInfo', array('_contentId' => $contentId)); foreach ($versions as $version) { $fields = $this->backend->find('Content\\Field', array('_contentId' => $contentId, 'versionNo' => $version->versionNo)); foreach ($fields as $field) { $this->backend->delete('Content\\Field', $field->id); } $this->backend->delete('Content\\VersionInfo', $version->id); } // @todo Deleting Locations by content object id should be possible using handler API? $locationHandler = $this->handler->locationHandler(); $locations = $this->backend->find('Content\\Location', array('contentId' => $contentId)); foreach ($locations as $location) { $locationHandler->removeSubtree($location->id); } }