/** * @param string $className * @param string $fieldName * * @return ParametrizedSqlMigrationQuery */ private function getDropEntityConfigFieldQuery($className, $fieldName) { $dropFieldIndexSql = 'DELETE FROM oro_entity_config_index_value' . ' WHERE entity_id IS NULL AND field_id IN (' . ' SELECT oecf.id FROM oro_entity_config_field AS oecf' . ' WHERE oecf.field_name = :field' . ' AND oecf.entity_id IN (' . ' SELECT oec.id' . ' FROM oro_entity_config AS oec' . ' WHERE oec.class_name = :class' . ' ))'; $dropFieldSql = 'DELETE FROM oro_entity_config_field' . ' WHERE field_name = :field' . ' AND entity_id IN (' . ' SELECT id' . ' FROM oro_entity_config' . ' WHERE class_name = :class' . ' )'; $query = new ParametrizedSqlMigrationQuery(); $query->addSql($dropFieldIndexSql, ['field' => $fieldName, 'class' => $className], ['field' => 'string', 'class' => 'string']); $query->addSql($dropFieldSql, ['field' => $fieldName, 'class' => $className], ['field' => 'string', 'class' => 'string']); return $query; }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $className = 'OroCRM\\Bundle\\MagentoBundle\\Entity\\MagentoSoapTransport'; $dropFieldsSql = 'DELETE FROM oro_entity_config_field' . ' WHERE entity_id IN (' . ' SELECT id' . ' FROM oro_entity_config' . ' WHERE class_name = :class' . ' )'; $dropFieldsQuery = new ParametrizedSqlMigrationQuery(); $dropFieldsQuery->addSql($dropFieldsSql, ['class' => $className], ['class' => 'string']); $queries->addPostQuery($dropFieldsQuery); $dropConfigurationSql = 'DELETE FROM oro_entity_config WHERE class_name = :class'; $dropConfigurationQuery = new ParametrizedSqlMigrationQuery(); $dropConfigurationQuery->addSql($dropConfigurationSql, ['class' => $className], ['class' => 'string']); $queries->addQuery($dropConfigurationQuery); }
protected function addSqls(ParametrizedSqlMigrationQuery $query) { $query->addSql('INSERT INTO test_table (name) VALUES (\'name\')'); $query->addSql('INSERT INTO test_table (name) VALUES (?1)', ['test']); $query->addSql('INSERT INTO test_table (name) VALUES (?1)', ['test'], ['string']); $query->addSql('INSERT INTO test_table (name) VALUES (:name)', ['name' => 'test']); $query->addSql('INSERT INTO test_table (name) VALUES (:name)', ['name' => 'test'], ['name' => 'string']); $query->addSql('UPDATE test_table SET values = ?1 WHERE id = ?2', [[1, 2, 3], 1], ['array', 'integer']); }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { foreach ($this->fields as $fieldName => $entityClasses) { foreach ($entityClasses as $entityClass) { $dropFieldsSql = <<<EOF DELETE FROM oro_entity_config_field WHERE field_name = :field_name AND entity_id IN (SELECT id FROM oro_entity_config WHERE class_name = :class_name) EOF; $dropFieldsQuery = new ParametrizedSqlMigrationQuery(); $dropFieldsQuery->addSql($dropFieldsSql, ['field_name' => $fieldName, 'class_name' => $entityClass], ['field_name' => Type::STRING, 'class_name' => Type::STRING]); $queries->addPostQuery($dropFieldsQuery); } } }
/** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { $table = $schema->getTable('orocrm_magento_order'); $table->addColumn('imported_at', 'datetime', ['notnull' => false, 'comment' => '(DC2Type:datetime)']); $table->addColumn('synced_at', 'datetime', ['notnull' => false, 'comment' => '(DC2Type:datetime)']); $updateDates = 'UPDATE orocrm_magento_order SET imported_at = created_at, synced_at = updated_at'; $updateDatesQuery = new ParametrizedSqlMigrationQuery(); $updateDatesQuery->addSql($updateDates); $queries->addPostQuery($updateDatesQuery); $table = $schema->getTable('orocrm_magento_customer'); $table->addColumn('imported_at', 'datetime', ['notnull' => false, 'comment' => '(DC2Type:datetime)']); $table->addColumn('synced_at', 'datetime', ['notnull' => false, 'comment' => '(DC2Type:datetime)']); $updateDates = 'UPDATE orocrm_magento_customer SET imported_at = created_at, synced_at = updated_at'; $updateDatesQuery = new ParametrizedSqlMigrationQuery(); $updateDatesQuery->addSql($updateDates); $queries->addPostQuery($updateDatesQuery); $table = $schema->getTable('orocrm_magento_cart'); $table->addColumn('imported_at', 'datetime', ['notnull' => false, 'comment' => '(DC2Type:datetime)']); $table->addColumn('synced_at', 'datetime', ['notnull' => false, 'comment' => '(DC2Type:datetime)']); $updateDates = 'UPDATE orocrm_magento_cart SET imported_at = createdat, synced_at = updatedat'; $updateDatesQuery = new ParametrizedSqlMigrationQuery(); $updateDatesQuery->addSql($updateDates); $queries->addPostQuery($updateDatesQuery); }
/** * @param string $fieldName * * @return ParametrizedSqlMigrationQuery */ protected function getDropEntityConfigManyToOneRelationQuery($fieldName) { $dropFieldIndexSql = 'DELETE FROM oro_entity_config_index_value' . ' WHERE entity_id IS NULL AND field_id IN (' . ' SELECT oecf.id FROM oro_entity_config_field AS oecf' . ' WHERE oecf.field_name = :field' . ' AND oecf.entity_id IN (' . ' SELECT oec.id' . ' FROM oro_entity_config AS oec' . ' WHERE oec.class_name = :class' . ' ))'; $dropFieldSql = 'DELETE FROM oro_entity_config_field' . ' WHERE field_name = :field' . ' AND entity_id IN (' . ' SELECT id' . ' FROM oro_entity_config' . ' WHERE class_name = :class' . ' )'; $taskClassName = $this->extendExtension->getEntityClassByTableName('orocrm_task'); $query = new ParametrizedSqlMigrationQuery(); $query->addSql($dropFieldIndexSql, ['field' => $fieldName, 'class' => $taskClassName], ['field' => 'string', 'class' => 'string']); $query->addSql($dropFieldSql, ['field' => $fieldName, 'class' => $taskClassName], ['field' => 'string', 'class' => 'string']); return $query; }