You are here

function webform_update_8001 in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.install.update.inc \webform_update_8001()

Issue #2834203: Convert webform field target_id to 32 characters.

File

includes/webform.install.update.inc, line 62
Archived Webform update hooks.

Code

function webform_update_8001() {
  $database_schema = \Drupal::database()
    ->schema();
  $schema = \Drupal::keyValue('entity.storage_schema.sql')
    ->getAll();
  foreach ($schema as $item_name => $item) {
    foreach ($item as $table_name => $table_schema) {
      foreach ($table_schema as $schema_key => $schema_data) {
        if ($schema_key === 'fields') {
          foreach ($schema_data as $field_name => $field_data) {
            if (preg_match('/_target_id$/', $field_name) && $field_data['description'] === 'The ID of the webform entity.' && $schema[$item_name][$table_name]['fields'][$field_name]['length'] === 255) {
              $schema[$item_name][$table_name]['fields'][$field_name]['length'] = 32;
              if ($database_schema
                ->tableExists($table_name)) {
                $database_schema
                  ->changeField($table_name, $field_name, $field_name, $schema[$item_name][$table_name]['fields'][$field_name]);
              }
            }
          }
        }
      }
    }
  }
  \Drupal::keyValue('entity.storage_schema.sql')
    ->setMultiple($schema);
}