who wants it? can we have it?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drzraf’s picture

Status: Active » Closed (duplicate)
meichr’s picture

Issue summary: View changes
Status: Closed (duplicate) » Needs review
FileSize
4.36 KB

So, this issue is marked as a duplicate to itself ;-) and I havn't found any other issue with the feature request of an entity_translation_upgrade drush extension. Therefore, I open this issue again and attached is a patch for a drush extension to upgrade nodes for entity translation.

Please be aware that another patch attached to the related issue #2307937-1: Batch API needs $context['results'] handled as an array, not a value has to be applied for the drush extension to work properly.

The drush extension 'drush entity-translation-upgrade [argument]' allows to upgrade nodes of one content type at a time by adding the content type machine name as the argument or by invoking the drush command 'drush etu' (alias) without an argument and selecting the content type out of a list.

Enjoy, and please kindly review.

meichr’s picture

Added related issue of a patch which is needed for the drush extension to work properly.

meichr’s picture

Related issue now correctly added.

joseph.olstad’s picture

very good script, used it myself to upgrade tens of thousands of nodes that would have otherwise timed out in the UI.

plach’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, thanks!

joseph.olstad’s picture

commit?

joseph.olstad’s picture

Performed yet another entity_translation upgrade using the above patch that provides the drush command drush entity-translation-upgrade.

FYI: here's our full upgrade steps and complementary scripts, field title, field trans, and node in the correct order.

See the scripts we used:

drush scr et_upgrade_article_node.php;#see php code below, contains code for this
drush scr enable_or_disable_field_translation.php --champ=field_location --action=enable;#see php code at bottom, contains code for this
drush scr enable_or_disable_field_translation.php --champ=field_subtitle --action=enable
drush scr enable_or_disable_field_translation.php --champ=field_image_caption --action=enable
drush entity-translation-upgrade article

et_upgrade_article_node.php
<?php

if (!module_exists('entity_translation_upgrade')) {
  drush_print('entity_translation_upgrade will be enabled, it is required for the batch upgrade of article content type');
  module_enable(array('entity_translation_upgrade'));
}
drush_print('****** DELETE UNWANTED DEPRECATED FIELDS PRIOR TO UPGRADE *********');
$result = db_query("SELECT distinct field_featured_images_fid FROM {field_data_field_featured_images} where bundle='article'");
foreach ($result as $row) {
  if ($img = file_load($row->field_featured_images_fid)) {
    $rc = file_delete($img, true);
    if ($rc !== true) {
      echo "Failed to delete " . $img->filename . "\n";
    }
  }
}

$result = db_query("SELECT distinct field_secondary_image_fid FROM {field_data_field_secondary_image} where bundle='article'");
foreach ($result as $row) {
  if ($img = file_load($row->field_secondary_image_fid)) {
    $rc = file_delete($img, true);
    if ($rc !== true) {
      echo "Failed to delete " . $img->filename . "\n";
    }
  }
}

drush_print('******* DELETE DEPRECATED article FIELDS ON NEWS ARTICLE CONTENT TYPE ******');

$field_instance = field_info_instances('node', 'article');
// Get the the value/instance of the field for the article bundle (in our case, article).
$instance = $field_instance['field_featured_images'];
// Delete the field instance of field_featured_images for the article bundle.
// This will also delete the field_featured_images field if the last instance/object
//of this field had been deleted. (however does not otherwise)
field_delete_instance($instance);
// also remove field_featured_description
$instance = $field_instance['field_featured_description'];
	   drush_print('delete field_featured_description');
field_delete_instance($instance);
$instance = $field_instance['field_featured_title'];
	   drush_print('delete field_featured_title');
field_delete_instance($instance);
$instance = $field_instance['field_secondary_image'];
	   drush_print('delete field_secondary_image');
field_delete_instance($instance);
$instance = $field_instance['field_featured_images'];
	   drush_print('delete field_featured_images');
field_delete_instance($instance);

drush_print('****** END IMPORTANT IMPROVEMENTS ******');

