function pmtimetracking_update_7105 in Drupal PM (Project Management) 7
Add date field to PM Timetracking.
File
- pmtimetracking/
pmtimetracking.install, line 263 - Install functions for PM Timetracking.
Code
function pmtimetracking_update_7105() {
// Create field instance.
field_create_instance(array(
'field_name' => 'pm_date',
'label' => 'Date',
'widget' => array(
'weight' => '-18',
'type' => 'date_text',
'module' => 'date',
'active' => 1,
'settings' => array(
'input_format' => 'm/d/Y - H:i:s',
'input_format_custom' => '',
'year_range' => '-3:+3',
'increment' => 15,
'label_position' => 'above',
'text_parts' => array(),
),
),
'settings' => array(
'default_value' => 'now',
'default_value_code' => '',
'default_value2' => 'same',
'default_value_code2' => '',
'user_register_form' => FALSE,
),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'date_default',
'settings' => array(
'format_type' => 'long',
'multiple_number' => '',
'multiple_from' => '',
'multiple_to' => '',
'fromto' => 'both',
),
'module' => 'date',
'weight' => 1,
),
'teaser' => array(
'type' => 'hidden',
'label' => 'above',
'settings' => array(),
'weight' => 0,
),
),
'required' => 0,
'entity_type' => 'node',
'bundle' => 'pmtimetracking',
));
// Migrate data
$query = db_select('pmtimetracking', 'pmtt');
$query
->join('node', 'n', 'n.vid = pmtt.vid');
$result = $query
->fields('pmtt', array(
'nid',
'vid',
'trackingdate',
'timebegin',
'timeend',
))
->execute();
foreach ($result as $record) {
$node = node_load($record->nid);
$datebegin = strtotime($record->timebegin, $record->trackingdate);
$dateend = strtotime($record->timeend, $record->trackingdate);
$node->pm_date[LANGUAGE_NONE][0]['value'] = date('Y-m-d H:i:s', $datebegin);
$node->pm_date[LANGUAGE_NONE][0]['value2'] = date('Y-m-d H:i:s', $dateend);
field_attach_presave('node', $node);
field_attach_update('node', $node);
}
// Delete columns from existing database table.
db_drop_field('pmtimetracking', 'trackingdate');
db_drop_field('pmtimetracking', 'timebegin');
db_drop_field('pmtimetracking', 'timeend');
}