You are here

function tmgmt_update_7006 in Translation Management Tool 7

Set word count for existing job items.

File

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

Code

function tmgmt_update_7006(&$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) {

    // Unseralize data, count it and then save the counters.
    if (!empty($row->data)) {
      $fake_job_item = (object) array(
        'word_count' => 0,
      );
      _tmgmt_data_count_7006(unserialize($row->data), $fake_job_item);
      db_update('tmgmt_job_item')
        ->condition('tjiid', $row->tjiid)
        ->fields((array) $fake_job_item)
        ->execute();
    }
    $sandbox['progress']++;
  }
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($row) {
    $sandbox['last_tjiid'] = $row->tjiid;
  }
}