diff --git a/core/modules/block/block.install b/core/modules/block/block.install index 01c5779..1b9396b 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -246,23 +246,23 @@ function block_update_8008() { // First, create the body field. $body_field = array( - 'field_name' => 'block_body', + 'id' => 'block_body', 'type' => 'text_with_summary', 'entity_types' => array('custom_block'), 'module' => 'text', 'cardinality' => 1, ); - _update_7000_field_create_field($body_field); + _update_8000_field_create_field($body_field); $instance = array( - 'field_name' => 'block_body', + 'id' => 'custom_block.basic.block_body', 'entity_type' => 'custom_block', 'bundle' => 'basic', 'label' => 'Block body', 'widget' => array('type' => 'text_textarea_with_summary'), 'settings' => array('display_summary' => FALSE), ); - _update_7000_field_create_instance($body_field, $instance); + _update_8000_field_create_instance($body_field, $instance); // Initialize state for future calls. $sandbox['last'] = 0; @@ -302,7 +302,7 @@ function block_update_8008() { ); // This is a core update and no contrib modules are enabled yet, so // we can assume default field storage for a faster update. - _update_7000_field_sql_storage_write('custom_block', 'basic', $block->bid, $block->bid, 'block_body', $data); + _update_8000_field_sql_storage_write('custom_block', 'basic', $block->bid, $block->bid, 'block_body', $data); $sandbox['last'] = $block->bid; $sandbox['count'] += 1; diff --git a/core/modules/field/field.install b/core/modules/field/field.install index dcf2b38..0fa04fa 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -9,241 +9,103 @@ use Drupal\field\Plugin\Core\Entity\Field; /** - * Creates a field by writing directly to the database. + * Creates a field by writing directly to configuration. + * + * @param array $field_config + * An array of field properties. * * @ingroup update_api */ -function _update_7000_field_create_field(&$field) { - // Merge in default values.` - $field += array( +function _update_8000_field_create_field(array &$field_config) { + $uuid = new Uuid(); + + // Merge in default values. + $field_config += array( + 'uuid' => $uuid->generate(), 'entity_types' => array(), 'cardinality' => 1, 'translatable' => FALSE, 'locked' => FALSE, 'settings' => array(), 'indexes' => array(), - 'deleted' => FALSE, 'active' => TRUE, + 'status' => 1, + 'langcode' => 'und', ); - // Set storage. - $field['storage'] = array( + // Set the storage. + $field_config['storage'] = array( 'type' => 'field_sql_storage', - 'settings' => array(), 'module' => 'field_sql_storage', 'active' => TRUE, + 'settings' => array(), ); - // Fetch the field schema to initialize columns and indexes. The field module - // is not guaranteed to be loaded at this point. - module_load_install($field['module']); - $schema = (array) module_invoke($field['module'], 'field_schema', $field); - $schema += array('columns' => array(), 'indexes' => array()); - // 'columns' are hardcoded in the field type. - $field['columns'] = $schema['columns']; - // 'indexes' can be both hardcoded in the field type, and specified in the - // incoming $field definition. - $field['indexes'] += $schema['indexes']; - - // The serialized 'data' column contains everything from $field that does not - // have its own column and is not automatically populated when the field is - // read. - $data = $field; - unset($data['columns'], $data['field_name'], $data['type'], $data['active'], $data['module'], $data['storage_type'], $data['storage_active'], $data['storage_module'], $data['locked'], $data['cardinality'], $data['deleted']); - // Additionally, do not save the 'bundles' property populated by - // field_info_field(). - unset($data['bundles']); - - // Write the field to the database. - $record = array( - 'field_name' => $field['field_name'], - 'type' => $field['type'], - 'module' => $field['module'], - 'active' => (int) $field['active'], - 'storage_type' => $field['storage']['type'], - 'storage_module' => $field['storage']['module'], - 'storage_active' => (int) $field['storage']['active'], - 'locked' => (int) $field['locked'], - 'data' => serialize($data), - 'cardinality' => $field['cardinality'], - 'translatable' => (int) $field['translatable'], - 'deleted' => (int) $field['deleted'], - ); - // We don't use drupal_write_record() here because it depends on the schema. - $field_id = db_insert('field_config') - ->fields($record) - ->execute(); + // Save in config. + Drupal::config('field.field.' . $field_config['id']) + ->setData($field_config) + ->save(); + update_config_manifest_add('field.field', array($field_config['id'])); // Create storage for the field. This requires a field entity, but cannot use // the regular entity_create() function here. - $field_entity = new Field($field); + $field_entity = new Field($field_config); field_sql_storage_field_storage_create_field($field_entity); - - $field['id'] = $field_id; } /** - * Deletes a field stored in SQL storage directly from the database. - * - * To protect user data, this function can only be used to delete fields once - * all information it stored is gone. Delete all data from the - * field_data_$field_name table before calling by either manually issuing - * delete queries against it or using _update_7000_field_delete_instance(). + * Writes a field instance directly to configuration. * - * @param $field_name - * The field name to delete. + * @param array $field_config + * An array of field properties. + * @param array $instance + * An array of field instance properties. * * @ingroup update_api */ -function _update_7000_field_delete_field($field_name) { - $table_name = 'field_data_' . $field_name; - if (db_select($table_name)->range(0, 1)->countQuery()->execute()->fetchField()) { - $t = get_t(); - 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(); - - // 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(); -} - -/** - * Deletes an instance and all its data of a field stored in SQL Storage. - * - * BEWARE: This function deletes user data from the field storage tables. - * - * @ingroup update_api - */ -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(); - - // Nuke data. - db_delete('field_data_' . $field_name) - ->condition('entity_type', $entity_type) - ->condition('bundle', $bundle) - ->execute(); - db_delete('field_revision_' . $field_name) - ->condition('entity_type', $entity_type) - ->condition('bundle', $bundle) - ->execute(); -} - -/** - * Fetches all of the field definitions from the database. - * - * Warning: Unlike the field_read_fields() API function, this function returns - * all fields by default, including deleted and inactive fields, unless - * specified otherwise in the $conditions parameter. - * - * @param $conditions - * An array of conditions to limit the select query to. - * @param $key - * The name of the field property the return array is indexed by. Using - * anything else than 'id' might cause incomplete results if the $conditions - * do not filter out deleted fields. - * - * @return - * An array of fields matching $conditions, keyed by the property specified - * by the $key parameter. - * @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); - } - 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; - } - return $fields; -} +function _update_8000_field_create_instance(array $field_config, array &$instance_config) { + $uuid = new Uuid(); -/** - * Writes a field instance directly to the database. - * - * @ingroup update_api - */ -function _update_7000_field_create_instance($field, &$instance) { // Merge in defaults. - $instance += array( - 'field_id' => $field['id'], - 'field_name' => $field['field_name'], - 'deleted' => FALSE, + $instance_config += array( 'description' => '', 'required' => FALSE, + 'uuid' => $uuid->generate(), + 'field_uuid' => $field_config['uuid'], + 'field_type' => $field_config['type'], + 'default_value' => array(), + 'default_value_function' => '', + 'settings' => array(), + 'widget' => array(), + 'status' => 1, + 'langcode' => 'und', ); - // The serialized 'data' column contains everything from $instance that does - // not have its own column and is not automatically populated when the - // instance is read. - $data = $instance; - unset($data['id'], $data['field_id'], $data['field_name'], $data['entity_type'], $data['bundle'], $data['deleted']); - - $record = array( - 'field_id' => $instance['field_id'], - 'field_name' => $instance['field_name'], - 'entity_type' => $instance['entity_type'], - 'bundle' => $instance['bundle'], - 'data' => serialize($data), - 'deleted' => (int) $instance['deleted'], - ); - $instance['id'] = db_insert('field_config_instance') - ->fields($record) - ->execute(); + // Save in config. + Drupal::config('field.instance.' . $instance_config['id']) + ->setData($instance_config) + ->save(); + update_config_manifest_add('field.instance', array($instance_config['id'])); } /** - * @addtogroup updates-7.x-to-8.x - * @{ - */ - -/** * Implements hook_update_dependencies(). */ function field_update_dependencies() { - // Convert Field API to ConfigEntities after: + // Convert Field API to ConfigEntities after the {file.usage}.id column + // has moved to varchar. $dependencies['field'][8003] = array( - // - Custom block bodies have been turned to fields. - 'block' => 8008, - // - User pictures have been turned to fields. - 'user' => 8011, - // - The {file_usage}.id column has moved to varchar. 'file' => 8001, ); return $dependencies; } /** + * @addtogroup updates-7.x-to-8.x + * @{ + */ + +/** * Empty update - moved into field_update_8003(). */ function field_update_8001() { diff --git a/core/modules/overlay/overlay.install b/core/modules/overlay/overlay.install index 588f871..29e6fa9 100644 --- a/core/modules/overlay/overlay.install +++ b/core/modules/overlay/overlay.install @@ -24,7 +24,7 @@ function overlay_enable() { function overlay_update_dependencies() { // Migrate users.data after User module prepared the tables. $dependencies['overlay'][8000] = array( - 'user' => 8011, + 'user' => 8016, ); return $dependencies; } diff --git a/core/modules/user/user.install b/core/modules/user/user.install index dca417c..d0ca5ef 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -373,6 +373,18 @@ function user_install_picture_field() { } /** + * Implements hook_update_dependencies(). + */ +function user_update_dependencies() { + // Convert user picture to field after the fields and instances are converted + // to ConfigEntities. + $dependencies['user'][8011] = array( + 'field' => 8003, + ); + return $dependencies; +} + +/** * @addtogroup updates-7.x-to-8.x * @{ */ @@ -697,7 +709,7 @@ function user_update_8011() { // Create the field and instance. $field = array( - 'field_name' => 'user_picture', + 'id' => 'user_picture', 'module' => 'image', 'type' => 'image', 'cardinality' => 1, @@ -707,15 +719,11 @@ function user_update_8011() { 'uri_scheme' => 'public', 'default_image' => FALSE, ), - 'storage' => array( - 'type' => 'field_sql_storage', - 'settings' => array(), - ), ); - _update_7000_field_create_field($field); + _update_8000_field_create_field($field); $instance = array( - 'field_name' => 'user_picture', + 'id' => 'user.user.user_picture', 'entity_type' => 'user', 'label' => 'Picture', 'bundle' => 'user', @@ -741,7 +749,7 @@ function user_update_8011() { 'weight' => -1, ), ); - _update_7000_field_create_instance($field, $instance); + _update_8000_field_create_instance($field, $instance); // Assign display settings for the 'default' and 'compact' view modes. In D7, // user pictures did not require Image module to work. Image module only @@ -776,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. @@ -787,20 +798,12 @@ function user_update_8011() { 'fid' => $default_image_fid, 'module' => 'image', 'type' => 'default_image', - 'id' => $field['id'], + 'id' => $field['uuid'], 'count' => 1, )) ->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');