You are here

function tmgmt_update_7004 in Translation Management Tool 7

Replace the [#translation][#finished] attribute with [#status].

File

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

Code

function tmgmt_update_7004(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['last_tjiid'] = 0;
    $sandbox['max'] = db_query('SELECT COUNT(tjiid) FROM {tmgmt_job_item}')
      ->fetchField();
  }
  $result = db_query('SELECT tjiid, data FROM {tmgmt_job_item} WHERE tjiid > :last_tjiid ORDER BY tjiid LIMIT 10', array(
    ':last_tjiid' => $sandbox['last_tjiid'],
  ));
  foreach ($result as $row) {
    if (!empty($row->data)) {
      $data = unserialize($row->data);
      $flattened_data = array_filter(tmgmt_flatten_data($data), '_tmgmt_filter_data');

      // Loop over data, find finished translations, remove the flag and set
      // the status instead.
      foreach ($flattened_data as $key => $values) {
        if (!empty($values['#translation']['#finished'])) {
          $finished = $values['#translation']['#finished'];
          unset($values['#translation']['#finished']);
          drupal_array_set_nested_value($data, array_merge($key, array(
            '#translation',
          )), $values['#translation']);
          if ($finished && (empty($values['#status']) || $values['#status'] == TMGMT_DATA_ITEM_STATE_PENDING)) {
            drupal_array_set_nested_value($data, array_merge($key, array(
              '#status',
            )), TMGMT_DATA_ITEM_STATE_TRANSLATED);
          }

          // Save the updated data structure.
          db_update('tmgmt_job_item')
            ->condition('tjiid', $row->tjiid)
            ->fields(array(
            'data' => serialize($data),
          ))
            ->execute();
        }
      }
    }
    $sandbox['progress']++;
  }
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($row) {
    $sandbox['last_tjiid'] = $row->tjiid;
  }
}