function _asin_migrate_field_from_d5 in Amazon Product Advertisement API 6
Batch Operation Callback
1 string reference to '_asin_migrate_field_from_d5'
- asin_update_6002 in asin/
asin.install - Migrate old data from the D5 version.
File
- asin/
asin.d5-migrate.inc, line 6
Code
function _asin_migrate_field_from_d5($fields, &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_node'] = 0;
$sql = "SELECT COUNT(DISTINCT nid) FROM {amazonnode} WHERE ntype IN ";
$sql .= '(' . db_placeholders($fields, 'varchar') . ')';
$context['sandbox']['max'] = db_result(db_query($sql, array_keys($fields)));
}
$sql = "SELECT DISTINCT(nid) FROM {amazonnode} WHERE ntype IN (" . db_placeholders($fields, 'varchar') . ") ORDER BY nid ASC";
$params[] = $context['sandbox']['current_node'];
$nid_results = db_query_range($sql, array_keys($fields), 0, 20);
$nids = array();
while ($nid = db_fetch_object($nid_results)) {
$nids[] = $nid->nid;
}
foreach ($nids as $nid) {
if ($node = _asin_migrate_from_d5($nid, $fields)) {
$context['results'][$node->nid] = $node->title;
$context['sandbox']['progress']++;
$context['sandbox']['current_node'] = $node->nid;
$context['message'] = t('Now processing %node', array(
'%node' => $node->title,
));
}
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}