Skip to content

Instantly share code, notes, and snippets.

@SergiuSavva
Created August 18, 2014 10:02
Show Gist options
  • Save SergiuSavva/e82e082bd3d507898e35 to your computer and use it in GitHub Desktop.
Save SergiuSavva/e82e082bd3d507898e35 to your computer and use it in GitHub Desktop.
<?php
/**
* Add full_html where format is null
*/
function mymodule_core_update_7110() {
$widgets = array('text_textarea', 'text_textarea_with_summary');
$translate_fields = variable_get('smartling_translate_fields', array());
$fields_need_update = array();
// Get all field instance for translatable fields.
foreach ($translate_fields as $bundle_name => $fields) {
$field_info_instances = field_info_instances('node', $bundle_name);
$intersect = array_intersect_key($field_info_instances, $translate_fields[$bundle_name]);
// Get list of text_textarea fields.
foreach ($intersect as $field_name => $field_instance) {
if (in_array($field_instance['widget']['type'], $widgets)) {
$fields_need_update[$field_name] = $field_instance;
}
}
}
// Update tables where format is NULL.
foreach ($fields_need_update as $field_name => $field_instance) {
$field_info = field_info_field($field_name);
$tables = array_keys($field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT']);
$table = reset($tables);
// Get format column name.
$format_column = $field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT'][$table]['format'];
// Update tables where format is null.
try {
db_update($table)
->fields(array($format_column => 'full_html'))
->condition($format_column, 'NULL', 'IS')
->execute();
} catch (Exception $e) {
watchdog('update', 'Error mymodule_update_7109 message : %mes',
array('%mes' => $e->getMessage())
);
}
}
cache_clear_all();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment