...
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\Bundle\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 { protected function configure() { // define a new app console command 'cookbook:run' which takes one argument mapped to contentId $this->setName( 'cookbook:run' ) ->setDefinition( array( new InputArgument( 'contentId', InputArgument::REQUIRED, 'An existing content id' ) ) ); } protected function execute( InputInterface $input, OutputInterface $output ) { // fetch the command line argument $contentId = $input->getArgument( 'contentId' ); // get the repository from DI container $repository = $this->getContainer()->get( 'ezpublish.api.repository' ); /*********** receipt code starts here ********************************/ // get the content service from the repository $contentService = $repository->getContentService(); try { // call loadContentInfo and print out print_r( $contentService->loadContentInfo( $contentId ) ); } catch( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e ) { $output->writeln( "No content with id $contentId" ); } /*********** receipt code ends here ********************************/ } } |
run f.e.
php app/console cookbook:run 57
Receipt 2 - Creating a content type
...
and
...
content
...
language | php |
---|
...
In this receipt we create a content type group and a simple content type in it and then we create a content object of that type.
Code Block | ||
---|---|---|
| ||
/*********** receipt code starts here ********************************/
/*********** receipt code ends here ********************************/ |
Receipt 3 Update content type
...