Skip to content

Instantly share code, notes, and snippets.

@scottalan
Forked from dsnopek/change_text_format.php
Last active August 29, 2015 14:09
Show Gist options
  • Save scottalan/b966f72ffe73389cb52d to your computer and use it in GitHub Desktop.
Save scottalan/b966f72ffe73389cb52d to your computer and use it in GitHub Desktop.
/**
* Change content from one input format to another, deleting the old at the end.
*
* @param string $old_format
* Name of the old input format.
* @param string $new_type
* Name of the new input format.
*/
function _myprofile_install_change_input_format($old_format, $new_format) {
// Change the format on all fields.
$fields = field_info_field_map();
foreach ($fields as $field_name => $field_info_lite) {
if (in_array($field_info_lite['type'], array('text_long', 'text_with_summary'))) {
$field_info = field_info_field($field_name);
if (empty($field_info['storage']['details']['sql'])) {
// If there is no SQL storage information, skip it!
continue;
}
foreach ($field_info['storage']['details']['sql'] as $table_info) {
foreach ($table_info as $table_name => $column_info) {
db_update($table_name)
->fields(array($column_info['format'] => $new_format))
->condition($column_info['format'], $old_format)
->execute();
}
}
}
}
// Change the format on all blocks.
db_update('block_custom')
->fields(array('format' => $new_format))
->condition('format', $old_format)
->execute();
// Delete the format afterward.
db_delete('filter')
->condition('format', $old_format)
->execute();
db_delete('filter_format')
->condition('format', $old_format)
->execute();
// Clear the cache so deletion takes in the UI.
cache_clear_all('filter_formats:', 'cache', TRUE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment