diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-09-29 19:46:40 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-09-29 19:46:40 +0000 |
commit | 0a8e9c5b20c09e896f7627a15b5cf817e9ed5f9e (patch) | |
tree | 1d2b9ace8b4387e78ccede842f4ab8a1a11f2ed4 /modules | |
parent | a6a4073b808b6af1b6e60f7a82666a1ccfd405c2 (diff) | |
download | brdo-0a8e9c5b20c09e896f7627a15b5cf817e9ed5f9e.tar.gz brdo-0a8e9c5b20c09e896f7627a15b5cf817e9ed5f9e.tar.bz2 |
- Patch #898558 by Damien Tournoud, chx, ksenzee: clean-up the upgrade path: node.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/field/field.install | 23 | ||||
-rw-r--r-- | modules/field/modules/field_sql_storage/field_sql_storage.install | 80 | ||||
-rw-r--r-- | modules/node/node.install | 80 |
3 files changed, 143 insertions, 40 deletions
diff --git a/modules/field/field.install b/modules/field/field.install index 8a57d0089..91b0d210f 100644 --- a/modules/field/field.install +++ b/modules/field/field.install @@ -171,7 +171,8 @@ function field_schema() { /** * Utility function: create a field by writing directly to the database. * - * This function is valid for a database schema version 7000. + * This function can be used for databases whose schema is at field module + * version 7000 or higher. * * @ingroup update-api-6.x-to-7.x */ @@ -240,14 +241,15 @@ function _update_7000_field_create_field(&$field) { } /** - * Utility function: delete a field stored in SQL Storage directly from the database. + * Utility function: delete 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(). * - * This function is valid for a database schema version 7000. + * This function can be used for databases whose schema is at field module + * version 7000 or higher. * * @param $field_name * The field name to delete. @@ -332,9 +334,10 @@ function _update_7000_field_read_fields() { } /** - * Utility function: create a field instance directly to the database. + * Utility function: write a field instance directly to the database. * - * This function is valid for a database schema version 7000. + * This function can be used for databases whose schema is at field module + * version 7000 or higher. * * @ingroup update-api-6.x-to-7.x */ @@ -374,10 +377,12 @@ function _update_7000_field_create_instance($field, &$instance) { * Field update version placeholder. */ function field_update_7000() { - // _update_7000_field_create_field() is supposed to create fields according - // to the structure of fields after running field_update_7000(). So this - // function needs to exist but as field is a new module in Drupal 7, it - // does not need to do anything. + // Some update helper functions (such as _update_7000_field_create_field()) + // modify the database directly. They can be used safely only if the database + // schema matches the field module schema established for Drupal 7.0 (i.e. + // version 7000). This function exists solely to set the schema version to + // 7000, so that update functions calling those helpers can do so safely + // by declaring a dependency on field_update_7000(). } /** diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.install b/modules/field/modules/field_sql_storage/field_sql_storage.install index 81a1dcf6f..92692a7e5 100644 --- a/modules/field/modules/field_sql_storage/field_sql_storage.install +++ b/modules/field/modules/field_sql_storage/field_sql_storage.install @@ -44,3 +44,83 @@ function field_sql_storage_schema() { } return $schema; } + +/** + * Utility function: write field data directly to SQL storage. + * + * This function can be used for databases whose schema is at field module + * version 7000 or higher. + * + * @ingroup update-api-6.x-to-7.x + */ +function _update_7000_field_sql_storage_write($entity_type, $bundle, $entity_id, $revision_id, $field_name, $data) { + $etid = _field_sql_storage_etid($entity_type); + $table_name = "field_data_{$field_name}"; + $revision_name = "field_revision_{$field_name}"; + + db_delete($table_name) + ->condition('etid', $etid) + ->condition('entity_id', $entity_id) + ->execute(); + db_delete($revision_name) + ->condition('etid', $etid) + ->condition('entity_id', $entity_id) + ->condition('revision_id', $revision_id) + ->execute(); + + $columns = array(); + foreach ($data as $langcode => $items) { + foreach ($items as $delta => $item) { + $record = array( + 'etid' => $etid, + 'entity_id' => $entity_id, + 'revision_id' => $revision_id, + 'bundle' => $bundle, + 'delta' => $delta, + 'language' => $langcode, + ); + foreach ($item as $column => $value) { + $record[_field_sql_storage_columnname($field_name, $column)] = $value; + } + + $records[] = $record; + // Record the columns used. + $columns += $record; + } + } + + if ($columns) { + $query = db_insert($table_name)->fields(array_keys($columns)); + $revision_query = db_insert($revision_name)->fields(array_keys($columns)); + foreach ($records as $record) { + $query->values($record); + if ($revision_id) { + $revision_query->values($record); + } + } + $query->execute(); + $revision_query->execute(); + } +} + +/** + * @defgroup field-sql-storage-updates-6.x-to-7.x Field SQL storage updates from 6.x to 7.x + * @{ + */ + +/** + * Field SQL storage update version placeholder. + */ +function field_sql_storage_update_7000() { + // Some update helper functions (such as + // _update_7000_field_sql_storage_write()) modify the database directly. They + // can be used safely only if the database schema matches the field module + // schema established for Drupal 7.0 (i.e. version 7000). This function exists + // solely to set the schema version to 7000, so that update functions calling + // those helpers can do so safely by declaring a dependency on + // field_sql_storage_update_7000(). +} + +/** + * @} End of "defgroup field-updates-6.x-to-7.x" + */ diff --git a/modules/node/node.install b/modules/node/node.install index f63caa1e7..56af7bce3 100644 --- a/modules/node/node.install +++ b/modules/node/node.install @@ -485,10 +485,9 @@ function node_update_7004() { // Map old preview setting to new values order. $original_preview ? $original_preview = 2 : $original_preview = 1; drupal_static_reset('_node_types_build'); - $type_list = node_type_get_types(); // Apply original settings to all types. - foreach ($type_list as $type => $entity) { + foreach (_update_7000_node_get_types() as $type => $type_object) { variable_set('teaser_length_' . $type, $original_length); variable_set('node_preview_' . $type, $original_preview); } @@ -517,18 +516,27 @@ function node_update_7006(&$sandbox) { // Get node type info for every invocation. drupal_static_reset('_node_types_build'); - $node_types = node_type_get_types(); if (!isset($sandbox['total'])) { // Initial invocation. + // First, create the body field. + $body_field = array( + 'field_name' => 'body', + 'type' => 'text_with_summary', + 'module' => 'text', + 'cardinality' => 1, + 'entity_types' => array('node'), + 'translatable' => TRUE, + ); + _update_7000_field_create_field($body_field); + + $default_trim_length = variable_get('teaser_length', 600); + // Get node type info, specifically the body field settings. - $result = db_select('node_type', 'node_type') - ->fields('node_type') - ->execute(); - foreach ($result as $type_object) { - $node_types[$type_object->type] = $type_object; - } + $node_types = _update_7000_node_get_types(); + + // Create default settings for orphan nodes. $extra_types = db_query('SELECT DISTINCT type FROM {node} WHERE type NOT IN (:types)', array(':types' => array_keys($node_types)))->fetchCol(); foreach ($extra_types as $type) { $type_object = new stdClass; @@ -541,26 +549,38 @@ function node_update_7006(&$sandbox) { $node_types[$type_object->type] = $type_object; } - $default_trim_length = variable_get('teaser_length', 600); // Add body field instances for existing node types. foreach ($node_types as $node_type) { if ($node_type->has_body) { - $instance = node_add_body_field($node_type, $node_type->body_label); - // Update newly created instance to convert teaser_length variable - // into formatter settings. $trim_length = variable_get('teaser_length_' . $node_type->type, $default_trim_length); - $instance_changed = FALSE; - foreach ($instance['display'] as $view_mode => $view_mode_info) { - if ($view_mode_info['type'] == 'text_trimmed' || $view_mode_info['type'] == 'text_summary_or_trimmed') { - if (!isset($view_mode_info['settings']['trim_length'])) { - $instance['display'][$view_mode]['settings']['trim_length'] = $trim_length; - $instance_changed = TRUE; - } - } - } - if ($instance_changed) { - field_update_instance($instance); - } + + $instance = array( + 'entity_type' => 'node', + 'bundle' => $node_type->type, + 'label' => $node_type->body_label, + 'widget' => array( + 'type' => 'text_textarea_with_summary', + 'settings' => array( + 'rows' => 20, + 'summary_rows' => 5, + ), + 'weight' => -4, + 'module' => 'text', + ), + 'settings' => array('display_summary' => TRUE), + 'display' => array( + 'default' => array( + 'label' => 'hidden', + 'type' => 'text_default', + ), + 'teaser' => array( + 'label' => 'hidden', + 'type' => 'text_summary_or_trimmed', + 'trim_length' => $trim_length, + ), + ), + ); + _update_7000_field_create_instance($body_field, $instance); variable_del('teaser_length_' . $node_type->type); } // Leave 'teaser_length' variable for aggregator module upgrade. @@ -580,14 +600,12 @@ function node_update_7006(&$sandbox) { $query = db_select('node', 'n'); $query->join('node_revision', 'nr', 'n.vid = nr.vid'); $sandbox['total'] = $query->countQuery()->execute()->fetchField(); + + $sandbox['body_field_id'] = $body_field['id']; } else { // Subsequent invocations. - // Grab the body field ID for field_sql_storage_field_storage_write(). - $body_field = field_info_field('body'); - $body_field_id = $body_field['id']; - $found = FALSE; if ($sandbox['total']) { // Operate on every revision of every node (whee!), in batches. @@ -647,7 +665,7 @@ function node_update_7006(&$sandbox) { } // This is a core update and no contrib modules are enabled yet, so // we can assume default field storage for a faster update. - field_sql_storage_field_storage_write('node', $node, FIELD_STORAGE_INSERT, array($body_field_id)); + _update_7000_field_sql_storage_write('node', $node->type, $node->nid, $node->vid, 'body', $node->body); } // Migrate the status columns to the {node_revision} table. @@ -699,7 +717,7 @@ function node_update_7007() { function node_update_7008() { $roles = user_roles(FALSE, 'administer nodes'); foreach ($roles as $rid => $role) { - user_role_grant_permissions($rid, array('access content overview')); + _update_7000_user_role_grant_permissions($rid, array('access content overview'), 'node'); } } |