...
Code Block | ||||
---|---|---|---|---|
| ||||
<?php /** * File containing the CookBookCommand class. * * @copyright Copyright (C) 2012 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version //autogentag// */ namespace eZ\Publish\Bundles\CookBookBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; class CookBookCommand extends ContainerAwareCommand { /** * This method override configures on input argument for the content id */ protected function configure() { $this->setName( 'cookbook:run' )->setDefinition( array( new InputArgument( 'contentId', InputArgument::REQUIRED, 'An existing content id' ) ) ); } /** * execute the command * @param InputInterface $input * @param OutputInterface $output */ protected function execute( InputInterface $input, OutputInterface $output ) { // fetch the input argument $contentId = $input->getArgument( 'contentId' ); // get the repository from the di container $repository = $this->getContainer()->get( 'ezpublish.api.repository' ); // get the content service from the repsitory $contentService = $repository->getContentService(); try { // print out the content info for the gicengiven content id print_r( $contentService->loadContentInfo( $contentId ) ); } catch( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e ) { // if the id is not found $output->writeln( "No content with id $contentId" ); } catch( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e ) { // not allowed to read this content $output->writeln( "Anonymous users are not allowed to read content with id $contentId" ); } } } |
...
This snippet creates a content type group for a given identifier.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$contentTypeService = $repository->getContentTypeService(); try { // instanciate a create struct $groupCreate = $this->contentTypeService->newContentTypeGroupCreateStruct($groupIdentifier); // call service method $contentTypeGroup = $this->contentTypeService->createContentTypeGroup( $groupCreate ); // print out the group print_r($contentTypeGroup); } catch( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e ) { // react on permission denied $output->writeln($e->getMessage()); } catch( \eZ\Publish\API\Repository\Exceptions\ForbiddenException $e ) { // react on identifier already exists $output->writeln($e->getMessage()); } |
...
If the user is identified by other mechanisms the user also can be loaded by its id .via the service method
$userService->loadUser($id)