Commit ce009a02 authored by KarenS's avatar KarenS
Browse files

Ensure that text filter formats get set to an allowed value during the...

Ensure that text filter formats get set to an allowed value during the migration, borrowing code from node_update_7006().
parent e3ddc834
......@@ -328,6 +328,9 @@ function _content_migrate_batch_process_migrate_data($field_name, &$context) {
return;
}
$field = $context['sandbox']['fields'][$field_name];
$instance = $context['sandbox']['instances'][$field_name][$node['type']];
// Construct an record to insert into the new field table
// from the data in the old table.
......@@ -359,11 +362,10 @@ function _content_migrate_batch_process_migrate_data($field_name, &$context) {
$query->condition('nid', $node['nid']);
$result = $query->execute();
$field = field_info_field($field_name);
foreach ($result as $record) {
// Let modules alter this before the insert.
drupal_alter('content_migrate_data_record', $record, $context['sandbox']['field']);
drupal_alter('content_migrate_data_record', $record, $field, $instance);
// Don't save empty values.
if (!empty($record)) {
......
......@@ -102,7 +102,7 @@ function content_migrate_filefield_instance_alter(&$instance_value, $field_value
*
* Tweaks individual records in a field.
*/
function content_migrate_filefield_data_record_alter(&$record, $field) {
function content_migrate_filefield_data_record_alter(&$record, $field, $instance) {
switch($field['type']) {
case 'image':
......
......@@ -88,4 +88,28 @@ function content_migrate_text_instance_alter(&$instance_value, $field_value) {
break;
}
}
/**
* Implements hook_content_migrate_data_record_alter().
*
* Tweaks individual records in a field.
*/
function content_migrate_text_data_record_alter(&$record, $field, $instance) {
$existing_formats = &drupal_static(__FUNCTION__);
if (empty($existing_formats)) {
$existing_formats = db_query("SELECT format FROM {filter_format}")->fetchCol();
}
switch($field_value['module']) {
case 'text':
if (!empty($instance_value['settings']['text_processing'])) {
// Adapted from node_update_7006(), to adjust the filter format values
// from the old numeric to the new text formats. Ensure we have a valid value.
if (!in_array($record[$field['field_name'] . '_format'], $existing_formats)) {
$record[$field['field_name'] . '_format'] = variable_get('filter_default_format', 1);
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment