function migrate_content_process_batch in Migrate 6
Process all enabled migration processes in a browser, using the Batch API to break it into manageable chunks.
Parameters
$clearing: Array of content set ids (keyed by content set id) to clear
$importing: Array of content set ids (keyed by content set id) to import
$limit: Maximum number of items to process
$idlist: Comma-separated list of source IDs to process, instead of proceeding through all unmigrated rows
$context: Batch API context structure
1 string reference to 'migrate_content_process_batch'
File
- ./
migrate.module, line 870 - This module provides tools at "administer >> content >> migrate" for analyzing data from various sources and importing them into Drupal tables.
Code
function migrate_content_process_batch($clearing, $importing, $limit, $idlist, &$context) {
// A zero max_execution_time means no limit - but let's set a reasonable
// limit anyway
$starttime = time();
$maxexectime = ini_get('max_execution_time');
if (!$maxexectime) {
$maxexectime = 240;
}
// Initialize the Batch API context
$context['finished'] = 0;
// The Batch API progress bar will reflect the number of operations being
// done (clearing/importing)
if (!isset($context['sandbox']['numops'])) {
$context['sandbox']['numops'] = count($clearing) + count($importing);
$context['sandbox']['numopsdone'] = 0;
$context['sandbox']['clearing'] = $clearing;
$context['sandbox']['importing'] = $importing;
$context['sandbox']['message'] = '';
$context['sandbox']['times'] = array();
}
// For the timelimit, subtract more than enough time to clean up
$options = array(
'itemlimit' => $limit,
'timelimit' => $starttime + ($maxexectime < 5 ? $maxexectime : $maxexectime - 5),
'idlist' => $idlist,
'feedback' => array(
'function' => '_migrate_process_message',
),
);
global $_migrate_messages;
if (!isset($_migrate_messages)) {
$_migrate_messages = array();
}
// Work on the last clearing op (if any)
if (count($context['sandbox']['clearing'])) {
$row = db_fetch_object(db_query("SELECT mcsid,description FROM {migrate_content_sets}\n WHERE mcsid IN (%s)\n ORDER BY weight DESC\n LIMIT 1", implode(',', $context['sandbox']['clearing'])));
$status = migrate_content_process_clear($row->mcsid, $options);
if ($status != MIGRATE_RESULT_INCOMPLETE) {
unset($context['sandbox']['clearing'][$row->mcsid]);
}
}
elseif (count($context['sandbox']['importing'])) {
$row = db_fetch_object(db_query("SELECT mcsid,description FROM {migrate_content_sets}\n WHERE mcsid IN (%s)\n ORDER BY weight ASC\n LIMIT 1", implode(',', $context['sandbox']['importing'])));
if (variable_get('migrate_update', 0)) {
migrate_content_set_update($row->mcsid);
variable_set('migrate_update', 0);
}
$status = migrate_content_process_import($row->mcsid, $options);
if ($status != MIGRATE_RESULT_INCOMPLETE) {
unset($context['sandbox']['importing'][$row->mcsid]);
}
}
else {
$context['finished'] = 1;
}
// Make sure the entire process stops if requested
if ($status == MIGRATE_RESULT_STOPPED) {
$context['finished'] = 1;
}
if ($context['finished'] != 1) {
if ($status != MIGRATE_RESULT_INCOMPLETE) {
$context['sandbox']['numopsdone']++;
}
$context['finished'] = $context['sandbox']['numopsdone'] / $context['sandbox']['numops'];
}
foreach ($_migrate_messages as $message) {
if (!isset($context['sandbox']['message'])) {
$context['sandbox']['message'] = $message . '<br />';
}
else {
$context['sandbox']['message'] .= $message . '<br />';
}
$context['message'] = $context['sandbox']['message'];
$context['results'][] .= $message;
}
$context['message'] = $context['sandbox']['message'];
// If requested save timers for eventual display
if (variable_get('migrate_display_timers', 0)) {
global $timers;
foreach ($timers as $name => $timerec) {
if (isset($timerec['time'])) {
if (isset($context['sandbox']['times'][$name])) {
$context['sandbox']['times'][$name] += $timerec['time'] / 1000;
}
else {
$context['sandbox']['times'][$name] = $timerec['time'] / 1000;
}
}
}
// When all done, display the timers
if ($context['finished'] == 1 && isset($context['sandbox']['times'])) {
global $timers;
arsort($context['sandbox']['times']);
foreach ($context['sandbox']['times'] as $name => $total) {
drupal_set_message("{$name}: " . round($total, 2));
}
}
}
}