diff --git a/includes/update.inc b/includes/update.inc index 1eb7a1d..7cd79d7 100644 --- a/includes/update.inc +++ b/includes/update.inc @@ -748,6 +748,9 @@ function update_fix_d7_requirements() { // Rename action description to label. db_change_field('actions', 'description', 'label', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0')); + // Include updates of new core modules. + update_fix_new_modules(); + variable_set('update_d7_requirements', TRUE); } @@ -755,6 +758,34 @@ function update_fix_d7_requirements() { } /** + * Prepares system records of new core modules to include their updates. + * + * In order to have module updates from newly added core modules picked up + * during a major version upgrade, their schema_version needs to be changed from + * SCHEMA_UNINSTALLED to 0 (unless they existed in the previous version + * already), since only updates of installed modules are ran. + * + * This cannot be done during execution of updates, since we need to calculate + * update dependencies. Without this adjustment, only module updates being + * required by other modules would be executed. + * + * Lastly, each of these modules should have an accompanying + * MODULE_schema_7000() implementation of hook_schema(), which specifies the + * original schema at the time of upgrading, in case the module has later + * updates that are changing the schema. The module update that enables the + * module MUST NOT use module_enable() to install the module. + */ +function update_fix_new_modules() { + $module_list = array('field_sql_storage', 'field', 'field_ui', 'text', 'number', 'list', 'options'); + db_update('system') + ->condition('type', 'module') + ->condition('name', $module_list, 'IN') + ->condition('schema_version', SCHEMA_UNINSTALLED) + ->fields(array('schema_version' => 0)) + ->execute(); +} + +/** * Register the currently installed profile in the system table. * * Install profiles are now treated as modules by Drupal, and have an upgrade diff --git a/modules/field/field.install b/modules/field/field.install index d56eb90..b9e6a5b 100644 --- a/modules/field/field.install +++ b/modules/field/field.install @@ -168,6 +168,168 @@ function field_schema() { } /** + * Implements hook_schema() for update_fix_new_modules(). + */ +function field_schema_7000() { + // Static (meta) tables. + $schema['field_config'] = array( + 'fields' => array( + 'id' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'description' => 'The primary identifier for a field', + ), + 'field_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'description' => 'The name of this field. Non-deleted field names are unique, but multiple deleted fields can have the same name.', + ), + 'type' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'description' => 'The type of this field.', + ), + 'module' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The module that implements the field type.', + ), + 'active' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Boolean indicating whether the module that implements the field type is enabled.', + ), + 'storage_type' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'description' => 'The storage backend for the field.', + ), + 'storage_module' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + 'description' => 'The module that implements the storage backend.', + ), + 'storage_active' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + 'description' => 'Boolean indicating whether the module that implements the storage backend is enabled.', + ), + 'locked' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + 'description' => '@TODO', + ), + 'data' => array( + 'type' => 'blob', + 'size' => 'big', + 'not null' => TRUE, + 'serialize' => TRUE, + 'description' => 'Serialized data containing the field properties that do not warrant a dedicated column.', + ), + 'cardinality' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + 'translatable' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + 'deleted' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('id'), + 'indexes' => array( + 'field_name' => array('field_name'), + // Used by field_read_fields(). + 'active' => array('active'), + 'storage_active' => array('storage_active'), + 'deleted' => array('deleted'), + // Used by field_modules_disabled(). + 'module' => array('module'), + 'storage_module' => array('storage_module'), + // Used by field_associate_fields(). + 'type' => array('type'), + 'storage_type' => array('storage_type'), + ), + ); + $schema['field_config_instance'] = array( + 'fields' => array( + 'id' => array( + 'type' => 'serial', + 'not null' => TRUE, + 'description' => 'The primary identifier for a field instance', + ), + 'field_id' => array( + 'type' => 'int', + 'not null' => TRUE, + 'description' => 'The identifier of the field attached by this instance', + ), + 'field_name' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '' + ), + 'entity_type' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '' + ), + 'bundle' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '' + ), + 'data' => array( + 'type' => 'blob', + 'size' => 'big', + 'not null' => TRUE, + 'serialize' => TRUE, + ), + 'deleted' => array( + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('id'), + 'indexes' => array( + // Used by field_delete_instance(). + 'field_name_bundle' => array('field_name', 'entity_type', 'bundle'), + // Used by field_read_instances(). + 'deleted' => array('deleted'), + ), + ); + $schema['cache_field'] = drupal_get_schema_unprocessed('system', 'cache'); + + return $schema; +} + +/** * Utility function: create a field by writing directly to the database. * * This function can be used for databases whose schema is at field module diff --git a/modules/system/system.install b/modules/system/system.install index e55c7cf..2babb2b 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -2071,8 +2071,15 @@ function system_update_7018() { /** * Enable field and field_ui modules. + * + * @see update_fix_new_modules() */ function system_update_7020() { + $schema = array(); + $schema += field_schema_7000(); + foreach ($schema as $table => $spec) { + db_create_table($table, $spec); + } $module_list = array('field_sql_storage', 'field', 'field_ui'); module_enable($module_list, FALSE); } @@ -2089,6 +2096,8 @@ function system_update_7021() { /** * Enable field type modules. + * + * @see update_fix_new_modules() */ function system_update_7027() { $module_list = array('text', 'number', 'list', 'options');