12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- /**
- * Implementation of hook_drush_command().
- */
- function entity_translation_create_drush_command() {
- $items['create-translations'] = array(
- 'description' => 'Create translations.',
- 'arguments' => array(
- 'bundle' => 'Bundle (like node type)',
- ),
- 'options' => array(
- 'limit' => 'limit.',
- ),
- 'aliases' => array('etcc'),
- );
- return $items;
- }
- /**
- * Command callback. Generate a number of users.
- */
- function drush_entity_translation_create_create_translations( $bundle = false) {
- if (!$bundle) {
- return drush_set_error(t('Invalid bundle.'));
- }
- $entity = 'node';
- $limit = 100; //drush_get_option('limit') ? drush_get_option('limit') : 0;
-
- drush_log(t('limit : @lim', array('@lim' => $limit)), 'notice');
- drush_log(t('Bundle : @bun', array('@bun' => $bundle)), 'notice');
- $query = db_select('entity_translation', 'et');
- $query->join('node', 'n', 'n.nid = et.entity_id');
- $query->fields('et');
-
- $query->condition('et.entity_type',$entity);
- $query->condition('et.source','');
- $query->condition('et.language','und', '<>');
- if($bundle){
- $query->condition('n.type',$bundle);
- }
- $entities = $query->execute();
- $num_translations = 0;
- $i = 0;
- foreach ($entities as $row) {
-
- $trans = db_select('entity_translation', 'et')
- ->fields('et')
- ->condition('et.entity_id',$row->entity_id)
- ->condition('et.entity_type',$entity)
- ->condition('et.source',$row->language)
- ->execute();
- $translations = 0;
- foreach ($trans as $t) {
- $translations++;
- }
- drush_log(t('count translations : @trans', array('@trans' => $translations)), 'notice');
- if(!$translations){
- $nid = db_insert('entity_translation') // Table name no longer needs {}
- ->fields(array(
- 'entity_id' => $row->entity_id,
- 'entity_type' => $row->entity_type,
- 'language' => $row->language == 'en' ? 'fr' : 'en',
- 'source' => $row->language,
- 'uid' => $row->uid,
- 'status' => $row->status,
- 'translate' => $row->translate,
- 'created' => $row->created,
- 'changed' => $row->changed,
- ))
- ->execute();
- $num_translations ++;
- }else{
- drush_log(t('Entity id : @id already have a translation', array('@id' => $row->entity_id)), 'notice');
- }
- }
- drush_log(t('Created @number translations', array('@number' => $num_translations)), 'success');
- }
|