function tmgmt_update_7003 in Translation Management Tool 7
Set counters for existing job items.
File
- ./
tmgmt.install, line 529 - Installation hooks for the Translation Management module.
Code
function tmgmt_update_7003(&$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(
'count_approved' => 0,
'count_translated' => 0,
'count_pending' => 0,
);
$data = unserialize($row->data);
_tmgmt_data_count_7003($data, $fake_job_item);
$fields = (array) $fake_job_item + array(
'data' => serialize($data),
);
db_update('tmgmt_job_item')
->condition('tjiid', $row->tjiid)
->fields($fields)
->execute();
}
$sandbox['progress']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
if ($row) {
$sandbox['last_tjiid'] = $row->tjiid;
}
}