Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function build(ClassMetadataBuilder $metadataBuilder, ConfigInterface $extendConfig)
 {
     $className = $extendConfig->getId()->getClassName();
     $indices = $extendConfig->get('index');
     // TODO: need to be changed to fieldName => columnName
     // TODO: should be done in scope https://magecore.atlassian.net/browse/BAP-3940
     foreach ($indices as $columnName => $enabled) {
         $fieldConfig = $this->extendConfigProvider->getConfig($className, $columnName);
         if ($enabled && !$fieldConfig->is('state', ExtendScope::STATE_NEW)) {
             $indexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $columnName);
             $metadataBuilder->addIndex([$columnName], $indexName);
         }
     }
 }
 /**
  * @param Schema   $schema
  * @param QueryBag $queries
  * @param string   $tableName
  * @param string   $columnName
  * @param array    $options
  */
 protected function processColumn(Schema $schema, QueryBag $queries, $tableName, $columnName, $options)
 {
     $className = $this->entityMetadataHelper->getEntityClassByTableName($tableName);
     $table = $schema->getTable($tableName);
     if (!isset($options[ExtendOptionsManager::NEW_NAME_OPTION])) {
         if (isset($options[ExtendOptionsManager::TYPE_OPTION])) {
             $columnType = $options[ExtendOptionsManager::TYPE_OPTION];
             if (!in_array($columnType, ['oneToMane', 'manyToMany', 'manyToOne', 'optionSet'])) {
                 $indexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $columnName);
                 $enabled = !isset($options['datagrid']['is_visible']) || $options['datagrid']['is_visible'];
                 if ($enabled && !$table->hasIndex($indexName)) {
                     $table->addIndex([$columnName], $indexName);
                 } elseif (!$enabled && $table->hasIndex($indexName)) {
                     $table->dropIndex($indexName);
                 }
             }
         }
     } else {
         // in case of renaming column name we should rename existing index
         $newColumnName = $options[ExtendOptionsManager::NEW_NAME_OPTION];
         $indexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $columnName);
         if ($table->hasIndex($indexName)) {
             $table->dropIndex($indexName);
             $newIndexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $newColumnName);
             $this->renameExtension->addIndex($schema, $queries, $tableName, [$newColumnName], $newIndexName);
         }
     }
 }
 /**
  * @param Schema $schema
  * @param QueryBag $queries
  * @param string $tableName
  * @param string $columnName
  * @param array $options
  * @param string $className
  * @param Table $table
  */
 protected function renameIndex(Schema $schema, QueryBag $queries, $tableName, $columnName, $options, $className, $table)
 {
     $newColumnName = $options[ExtendOptionsManager::NEW_NAME_OPTION];
     $indexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $columnName);
     if ($table->hasIndex($indexName)) {
         $table->dropIndex($indexName);
         $newIndexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $newColumnName);
         $this->renameExtension->addIndex($schema, $queries, $tableName, [$newColumnName], $newIndexName);
     }
 }