$entity_type = 'node';
$bundle = 'article';
$legacy_field = 'title';
if (function_exists('title_field_replacement_toggle')) {
  print_r('****************** begin title field upgrade for article node (News Article) *******************');
  drush_print('ça roule');
  if (title_field_replacement_toggle($entity_type, $bundle, $legacy_field)) {
	drupal_set_message(t('%field replaced with a field instance.', array('%field' => 'title')));
  }

$batch2 = array(
   'title' => t('Replacing field values for %field', array('%field' => $legacy_field)),
   'operations' => array(
		   array('title_field_replacement_batch', array($entity_type, $bundle, $legacy_field)),
		 /*array('title_field_replacement_batch', array($entity_type, 'mandate_letter', $legacy_field)),*/ //EXAMPLE you can do more than one content type in same batch
		 ),
   'finished' => 'title_field_replacement_batch_end',
   'init_message' => t('Title field replacement batch is starting.'),
   'error_message' => t('Title field batch has encountered an error.'),
   'file' => drupal_get_path('module', 'title') . '/title.module',
   );

  batch_set($batch2);
  $batch2 =& batch_get();
  watchdog('batch2_title_replace', '<pre>@print_r</pre>', array('@print_r' => print_r( $batch2, TRUE)));
  $batch2['progressive'] = FALSE;
  drush_backend_batch_process();
  //batch2 fin
  drush_print('batch2 terminé');
} else {
  drush_print("*** ERROR function title_field_replacement_toggle does not exist, where is title.module? is the 'title' module enabled? ***");
}

enable_or_disable_field_translation.php
<?php

$translatable=TRUE;
$field_name = drush_get_option('champ');
$action = drush_get_option('action');
if ($action == 'disable') {
  $translatable=TRUE;
} else {
  $translatable=FALSE;
}
if (empty($field_name) || empty($action) ) {
  drush_print('usage: drush scr enable_or_disable_field_translation.php --champ=field_image_small_ --action=enable');
  return;
}
$copy_all_languages=1;

if (!function_exists('entity_translation_translatable_batch')) {
  module_load_include('inc', 'entity_translation', 'entity_translation.admin');
} else {
  drush_print('entity_translation_translatable_batch existe sans module_load_include');
}
if (!function_exists('entity_translation_translatable_switch')) {
  drush_print('entity_translation_translatable_switch n`existe donc il va falloir executer ceci:');
  drush_print('module_load_include(\'inc\', \'entity_translation\', \'entity_translation.admin\');');
  module_load_include('inc', 'entity_translation', 'entity_translation.admin');
    if (function_exists('entity_translation_translatable_switch')) {
      drush_print('module_load_include réussit');
    }
}

$field = field_info_field($field_name);

  // If a field is untranslatable, it can have no data except under
  // LANGUAGE_NONE. Thus we need a field to be translatable before we convert
  // data to the entity language. Conversely we need to switch data back to
  // LANGUAGE_NONE before making a field untranslatable lest we lose
  // information.
if ($field['translatable'] !== $translatable) {
  $operations = array(
    array('entity_translation_translatable_batch', array(!$translatable, $field_name, $copy_all_languages)),
    array('entity_translation_translatable_switch', array(!$translatable, $field_name)),
  );
  $operations = $translatable ? $operations : array_reverse($operations);

  $t_args = array('%field' => $field_name);
  $title = !$translatable ? t('Enabling translation for the %field field', $t_args) : t('Disabling translation for the %field field', $t_args);

  $batch = array(
    'title' => $title,
    'operations' => $operations,
    'finished' => 'entity_translation_translatable_batch_done',
    'file' => drupal_get_path('module', 'entity_translation') . '/entity_translation.admin.inc',
  );

  batch_set($batch);
  $batch =& batch_get();
  watchdog('batch_enable_trans_' . $field_name, '<pre>@print_r</pre>', array('@print_r' => print_r( $batch, TRUE)));
  $batch['progressive'] = FALSE;
  drush_backend_batch_process();
  drush_print('batch terminé');
}
stefanos.petrakis@gmail.com’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for this, I will fix some small things (typos, code-styling, verb usage) on commit.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.