summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanillo Nunes2012-12-17 23:57:43 (GMT)
committer Danillo Nunes2012-12-17 23:58:08 (GMT)
commit48e8931411fb33741add37402052bd04a5e55907 (patch)
tree8c281aebb5a058382f41f710f3a564e478c3bc3d
parent933f8b7951643e04927d99b275e51e61fc844c90 (diff)
Create revisions for each stored time entry
-rw-r--r--time_entry.install34
1 files changed, 34 insertions, 0 deletions
diff --git a/time_entry.install b/time_entry.install
index 4868a39..5b4d30e 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.');
+}