summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgit2013-12-12 20:13:06 (GMT)
committerColan Schwartz2013-12-12 20:13:06 (GMT)
commit821ff918b7dd9a801d51cfdd9e817763fbcd92f9 (patch)
tree9141d8d5cfb5481606814da4a3295c794444029c
parent8385497322a7dd2296f7816dc452524287760a88 (diff)
Issue #1266842 by fbrooks, Jody Lynn, colan: Added a try/catch to catch an error.HEAD7.x-3.0-alpha37.x-3.x
-rw-r--r--modules/content_migrate/includes/content_migrate.admin.inc60
1 files changed, 37 insertions, 23 deletions
diff --git a/modules/content_migrate/includes/content_migrate.admin.inc b/modules/content_migrate/includes/content_migrate.admin.inc
index 8d00768..a2ac7e8 100644
--- a/modules/content_migrate/includes/content_migrate.admin.inc
+++ b/modules/content_migrate/includes/content_migrate.admin.inc
@@ -390,6 +390,10 @@ function _content_migrate_batch_process_migrate_data($field_name, &$context) {
$node = array_shift($context['sandbox']['nodes']);
if (!$node) {
+ // Rollback the field if there was a data migration error.
+ if ($context['sandbox']['rollback'] == TRUE) {
+ content_migrate_rollback(array($field_name));
+ }
return;
}
$instance = field_info_instance('node', $field_name, $node['type']);
@@ -400,32 +404,44 @@ function _content_migrate_batch_process_migrate_data($field_name, &$context) {
foreach ($result as $record) {
module_load_include('inc', 'content_migrate', 'modules/content_migrate.' . $field['module']);
- // Let modules alter this before the insert.
- drupal_alter('content_migrate_data_record', $record, $field, $instance);
-
- // Don't save empty values.
- if (!empty($record)) {
- $function = $field['module'] . '_field_is_empty';
- if (function_exists($function)) {
- // The $record array has the database columns as keys, which drupal_write_record() will need,
- // but the _field_is_empty() function will be looking for the short, normalized column name.
- $item = array();
- foreach ($context['sandbox']['new_cols'] as $column_name => $db_column_name) {
- if (array_key_exists($db_column_name, $record)) {
- $item[$column_name] = $record[$db_column_name];
+ try {
+
+ // Let modules alter this before the insert.
+ drupal_alter('content_migrate_data_record', $record, $field, $instance);
+
+ // Don't save empty values.
+ if (!empty($record)) {
+ $function = $field['module'] . '_field_is_empty';
+ if (function_exists($function)) {
+ // The $record array has the database columns as keys, which drupal_write_record() will need,
+ // but the _field_is_empty() function will be looking for the short, normalized column name.
+ $item = array();
+ foreach ($context['sandbox']['new_cols'] as $column_name => $db_column_name) {
+ if (array_key_exists($db_column_name, $record)) {
+ $item[$column_name] = $record[$db_column_name];
+ }
+ }
+ if ($function($item, $field)) {
+ $record = NULL;
}
- }
- if ($function($item, $field)) {
- $record = NULL;
}
}
- }
- if (!empty($record)) {
- if ($record['revision_id'] == $node['vid']) {
- drupal_write_record($context['sandbox']['new_table'], $record);
+ if (!empty($record)) {
+ if ($record['revision_id'] == $node['vid']) {
+ drupal_write_record($context['sandbox']['new_table'], $record);
+ }
+ drupal_write_record($context['sandbox']['new_revision_table'], $record);
}
- drupal_write_record($context['sandbox']['new_revision_table'], $record);
+ }
+ catch (Exception $e) {
+ // An error has occurred trying to migrate a record of this field.
+ // Set this field to be rolledback and display a detailed error message.
+ $context['sandbox']['rollback'] = TRUE;
+ $exception = t('<p>Requesting rollback of field "@field" due to failure to convert record:</p>' .
+ '<p>@record</p> <p>Cause:</p> <p>@cause</p>',
+ array('@field' => $field_name, '@record' => var_export($record, TRUE), '@cause' => $e));
+ drupal_set_message($exception, 'error');
}
}
@@ -441,5 +457,3 @@ function _content_migrate_batch_process_migrate_data($field_name, &$context) {
}
}
-
-