Commit 35887cc3 authored by Fathima Nazeeha Asmat's avatar Fathima Nazeeha Asmat Committed by neffets
Browse files

Issue #3312090 by fathima.asmat, neffets: Update_N hook fail for field type...

Issue #3312090 by fathima.asmat, neffets: Update_N hook fail for field type change for fields with existing data/new columns
parent b9ea596a
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -162,6 +162,26 @@ class FieldTypeUpdateUtil {
        $database = \Drupal::database();
        $existing_data = [];
        foreach ($tables as $table) {
          // Create any new fields from the field schema
          // if they don't exist in the database table.
          $field_schema = $field_storage_definition->getSchema();
          $columns = $table_mapping->getColumnNames($field_name);
          if (!empty($field_schema['columns'])) {
            foreach ($field_schema['columns'] as $column_name => $column_data) {
              $table_exists = $schema->tableExists($table);
              if ($table_exists) {
                $field_exists = $schema->fieldExists($table, $columns[$column_name]);
                if ($field_exists === FALSE) {
                  $schema->addField($table, $columns[$column_name], $column_data);
                }
              }
            }

            // Caches have to be cleared first to ensure
            // new fields are detected in the code.
            drupal_flush_all_caches();
          }

          // Get the old data.
          $existing_data[$table] = $database->select($table)
            ->fields($table)