function migrate_ui_migrate_submit in Migrate 7.2
Submit callback for the dashboard form.
1 string reference to 'migrate_ui_migrate_submit'
- _migrate_ui_migrate_operations in migrate_ui/
migrate_ui.pages.inc
File
- migrate_ui/
migrate_ui.pages.inc, line 410 - Pages for managing migration processes.
Code
function migrate_ui_migrate_submit($form, &$form_state) {
$values = $form_state['values'];
$operation = $values['operation'];
$limit = $values['limit'];
if (isset($values['update'])) {
$update = $values['update'];
}
else {
$update = 0;
}
if (isset($values['force'])) {
$force = $values['force'];
}
else {
$force = 0;
}
$machine_names = _migrate_ui_selected_migrations($values);
$operations = array();
// Rollback in reverse order.
if (in_array($operation, array(
'rollback_immediate',
'deregister',
))) {
$machine_names = array_reverse($machine_names);
}
// Special case: when deregistering a group, go through the group API
if ($operation == 'deregister' && isset($values['tasks'])) {
foreach ($values['tasks'] as $task) {
MigrateGroup::deregister($task);
}
return;
}
$drush_arguments = array();
foreach ($machine_names as $machine_name) {
$migration = Migration::getInstance($machine_name);
if ($migration) {
switch ($operation) {
case 'import_immediate':
// Update (if necessary) once, before starting
if ($update && method_exists($migration, 'prepareUpdate')) {
$migration
->prepareUpdate();
}
$operations[] = array(
'migrate_ui_batch',
array(
'import',
$machine_name,
$limit,
$force,
),
);
break;
case 'rollback_immediate':
$operations[] = array(
'migrate_ui_batch',
array(
'rollback',
$machine_name,
$limit,
$force,
),
);
break;
case 'import_background':
case 'rollback_background':
$drush_arguments[] = $machine_name;
break;
case 'stop':
$migration
->stopProcess();
break;
case 'reset':
$migration
->resetStatus();
break;
case 'deregister':
migrate_ui_deregister_migration($machine_name);
break;
}
}
}
// Only immediate rollback and import operations will need to go through Batch API.
if (count($operations) > 0) {
$batch = array(
'operations' => $operations,
'title' => t('Import processing'),
'file' => drupal_get_path('module', 'migrate_ui') . '/migrate_ui.pages.inc',
'init_message' => t('Starting import process'),
'progress_message' => t(''),
'error_message' => t('An error occurred. Some or all of the import processing has failed.'),
'finished' => 'migrate_ui_batch_finish',
);
batch_set($batch);
}
elseif (count($drush_arguments) > 0) {
$drush_path = trim(variable_get('migrate_drush_path', ''));
// Check that $drush_path works. See migrate_ui_configure_form().
if (!is_executable($drush_path)) {
$message = t('To enable running operations in the background with <a href="@drush">drush</a>, (which is <a href="@recommended">recommended</a>), some configuration must be done on the server. See the <a href="@config">documentation</a> on <a href="@dorg">drupal.org</a>.', array(
'@drush' => 'http://drupal.org/project/drush',
'@recommended' => 'http://drupal.org/node/1806824',
'@config' => 'http://drupal.org/node/1958170',
'@dorg' => 'http://drupal.org/',
));
drupal_set_message($message);
return;
}
$uri = $GLOBALS['base_url'];
$uid = $GLOBALS['user']->uid;
if ($operation == 'import_background') {
$command = 'mi';
$log_suffix = '.import.log';
}
else {
$command = 'mr';
$log_suffix = '.rollback.log';
}
$migrations = implode(',', $drush_arguments);
// If on Acquia, call required shell script to add environment variables.
$drush_command = isset($_ENV['AH_SITE_ENVIRONMENT']) ? "/mnt/users/{$_ENV['AH_SITE_GROUP']}/{$_ENV['AH_SITE_ENVIRONMENT']}.shell " : '';
$drush_command .= "{$drush_path} {$command} {$migrations} --user={$uid} --uri={$uri} " . '--root=' . DRUPAL_ROOT;
if ($force) {
$drush_command .= ' --force';
}
if ($update) {
$drush_command .= ' --update';
}
if (variable_get('migrate_drush_mail', 0)) {
$drush_command .= ' --notify';
}
if (!empty($limit['value'])) {
$limit = $limit['value'] . ' ' . $limit['unit'];
$drush_command .= " --limit=\"{$limit}\"";
}
$log_file = drupal_realpath('temporary://' . $drush_arguments[0] . $log_suffix);
$drush_command .= " >{$log_file} 2>&1 &";
exec($drush_command, $output, $status);
if (variable_get('migrate_drush_mail', 0)) {
drupal_set_message('Your operation is running in the background. You will receive an email message when it is complete.');
}
else {
drupal_set_message('Your operation is running in the background. You may ' . 'refresh the dashboard page to check on its progress.');
}
}
}