Created
October 13, 2011 10:21
-
-
Save dpobel/1283914 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' ) ); | |
$sc = new ezp\Base\ServiceContainer( \ezp\Base\Configuration::getInstance( 'service' )->getAll(), array( '@persistence_handler' => $handler ) ); | |
$repository = $sc->getRepository(); | |
$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() ); | |
$converter->register( 'ezinteger', new \ezp\Persistence\Storage\Legacy\Content\FieldValue\Converter\Integer() ); | |
$userService = $repository->getUserService(); | |
$repository->setUser( $userService->load( 14 ) ); | |
$contentService = $repository->getContentService(); | |
$typeService = $repository->getContentTypeService(); | |
$section = $repository->getSectionService()->load( 1 ); | |
$contentType = new \ezp\Content\Type\Concrete(); | |
$contentType->identifier = 'a_date_class'; | |
$contentType->name = array( 'eng-GB' => 'A Date Class' ); | |
$contentType->description = array( 'eng-GB' => 'This is a date class test' ); | |
$contentType->nameSchema = '<name>'; | |
$contentType->urlAliasSchema = ''; | |
$contentType->isContainer = false; | |
$contentType->initialLanguageId = 2; | |
$contentType->creatorId = $contentType->modifierId = 14; | |
$contentType->sortField = \ezp\Content\Location::SORT_FIELD_PATH; | |
$contentType->sortOrder = \ezp\Content\Location::SORT_ORDER_ASC; | |
$fields = array( | |
'name' => array( 'fieldType' => 'ezstring', | |
'name' => array( 'eng-GB' => 'Name' ), | |
'description' => array( 'eng-GB' => 'This is a test' ), | |
'position' => 0, | |
'fieldGroup' => '', | |
'isRequired' => false, | |
'isSearchable' => true, | |
'isInfoCollector' => false, | |
'isTranslatable' => true, | |
'fieldSettings' => array(), | |
'validator' => array() ), | |
'date' => array( 'fieldType' => 'ezdatetime', | |
'name' => array( 'eng-GB' => 'Date' ), | |
'description' => array( 'eng-GB' => 'This is a Date test' ), | |
'position' => 1, | |
'fieldGroup' => 'meta', | |
'isRequired' => true, | |
'isSearchable' => true, | |
'isInfoCollector' => false, | |
'isTranslatable' => true, | |
'fieldSettings' => array()//array( 'defaultType' => \ezp\Content\FieldType\DateAndTime\Type::DEFAULT_CURRENT_DATE ) | |
) | |
); | |
$addFields = array(); | |
foreach ( $fields as $identifier => $data ) | |
{ | |
$field = new \ezp\Content\Type\FieldDefinition( $contentType, $data['fieldType'] ); | |
$field->identifier = $identifier; | |
$field->name = $data['name']; | |
$field->description = $data['description']; | |
$field->position = $data['position']; | |
$field->fieldGroup = $data['fieldGroup']; | |
$field->isRequired = $data['isRequired']; | |
$field->isSearchable = $data['isSearchable']; | |
$field->isInfoCollector = $data['isInfoCollector']; | |
$field->isTranslatable = $data['isTranslatable']; | |
if ( isset( $data['defaultValue'] ) ) | |
$field->setDefaultValue( $data['defaultValue'] ); | |
foreach ( $data['fieldSettings'] as $fieldSetting => $value ) | |
{ | |
$field->setFieldSetting( $fieldSetting, $value ); | |
} | |
if ( isset( $data['validators'] ) ) | |
{ | |
foreach ( $data['validators'] as $validatorName => $constraints ) | |
{ | |
$validator = new $validatorName; | |
$validator->initializeWithConstraints( $constraints ); | |
$field->addValidator( $validator ); | |
} | |
} | |
$addFields[] = $field; | |
} | |
$linkGroups = array( $typeService->loadGroup( 1 ) ); | |
$contentType = $typeService->createAndPublish( $contentType, $linkGroups, $addFields ); | |
} | |
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