added fr2en batch function

This commit is contained in:
Bachir Soussi Chiadmi 2015-11-24 10:59:13 +01:00
parent d7e7410950
commit 73993a539b
3 changed files with 2420 additions and 6 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -15,9 +15,13 @@ function materio_taxonomy_permission() {
// }
$perms['access taxonomy terms page'] = array(
'title' => t('access taxonomy terms page'),
'description' => t(''),
);
'title' => t('access taxonomy terms page'),
'description' => t(''),
);
$perms['access fr2en materio'] = array(
'title' => t('access fr2en materio'),
'description' => t(''),
);
return $perms;
}
@ -28,8 +32,6 @@ function materio_taxonomy_menu_alter(&$items) {
$items['taxonomy/term/%taxonomy_term/feed']['access arguments'] = array('access taxonomy terms page');
}
/**
* Implementation of hook_query_term_access_alter().
*
@ -74,4 +76,102 @@ function materio_taxonomy_query_term_access_alter(QueryAlterableInterface $query
}
}
}
}
/**
* Implements hook_menu().
*/
function materio_taxonomy_menu() {
$items['admin/taxonomy/fr2en'] = array(
'title' => 'fr2en taglibres',
'page callback' => 'drupal_get_form',
'page arguments' => array('materio_taxonomy_fr2en_form'),
'access arguments' => array('access fr2en materio'),
);
return $items;
}
function materio_taxonomy_fr2en_form(){
$form['description'] = array(
'#type' => 'markup',
'#markup' => t('convert tag libres terms name frome french to english from csv file'),
);
$form['batch'] = array(
'#type' => 'select',
'#title' => 'Choose batch',
'#options' => array(
'fr2en' => t('fr2en'),
'en2fr' => t('en2fr'),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Go',
);
return $form;
}
function materio_taxonomy_fr2en_form_submit($form, &$form_state) {
$function = 'materio_taxonomy_fr2en';
// Reset counter for debug information.
$_SESSION['http_request_count'] = 0;
// Execute the function named batch_example_1 or batch_example_2.
$batch = $function($form_state['values']['batch']);
batch_set($batch);
}
function materio_taxonomy_fr2en($op){
$file = drupal_get_path('module', 'materio_taxonomy')."/assets/taglibres_".$op.".csv";
$data = array();
if (($handle = fopen($file, "r")) !== FALSE) {
while (($line = fgetcsv($handle, 1000, ",")) !== FALSE) {
$data[$line[0]] = $line[1];
}
fclose($handle);
}else{
drupal_set_message("fopen csv file failed");
return;
}
$tags = taxonomy_get_tree(4); // get term list from vocabulary
$operations = [];
foreach ($tags as $tid => $t) {
if($t->name){
if(isset($data[$t->name])){
$operations[] = array(
'materio_taxonomy_fr2en_batch',
array(
$data[$t->name],
$t
)
);
}
}
}
$batch = array(
"operations" => $operations,
"finished" => "materio_taxonomy_fr2en_batch_finished"
);
return $batch;
}
function materio_taxonomy_fr2en_batch($name, $t, &$context){
$oldname = $t->name;
$t->name = $name;
taxonomy_term_save($t);
$cont= array('term',$t->tid,'name');
i18n_string_textgroup('taxonomy')->update_translation($cont, 'fr', $oldname);
$context['message'][] = $oldname .' -> '. $name;
$_SESSION['http_request_count']++;
}
function materio_taxonomy_fr2en_batch_finished($success, $results, $operations){
if($success){
drupal_set_message('All terms converted');
}
}