function pmtask_update_7103 in Drupal PM (Project Management) 7
Add date field to PM Task.
File
- pmtask/
pmtask.install, line 291 - Install, disable, uninstall and update functions for pmtask module.
Code
function pmtask_update_7103() {
// 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' => 'pmtask',
));
// Migrate data
$query = db_select('pmtask', 'pmta');
$query
->join('node', 'n', 'n.vid = pmta.vid');
$result = $query
->fields('pmta', array(
'nid',
'vid',
'datebegin',
'dateend',
))
->execute();
foreach ($result as $record) {
$node = node_load($record->nid);
$node->pm_date[LANGUAGE_NONE][0]['value'] = date('Y-m-d H:i:s', $record->datebegin);
$node->pm_date[LANGUAGE_NONE][0]['value2'] = date('Y-m-d H:i:s', $record->dateend);
field_attach_presave('node', $node);
field_attach_update('node', $node);
}
// Delete columns from existing database table.
db_drop_field('pmtask', 'datebegin');
db_drop_field('pmtask', 'dateend');
}