4 * Implements hook_install().
6 function time_entry_install() {
7 if (!drupal_installation_attempted()) {
8 $type = entity_create('time_entry_type', array(
10 'label' => t('Default'),
19 * Implements hook_enable().
21 function time_entry_enable() {
22 if(db_table_exists('time_entry_type') == FALSE
) {
23 drupal_install_schema('time_entry');
28 * Implements hook_schema().
30 function time_entry_schema() {
31 $schema['time_entry'] = array(
36 'description' => 'Internal identifier for time entry.',
42 'description' => 'The version id.',
45 'description' => 'Base time represented as Unix timestamp (on UTC).',
51 'description' => 'Time entry duration, in seconds.',
57 'description' => 'Type of this time entry.',
64 'primary key' => array('id'),
67 $schema['time_entry_revision'] = array(
73 'description' => 'The {time_entry} this version belongs to.',
76 'description' => 'The primary identifier for this version.',
82 'description' => 'Base time represented as Unix timestamp (on UTC).',
88 'description' => 'Time entry duration, in seconds.',
94 'description' => 'Type of this time entry.',
101 'primary key' => array('vid'),
104 $schema['time_entry_type'] = array(
105 'description' => 'Stores information about all defined time entry types.',
110 'description' => 'Primary Key: Unique profile type ID.',
113 'description' => 'The machine-readable name of this profile type.',
119 'description' => 'The human-readable name of this profile type.',
130 'description' => 'The weight of this profile type in relation to others.',
137 'description' => 'A serialized array of additional data related to this profile type.',
142 // Set the default to ENTITY_CUSTOM without using the constant as it is
143 // not safe to use it at this point.
146 'description' => 'The exportable status of the entity.',
149 'description' => 'The name of the providing module if the entity has been defined in code.',
155 'primary key' => array('id'),
156 'unique keys' => array(
157 'type' => array('type'),
165 * Create revision database structure.
167 function time_entry_update_7100() {
168 if (!db_field_exists('time_entry', 'vid')) {
173 'description' => 'The version id.',
176 db_add_field('time_entry', 'vid', $vid);
178 if (!db_table_exists('time_entry_revision')) {
179 $time_entry_revision = array(
185 'description' => 'The {time_entry} this version belongs to.',
188 'description' => 'The primary identifier for this version.',
194 'description' => 'Base time represented as Unix timestamp (on UTC).',
200 'description' => 'Time entry duration, in seconds.',
206 'description' => 'Type of this time entry.',
213 'primary key' => array('vid'),
215 db_create_table('time_entry_revision', $time_entry_revision);
220 * Create revisions for each stored time entry.
222 function time_entry_update_7105(&$sandbox) {
223 if (!isset($sandbox['progress'])) {
224 $sandbox['progress'] = 0;
225 $sandbox['current_id'] = 0;
226 $sandbox['max'] = db_query('SELECT COUNT(DISTINCT id) FROM {time_entry} WHERE vid=0')->fetchField();
229 $time_entries = db_select('time_entry', 't')
230 ->fields('t', array('id', 'time', 'duration', 'type', 'vid'))
231 ->condition('id', $sandbox['current_id'], '>')
232 ->condition('t.vid', 0, '=')
234 ->orderBy('id', 'ASC')
237 foreach ($time_entries as
$time_entry) {
238 // Lazy mode: Since this is a new table, I'm sure that id is available as vid.
239 $time_entry->vid
= $time_entry->id
;
241 drupal_write_record('time_entry', $time_entry, 'id');
242 drupal_write_record('time_entry_revision', $time_entry);
244 $sandbox['progress']++;
245 $sandbox['current_id'] = $time_entry->id
;
248 $sandbox['#finished'] = empty($sandbox['max']) ?
1 : ($sandbox['progress'] / $sandbox['max']);
250 return t('Created revisions for each stored time entry.');