diff --git a/modules/field/field.install b/modules/field/field.install index d56eb90..00ddd38 100644 --- a/modules/field/field.install +++ b/modules/field/field.install @@ -435,5 +435,53 @@ function field_update_7001() { } /** + * Make every field with no language-aware values non translatable. + */ +function field_update_7002() { + // Check that Locale is not installed, this is the only scenario in which the + // update can run safely. + $result = db_select('system', 's') + ->fields('s', array('name')) + ->condition('name', 'locale') + ->condition('schema_version', -1) + ->countQuery() + ->range(0, 1) + ->execute() + ->fetchObject(); + + if (empty($result->expression)) { + return; + } + + $fields = _update_7000_field_read_fields(); + + // For each field check that no value has a language assigned, otherwise + // switching the field's translatablity would cause misbehaviors in the whole + // field attach workflow. + foreach ($fields as $field) { + $query = new EntityFieldQuery(); + + $count = $query + ->fieldLanguageCondition($field, LANGUAGE_NONE, '!=') + ->range(0, 1) + ->count() + ->execute(); + + if ($count > 0) { + // We cannot proceed with the update. + return; + } + } + + // Switch all fields translatability to FALSE. + db_update('field_config') + ->fields(array('translatable' => 0)) + ->execute(); + + // Ensure that the updated values are correctly picked up. + field_info_cache_clear(); +} + +/** * @} End of "addtogroup updates-6.x-to-7.x" */