Advertisement
Guest User

command

a guest
Apr 27th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. <?php
  2.  
  3. namespace EzSystems\EzSupportToolsBundle\Command;
  4.  
  5. use EzSystems\EzSupportToolsBundle\SystemInfo\SystemInfoCollectorRegistry;
  6. use EzSystems\EzSupportToolsBundle\SystemInfo\OutputFormatRegistry;
  7. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  8. use Symfony\Component\Console\Input\InputArgument;
  9. use Symfony\Component\Console\Input\InputOption;
  10. use Symfony\Component\Console\Input\InputInterface;
  11. use Symfony\Component\Console\Output\OutputInterface;
  12.  
  13. class CreateFolderCommand extends ContainerAwareCommand
  14. {
  15. /**
  16. * Define command and input options.
  17. */
  18. protected function configure()
  19. {
  20. $this->setName('content:create');
  21. }
  22.  
  23. /**
  24. * Execute the Command.
  25. *
  26. * @param $input InputInterface
  27. * @param $output OutputInterface
  28. */
  29. protected function execute(InputInterface $input, OutputInterface $output)
  30. {
  31. $repository = $this->getContainer()->get( 'ezpublish.api.repository');
  32. $userService = $repository->getUserService();
  33. $contentService = $repository->getContentService();
  34. $locationService = $repository->getLocationService();
  35. $contentTypeService = $repository->getContentTypeService();
  36.  
  37. $username = 'admin';
  38. $password = 'publish';
  39.  
  40. $contentTypeName = 'folder';
  41. $languageCode = 'eng-GB';
  42. $parentLocationId = 2;
  43.  
  44. $permissionResolver = $repository->getPermissionResolver();
  45. $user = $userService->loadUserByCredentials( $username, $password );
  46. $permissionResolver->setCurrentUserReference($user);
  47.  
  48. $contentType = $contentTypeService->loadContentTypeByIdentifier( $contentTypeName );
  49. $contentCreateStruct = $contentService->newContentCreateStruct( $contentType, $languageCode );
  50.  
  51. $contentCreateStruct->setField( 'name', 'Destination' );
  52.  
  53. $locationCreateStruct = $locationService->newLocationCreateStruct( $parentLocationId );
  54. $draft = $contentService->createContent( $contentCreateStruct, array( $locationCreateStruct ) );
  55. $content = $contentService->publishVersion( $draft->versionInfo );
  56.  
  57. return 0;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement