diff --git a/time_entry.install b/time_entry.install index 4868a3956a314f9b5dae604ee308c33c8f2980d4..5b4d30eb96347e454bb905f0785e61722e0066cd 100644 --- a/time_entry.install +++ b/time_entry.install @@ -215,3 +215,37 @@ function time_entry_update_7100() { db_create_table('time_entry_revision', $time_entry_revision); } } + +/** + * Create revisions for each stored time entry. + */ +function time_entry_update_7105(&$sandbox) { + if (!isset($sandbox['progress'])) { + $sandbox['progress'] = 0; + $sandbox['current_id'] = 0; + $sandbox['max'] = db_query('SELECT COUNT(DISTINCT id) FROM {time_entry} WHERE vid=0')->fetchField(); + } + + $time_entries = db_select('time_entry', 't') + ->fields('t', array('id', 'time', 'duration', 'type', 'vid')) + ->condition('id', $sandbox['current_id'], '>') + ->condition('t.vid', 0, '=') + ->range(0, 3) + ->orderBy('id', 'ASC') + ->execute(); + + foreach ($time_entries as $time_entry) { + // Lazy mode: Since this is a new table, I'm sure that id is available as vid. + $time_entry->vid = $time_entry->id; + + drupal_write_record('time_entry', $time_entry, 'id'); + drupal_write_record('time_entry_revision', $time_entry); + + $sandbox['progress']++; + $sandbox['current_id'] = $time_entry->id; + } + + $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); + + return t('Created revisions for each stored time entry.'); +}