Пример #1
0
 /**
  * @dataProvider setColumnOptionsProvider
  */
 public function testSetColumnOptions($tableName, $columnName, array $options, array $prevValues, array $expected)
 {
     if (!empty($prevValues)) {
         $this->setProtectedProperty($this->manager, 'options', $prevValues);
     }
     $this->manager->setColumnOptions($tableName, $columnName, $options);
     $this->assertEquals($expected, $this->manager->getExtendOptions());
 }
Пример #2
0
 /**
  * @param string $name
  * @param mixed  $value Can be scalar type, array or OroOptions object
  *
  * @return \Doctrine\DBAL\Schema\Table
  */
 public function addOption($name, $value)
 {
     if ($name === OroOptions::KEY) {
         if ($value instanceof OroOptions) {
             $value = $value->toArray();
         }
         $this->extendOptionsManager->setTableOptions($this->getName(), $value);
         return $this;
     }
     return parent::addOption($name, $value);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function setOptions(array $options)
 {
     if (isset($options[OroOptions::KEY])) {
         $oroOptions = $options[OroOptions::KEY];
         if ($oroOptions instanceof OroOptions) {
             $oroOptions = $oroOptions->toArray();
         }
         $this->extendOptionsManager->setColumnOptions($this->tableName, $this->getName(), $oroOptions);
         unset($options[OroOptions::KEY]);
     }
     if (!empty($options)) {
         parent::setOptions($options);
     }
     return $this;
 }
Пример #4
0
 /**
  * Adds many-to-one relation
  *
  * @param Schema       $schema
  * @param Table|string $table            A Table object or table name
  * @param string       $associationName  A relation name
  * @param Table|string $targetTable      A Table object or table name
  * @param string       $targetColumnName A column name is used to show related entity
  * @param array        $options
  * @param string       $fieldType        The field type. By default the field type is manyToOne,
  *                                       but you can specify another type if it is based on manyToOne.
  *                                       In this case this type should be registered
  *                                       in entity_extend.yml under underlying_types section
  */
 public function addManyToOneRelation(Schema $schema, $table, $associationName, $targetTable, $targetColumnName, array $options = [], $fieldType = RelationType::MANY_TO_ONE)
 {
     $this->ensureExtendFieldSet($options);
     $selfTableName = $this->getTableName($table);
     $selfTable = $this->getTable($table, $schema);
     $selfColumnName = $this->nameGenerator->generateManyToOneRelationColumnName($associationName);
     $targetTableName = $this->getTableName($targetTable);
     $targetTable = $this->getTable($targetTable, $schema);
     $targetPrimaryKeyColumnName = $this->getPrimaryKeyColumnName($targetTable);
     $targetPrimaryKeyColumn = $targetTable->getColumn($targetPrimaryKeyColumnName);
     $this->checkColumnsExist($targetTable, [$targetColumnName]);
     $this->addRelationColumn($selfTable, $selfColumnName, $targetPrimaryKeyColumn, ['notnull' => false]);
     $selfTable->addIndex([$selfColumnName]);
     $selfTable->addForeignKeyConstraint($targetTable, [$selfColumnName], [$targetPrimaryKeyColumnName], ['onDelete' => 'SET NULL']);
     $options[ExtendOptionsManager::TARGET_OPTION] = ['table_name' => $targetTableName, 'column' => $targetColumnName];
     $options[ExtendOptionsManager::TYPE_OPTION] = $fieldType;
     $this->extendOptionsManager->setColumnOptions($selfTableName, $associationName, $options);
 }
Пример #5
0
 /**
  * Adds the inverse side of a many-to-one relation
  *
  * @param Schema       $schema
  * @param Table|string $table                     A Table object or table name
  * @param string       $associationName           The name of a relation field
  * @param Table|string $targetTable               A Table object or table name
  * @param string       $targetAssociationName     The name of a relation field on the inverse side
  * @param string[]     $targetTitleColumnNames    Column names are used to show a title of related entity
  * @param string[]     $targetDetailedColumnNames Column names are used to show detailed info about related entity
  * @param string[]     $targetGridColumnNames     Column names are used to show related entity in a grid
  * @param array        $options                   Entity config values
  *                                                format is [CONFIG_SCOPE => [CONFIG_KEY => CONFIG_VALUE]]
  */
 public function addManyToOneInverseRelation(Schema $schema, $table, $associationName, $targetTable, $targetAssociationName, array $targetTitleColumnNames, array $targetDetailedColumnNames, array $targetGridColumnNames, array $options = [])
 {
     $this->ensureExtendFieldSet($options);
     $selfTableName = $this->getTableName($table);
     $selfClassName = $this->getEntityClassByTableName($selfTableName);
     $targetTableName = $this->getTableName($targetTable);
     $targetTable = $this->getTable($targetTable, $schema);
     $targetClassName = $this->getEntityClassByTableName($targetTableName);
     $this->checkColumnsExist($targetTable, $targetTitleColumnNames);
     $this->checkColumnsExist($targetTable, $targetDetailedColumnNames);
     $this->checkColumnsExist($targetTable, $targetGridColumnNames);
     $relationKey = ExtendHelper::buildRelationKey($selfClassName, $associationName, RelationType::MANY_TO_ONE, $targetClassName);
     $targetFieldId = new FieldConfigId('extend', $targetClassName, $targetAssociationName, RelationType::ONE_TO_MANY);
     $selfTableOptions['extend']['relation.' . $relationKey . '.target_field_id'] = $targetFieldId;
     $this->extendOptionsManager->setTableOptions($selfTableName, $selfTableOptions);
     $targetTableOptions['extend']['relation.' . $relationKey . '.field_id'] = $targetFieldId;
     $this->extendOptionsManager->setTableOptions($targetTableName, $targetTableOptions);
     $options[ExtendOptionsManager::TARGET_OPTION] = ['table_name' => $selfTableName, 'relation_key' => $relationKey, 'columns' => ['title' => $targetTitleColumnNames, 'detailed' => $targetDetailedColumnNames, 'grid' => $targetGridColumnNames]];
     $options[ExtendOptionsManager::TYPE_OPTION] = RelationType::ONE_TO_MANY;
     $this->extendOptionsManager->setColumnOptions($targetTableName, $targetAssociationName, $options);
 }
Пример #6
0
 /**
  * @return array
  */
 public function getExtendOptions()
 {
     return $this->extendOptionsManager->getExtendOptions();
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function renameColumn(Schema $schema, QueryBag $queries, Table $table, $oldColumnName, $newColumnName)
 {
     $this->extendOptionsManager->setColumnOptions($table->getName(), $oldColumnName, [ExtendOptionsManager::NEW_NAME_OPTION => $newColumnName]);
     parent::renameColumn($schema, $queries, $table, $oldColumnName, $newColumnName);
 }