diff --git a/core/includes/update.inc b/core/includes/update.inc index 2719634..8bcf18b 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -1480,6 +1480,33 @@ function update_config_manifest_add($config_prefix, array $ids) { } /** + * Removes configuration entities and the entry in the manifest file during + * updates. + * + * @param string $config_prefix + * The configuration entity prefix from the annotation. + * @param array $ids + * An array of configuration entities to add to the manifest. + */ +function update_config_remove_config($config_prefix, array $ids) { + $manifest = config('manifest.' . $config_prefix); + + // Add record to manifest for each config entity. Operate on the data array + // as a whole, because $manifest->get() would treat dots in ids as nesting. + $data = $manifest->get(); + foreach ($ids as $id) { + if (isset($data[$id])) { + config($config_prefix . $id)->delete(); + unset($data[$id]); + } + } + $manifest->setData($data); + + // Write manifest to disk. + $manifest->save(); +} + +/** * Updates 7.x variables to state records. * * Provides a generalized method to migrate variables from 7.x to 8.x's diff --git a/core/modules/field/field.install b/core/modules/field/field.install index 41ad9f3..e9cb949 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -71,18 +71,20 @@ function _update_7000_field_delete_field($field_name) { throw new Exception($t('This function can only be used to delete fields without data')); } // Delete all instances. - db_delete('field_config_instance') - ->condition('field_name', $field_name) - ->execute(); + $config_names = config_get_storage_names_with_prefix('field.instance'); + foreach ($config_names as $id) { + list($p1, $p2, $entity_type, $bundle, $field_name) = explode('.', $id); + if ($field_name == $field_name) { + update_config_remove_config('field.instance', $entity_type . '.' . $bundle . '.' . $field_name); + } + } // Nuke field data and revision tables. db_drop_table($table_name); db_drop_table('field_revision_' . $field_name); // Delete the field. - db_delete('field_config') - ->condition('field_name', $field_name) - ->execute(); + update_config_remove_config('field.field', $field_name); } /** @@ -94,11 +96,7 @@ function _update_7000_field_delete_field($field_name) { */ function _update_7000_field_delete_instance($field_name, $entity_type, $bundle) { // Delete field instance configuration data. - db_delete('field_config_instance') - ->condition('field_name', $field_name) - ->condition('entity_type', $entity_type) - ->condition('bundle', $bundle) - ->execute(); + update_config_remove_config('field.instance', $entity_type . '.' . $bundle . '.' . $field_name); // Nuke data. db_delete('field_data_' . $field_name) @@ -131,30 +129,34 @@ function _update_7000_field_delete_instance($field_name, $entity_type, $bundle) * @ingroup update_api */ function _update_7000_field_read_fields(array $conditions = array(), $key = 'id') { - $fields = array(); - $query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC)) - ->fields('fc'); - foreach ($conditions as $column => $value) { - $query->condition($column, $value); + $matching_fields = array(); + + $config_names = config_get_storage_names_with_prefix('field.field'); + $deleted_fields = Drupal::state()->get('field.field.deleted') ?: array(); + // Ditch UUID keys, we will iterate through deleted fields using a numeric + // index. + $deleted_fields = array_values($deleted_fields); + + if (empty($config_names) && empty($deleted_fields)) { + return $matching_fields; } - foreach ($query->execute() as $record) { - $field = unserialize($record['data']); - $field['id'] = $record['id']; - $field['field_name'] = $record['field_name']; - $field['type'] = $record['type']; - $field['module'] = $record['module']; - $field['active'] = $record['active']; - $field['storage']['type'] = $record['storage_type']; - $field['storage']['module'] = $record['storage_module']; - $field['storage']['active'] = $record['storage_active']; - $field['locked'] = $record['locked']; - $field['cardinality'] = $record['cardinality']; - $field['translatable'] = $record['translatable']; - $field['deleted'] = $record['deleted']; - - $fields[$field[$key]] = $field; + + // Collect matching fields. + foreach ($config_names as $id) { + $field = config($id)->get(); + + if (!empty($conditions)) { + foreach ($conditions as $key => $value) { + if ($field[$key] != $value) { + continue 2; + } + } + } + + $matching_fields[$field[$key]] = $field; } - return $fields; + + return $matching_fields; } /** @@ -189,6 +191,18 @@ function _update_7000_field_create_instance($field, &$instance) { } /** + * Implements hook_update_dependencies(). + */ +function field_update_dependencies() { + // Convert Field API to ConfigEntities: + $dependencies['field'][8003] = array( + // - After the {file_usage}.id column has moved to varchar. + 'file' => 8001, + ); + return $dependencies; +} + +/** * @addtogroup updates-7.x-to-8.x * @{ */ diff --git a/core/modules/field_sql_storage/field_sql_storage.install b/core/modules/field_sql_storage/field_sql_storage.install index f8dd684..03390a6 100644 --- a/core/modules/field_sql_storage/field_sql_storage.install +++ b/core/modules/field_sql_storage/field_sql_storage.install @@ -62,6 +62,18 @@ function _update_8000_field_sql_storage_write($entity_type, $bundle, $entity_id, } /** + * Implements hook_update_dependencies(). + */ +function field_sql_storage_update_dependencies() { + // Convert storage tables after field definitions have moved to + // ConfigEntities. + $dependencies['field_sql_storage'][8000] = array( + 'field' => 8003, + ); + return $dependencies; +} + +/** * Renames the 'language' column to 'langcode' in field data tables. */ function field_sql_storage_update_8000(&$sandbox) { diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 2bc4b19..9815191 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -376,10 +376,10 @@ function user_install_picture_field() { * Implements hook_update_dependencies(). */ function user_update_dependencies() { - // Convert user picture to field after the {file_usage}.id column - // has moved to varchar. + // Convert user picture to field after the fields and instances + // are converted to ConfigEntities. $dependencies['user'][8011] = array( - 'file' => 8001, + 'field' => 8003, ); return $dependencies; } @@ -784,8 +784,11 @@ function user_update_8011() { 'image_link' => 'content', ), 'weight' => 0, - )) - ->save(); + )); + $display->set('content.member_for', array( + 'visible' => FALSE, + )); + $display->save(); update_config_manifest_add('entity.display', array($display->get('id'))); // Add file usage for the default field. @@ -801,14 +804,6 @@ function user_update_8011() { ->execute(); } - // Update the user bundle settings and hide the member_for extra field. - $settings = update_variable_get('field_bundle_settings_user__user'); - $settings['extra_fields']['display']['member_for']['compact'] = array( - 'weight' => 0, - 'visible' => FALSE, - ); - update_variable_set('field_bundle_settings_user__user', $settings); - // Delete old variables. update_variable_del('user_pictures'); update_variable_del('user_picture_path');