function location_taxonomize_location_bulk_taxonomize_op in Location Taxonomize 7.2
Runs the bulk taxonomize operation
File
- location_taxonomize_location/
location_taxonomize_location.module, line 60
Code
function location_taxonomize_location_bulk_taxonomize_op($form_state, &$context) {
// initialize progress, max, and current if this is the first iteration
if (!isset($context['sandbox']['progress'])) {
$max = db_query('SELECT COUNT(DISTINCT lid) FROM {location}')
->fetchField();
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = $max;
$context['sandbox']['current'] = 0;
$context['results']['added'] = 0;
$context['results']['processed'] = 0;
}
// maximum 20 locations per function iteration
$limit = 20;
// iterate through the next group of locations
$result = db_query_range("SELECT lid, name, street, additional, city, province, postal_code, country, latitude, longitude, source FROM {location} WHERE lid <> 0 ORDER BY lid ASC", $context['sandbox']['current'], $limit, array());
$result_array = $result
->fetchAllAssoc('lid');
$taxonomize = array();
$count = 0;
foreach ($result_array as $row) {
$address = location_taxonomize_location_fixup((array) $row);
$lid = $address['lid'];
$nid_results = db_query("SELECT nid FROM {location_instance} WHERE lid = :lid", array(
":lid" => $lid,
));
$nid = $nid_results
->fetchField();
$taxonomize[$nid][] = $address;
$count++;
}
$results = location_taxonomize_taxonomize_bulk($taxonomize);
$saved = $results['saved'];
$context['results']['added'] += $saved;
$context['sandbox']['progress'] += $count;
$context['message'] = t('Processing location', array());
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
$context['sandbox']['current'] = $context['sandbox']['progress'];
$context['results']['processed'] = $context['sandbox']['progress'];
}