diff --git a/modules/field/field.install b/modules/field/field.install index d56eb90..8e48155 100644 --- a/modules/field/field.install +++ b/modules/field/field.install @@ -435,5 +435,51 @@ function field_update_7001() { } /** + * Disable 'translatable' flag for all fields that do not contain language-specific field values. + */ +function field_update_7002() { + $fields = _update_7000_field_read_fields(array( + // Only currently enabled fields are affected. + 'translatable' => 1, + // Field storage engines depend on the module and hook system; we can only + // query and update fields in SQL. Alternative field storage engines have to + // implement a corresponding module update on their own. + 'storage_type' => 'field_sql_storage', + // Field configuration and values of deleted fields are irrelevant. + 'deleted' => 0, + )); + $changed_fields = array(); + foreach ($fields as $field) { + $tables = array("field_data_{$field['field_name']}", "field_revision_{$field['field_name']}"); + $has_language = FALSE; + foreach ($tables as $table) { + // 'und' denotes LANGUAGE_NONE; constant values may change over time. + $query = db_select($table)->condition('language', 'und', '<>')->range(0, 1); + $query->addExpression(1); + $has_language = $has_language || $query->execute()->fetchField(); + } + // Only in case there is no language-specific field value, update the + // field's configuration to mark it untranslatable. + // Note: There is a small chance of disabling the translatable flag for + // fields that actually have a field translation handler associated (but + // e.g., no values yet). However, since the field translation handler + // entirely depends on module hooks, it is impossible to gather this + // information in a module update. + if (!$has_language) { + $changed_fields[] = $field['field_name']; + db_update('field_config') + ->condition('id', $field['id']) + ->fields(array('translatable' => 0)) + ->execute(); + } + } + if ($changed_fields) { + drupal_set_message(t('The following fields have been changed to be no longer translatable: %field-list.', array( + '%field-list' => implode(', ', $changed_fields), + ))); + } +} + +/** * @} End of "addtogroup updates-6.x-to-7.x" */