'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'); }