Created
October 11, 2011 13:10
-
-
Save dpobel/1278028 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'extension/api/testsBootstrap.php'; | |
try | |
{ | |
$handler = new \ezp\Persistence\Storage\Legacy\Handler( array( 'dsn' => 'mysql://muser:mpasswd@localhost/mdatabase' ) ); // force the use of an eZ Publish database | |
$sc = new ezp\Base\ServiceContainer( \ezp\Base\Configuration::getInstance( 'service' )->getAll(), array( '@persistence_handler' => $handler ) ); | |
$repository = $sc->getRepository(); | |
// currently the "converters" need to be manually registered | |
$converter = $handler->getFieldValueConverterRegistry(); | |
$converter->register( 'ezstring', new \ezp\Persistence\Storage\Legacy\Content\FieldValue\Converter\TextLine() ); | |
$converter->register( 'ezxmltext', new \ezp\Persistence\Storage\Legacy\Content\FieldValue\Converter\XmlText() ); | |
$converter->register( 'ezboolean', new \ezp\Persistence\Storage\Legacy\Content\FieldValue\Converter\Checkbox() ); | |
$userService = $repository->getUserService(); | |
$repository->setUser( $userService->load( 14 ) ); | |
$contentService = $repository->getContentService(); | |
$typeService = $repository->getContentTypeService(); | |
$section = $repository->getSectionService()->load( 1 ); | |
$folder = new \ezp\Content\Concrete( $typeService->load( 1 ), new \ezp\User\Concrete( 14 ) ); | |
$folder->name = array( 'eng-GB' => 'News' ); // workaround of a known bug | |
$folder->fields['name'] = 'News'; | |
$folder->addParent( $repository->getLocationService()->load( 2 ) ); | |
$folder->setSection( $section ); // workaround of a known bug | |
$folder = $contentService->create( $folder ); | |
$contentService->publish( $folder->versions[1] ); | |
} | |
catch( Exception $e ) | |
{ | |
$cli->error( 'Exception: ' . get_class( $e ) ); | |
$cli->error( $e->getMessage() ); | |
$cli->error(); | |
$cli->error( $e->getTraceAsString() ); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment