Posted by oskar_calvo on June 20, 2012 at 2:51pm
Por algún motivo, estoy depurando, da una única vuelta, como si solo encontrase un resultado, he comprobado que las querys a la bbdd no drupal funcionan correctamente.
Estoy mirando pero no encuentro si hay error. Yo no lo encuentro.
<?php
/**
* @function
* función para montar el proceso de batch api
*
*/
function _mimodulo_batch_migrate_categories() {
$batch = array(
'title' => t('Exporting'),
'operations' => array(
array('_mimodulo_migrate_categories',array()),
),
'finished' => '_mimodulo_migrate_categories_finished',
'file' => drupal_get_path('mimodulo', 'mimodulo.categories.inc'),
);
batch_set($batch);
// Only needed if not inside a form _submit handler.
// Setting redirect in batch_process.
batch_process('admin/config/development/mimodulo');
}
?><?php
/**
* @ function
* función que se ejecuta reiteradamente mientras sean recursivas.
*
*/
function _mimodulo_migrate_categories(&$context){
//include the object to conect with the new ddbb.
include_once('mimodulo.class.mysql.php');
// Use the $context['sandbox'] at your convenience to store the
// information needed to track progression between successive calls.
if (empty($context['sandbox'])) {
$context['sandbox'] = array();
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_tid'] = 0;
//conection
$db = MysqlDDBB::getInstance();
$db->setQuery('SELECT * FROM categoria ORDER BY ID_CATEGORIA');
$cantidad = $db->CountResult();
// Save node count for the termination message.
$context['sandbox']['max'] = $cantidad;
}
//limit
$limit = 10;
// Retrieve the next group of ID_CATEGORIA.
$query = 'SELECT * FROM categoria ';
$query .= ' limit '. $context['sandbox']['progress'] .','. $limit;
$db2 = MysqlDDBB::getInstance();
$db2->setQuery($query);
$result = $db2->loadObjectList();
foreach ($result as $row) {
//guardamos la taxonomía
$term = new stdClass;
//Vocabulary 1 is the main vocabulary.
$term->vid = 1;
$term->name = $row->NOMBRE;
$term->vocabulary_machine_name = transliteration_clean_filename($row->NOMBRE, $source_langcode = NULL) .'-'. $row->ID_CATEGORIA;
taxonomy_term_save($term);
//save the new data in temporal tables.
db_insert('categorias')
->fields(array (
'ID_CATEGORIA' => $row->ID_CATEGORIA,
'NOMBRE' => $row->NOMBRE,
'ID_PADRE' => $row->ID_PADRE,
'tid' => $term->tid,
))
->execute();
// Store some result for post-processing in the finished callback.
$context['results'][] = $row->ID_CATEGORIA . ' : ' . check_plain($row->nombre);
// Update our progress information.
$context['sandbox']['progress']++;
$context['sandbox']['current_tid'] = $row->ID_CATEGORIA;
$context['message'] = $row->NOMBRE;
}
// 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'];
}
}
?><?php
/**
*
*/
function _mimodulo_migrate_categories_finished($success, $results, $operations) {
var_dump($success);
var_dump($results);
var_dump($operations);
if ($success) {
// Here we could do something meaningful with the results.
// We just display the number of nodes we processed...
drupal_set_message(t('@count results processed in @requests HTTP requests.', array('@count' => count($results), '@requests' => _batch_example_get_http_requests())));
drupal_set_message(t('The final result was "%final"', array('%final' => end($results))));
}
else {
// An error occurred.
// $operations contains the operations that remained unprocessed.
$error_operation = reset($operations);
drupal_set_message(t('An error occurred while processing @operation with arguments : @args', array('@operation' => $error_operation[0], '@args' => print_r($error_operation[0], TRUE))));
}
}
?>Gracias
Oskar
