You are here

function tmgmt_update_7000 in Translation Management Tool 7

Merge the content of the 'translation' field into the 'data' field.

File

./tmgmt.install, line 410
Installation hooks for the Translation Management module.

Code

function tmgmt_update_7000(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['max'] = db_query('SELECT COUNT(*) FROM {tmgmt_job_item}')
      ->fetchField();
  }
  $results = db_select('tmgmt_job_item', 'tji')
    ->fields('tji', array(
    'tjiid',
    'data',
    'translation',
  ))
    ->range($sandbox['progress'], 50)
    ->orderBy('tjiid', 'ASC')
    ->execute();
  foreach ($results as $item) {
    $data = unserialize($item->data);
    if (!empty($item->translation)) {
      foreach (tmgmt_flatten_data(unserialize($item->translation)) as $key => $translation) {
        if (!empty($item->data)) {
          $key = explode('][', $key);
          drupal_array_set_nested_value($data, array_merge($key, array(
            '#translation',
          )), $translation);
        }
      }
      db_update('tmgmt_job_item')
        ->condition('tjiid', $item->tjiid)
        ->fields(array(
        'data' => serialize($data),
      ))
        ->execute();
    }
    $sandbox['progress']++;
  }
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
}