Commit 344d81c8 authored by Lily Yan's avatar Lily Yan
Browse files

FDSU-1805 Convert old faculty field value to new faculty field and remove old faculty field.

parent 8cb5f6a1
......@@ -46,11 +46,11 @@ function uw_virtual_site_homepage_update_7100() {
$old_names = array(
'field_faculty',
'field_office_location',
'field_phone_number',
'field_extension',
'field_email_homepage',
'field_office_hours',
'field_office_location',
'field_phone_number',
'field_extension',
'field_email_homepage',
'field_office_hours',
'field_profile_image',
'body',
);
......@@ -194,6 +194,123 @@ function uw_virtual_site_homepage_update_7100() {
features_revert_module('uw_virtual_site_homepage');
}
/**
* Implements hook_update_N().
* Convert the value from field_uw_faculty to field_uw_faculty_list.
* Remove field_uw_faculty field.
*/
function uw_virtual_site_homepage_update_7101() {
// Revert fields
features_revert(array('uw_virtual_site_homepage' => array('field_base', 'field_instance')));
// Convert the value from field_data_field_uw_faculty table to field_data_field_uw_faculty_list table.
if (db_table_exists('field_data_field_uw_faculty') && db_table_exists('field_data_field_uw_faculty_list')) {
$result = db_select('field_data_field_uw_faculty', 'f')
->fields('f')
->execute()
->fetchAssoc();
$faculty = $result['field_uw_faculty_value'];
$faculty_value = _get_faculty_list_value($faculty);
$data = array(
'entity_type' => 'node',
'bundle' => 'uw_virtual_site_homepage',
'deleted' => 0,
'entity_id' => $result['entity_id'],
'revision_id' => $result['revision_id'],
'language' => 'und',
'delta' => 0,
'field_uw_faculty_list_value' => $faculty_value,
);
drupal_write_record('field_data_field_uw_faculty_list', $data);
}
// Convert the value from field_revision_field_uw_faculty to field_revision_field_uw_faculty_list.
if (db_table_exists('field_revision_field_uw_faculty') && db_table_exists('field_revision_field_uw_faculty_list')) {
$result2 = db_select('field_revision_field_uw_faculty', 'f')
->fields('f')
->execute()
->fetchAssoc();
$faculty2 = $result2['field_uw_faculty_value'];
$faculty_value2 = _get_faculty_list_value($faculty2);
$data = array(
'entity_type' => 'node',
'bundle' => 'uw_virtual_site_homepage',
'deleted' => 0,
'entity_id' => $result['entity_id'],
'revision_id' => $result['revision_id'],
'language' => 'und',
'delta' => 0,
'field_uw_faculty_list_value' => $faculty_value2,
);
drupal_write_record('field_revision_field_uw_faculty_list', $data);
}
drupal_set_message(t("Converted the value from the old faculty field to the new faculty field for the existing hompage setting node."));
// Delete or remove field_uw_faculty field from uw_virtual_site_homepage content type.
$field_uw_faculty = field_info_instance('node', 'field_uw_faculty', 'uw_virtual_site_homepage');
if (!empty($field_uw_faculty)) {
field_delete_field('field_uw_faculty');
drupal_set_message(t('field_uw_faculty field has been successfully removed.'), 'status');
}
}
/**
* Helper function to get the value from field_uw_faculty
*/
function _get_faculty_list_value($field_uw_faculty) {
$faculty_name = strtolower($field_uw_faculty);
if (strpos($faculty_name, 'waterloo') !== FALSE) {
$faculty_list_value = 'default';
}
if (strpos($faculty_name, 'applied') !== FALSE) {
$faculty_list_value = 'ahs';
}
if (strpos($faculty_name, 'arts') !== FALSE) {
$faculty_list_value = 'arts';
}
if (strpos($faculty_name, 'engineering') != FALSE) {
$faculty_list_value = 'engineering';
}
if (strpos($faculty_name, 'environment') != FALSE) {
$faculty_list_value = 'environment';
}
if (strpos($faculty_name, 'math') != FALSE) {
$faculty_list_value = 'math';
}
if (strpos($faculty_name, 'science') != FALSE) {
$faculty_list_value = 'science';
}
if (strpos($faculty_name, 'conrad') != FALSE || strpos($faculty_name, 'grebel') != FALSE) {
$faculty_list_value = 'cgc';
}
if (strpos($faculty_name, 'renison') != FALSE) {
$faculty_list_value = 'ren';
}
if (strpos($faculty_name, 'jerome') != FALSE) {
$faculty_list_value = 'stj';
}
if (strpos($faculty_name, 'paul') != FALSE) {
$faculty_list_value = 'stp';
}
return $faculty_list_value;
}
/**
* Helper function to get the new field information
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment