7100, ); $dependencies['os_profiles'][7048] = array( 'uw_virtual_site_homepage' => 7100, ); $dependencies['os_profiles'][7049] = array( 'uw_virtual_site_homepage' => 7100, ); $dependencies['os_profiles'][7050] = array( 'uw_virtual_site_homepage' => 7100, ); $dependencies['os_profiles'][7051] = array( 'uw_virtual_site_homepage' => 7100, ); $dependencies['os_profiles'][7052] = array( 'uw_virtual_site_homepage' => 7100, ); return $dependencies; } /** * Implements hook_update_N(). * * Changing Office Hours field name and instance for virtual homepages. */ function uw_virtual_site_homepage_update_7100() { // There is a conflict with os_profiles and uw_virtual_site_homepage for the field: field_office_hours. // We are going to change our custom module: uw_virtual_site_homepage, to use a field with name: field_uw_office_hours. // New field and instances will have to be created, all content migrated, all old instances removed. // Set variables, changing the below fields for uw homepage virtual sites. // Profile image, Site description, Faculty, Office location, Phone number, Extension, Email and Office hours. $entity_type = 'node'; $bundle = 'uw_virtual_site_homepage'; $old_names = array( 'field_faculty', 'field_office_location', 'field_phone_number', 'field_extension', 'field_email_homepage', 'field_office_hours', 'field_profile_image', 'body', ); // Step through each of the old names and convert to new names. foreach ($old_names as $old_name) { // If this is the body, special new name, else insert uw into old field name. if ($old_name == 'body') { $new_name = 'field_uw_site_description'; } else { $new_name = str_replace("field", "field_uw", $old_name); } // Get old fields' data. $field_data = db_select('field_data_' . $old_name, 'old') ->fields('old') ->condition('entity_type', $entity_type) ->condition('bundle', $bundle) ->execute(); // Store old fields data. $counter = 0; $data_new = array(); while ($data = $field_data->fetchAssoc()) { foreach ($data as $column => $value) { $column = str_replace($old_name, $new_name, $column); $data_new[$counter][$column] = $value; } $counter++; } // Get old fields' revisions. $field_revision = db_select('field_revision_' . $old_name, 'old') ->fields('old') ->condition('entity_type', $entity_type) ->condition('bundle', $bundle) ->execute(); // Store old fields' revisions. $counter = 0; $revision_new = array(); while ($revision = $field_revision->fetchAssoc()) { foreach ($revision as $column => $value) { $column = str_replace($old_name, $new_name, $column); $revision_new[$counter][$column] = $value; } $counter++; } // As long as not body, delete the old field. if ($old_name !== 'body') { field_delete_field($old_name); } // If there is no new field, create the new field. if (!db_table_exists('field_data_' . $new_name)) { $new_field = _get_new_field($new_name); field_create_field($new_field); } // Get the old instance. $check_old_instance = db_select('field_config_instance', 'fc') ->fields('fc') ->condition('field_name', $old_name) ->condition('entity_type', $entity_type) ->condition('bundle', $bundle) ->execute()->fetchAll(); // If there is an old instance, delete it. if (count($check_old_instance) > 0) { $instance['field_name'] = $old_name; $instance['entity_type'] = $entity_type; $instance['bundle'] = $bundle; field_delete_instance($instance); } // Step through each of the old fields data and set it to the new fields data. foreach ($data_new as $data) { // If there is a new field, insert the old data. if (db_table_exists('field_data_' . $new_name)) { // Get the data from the new field. $check_for_field = db_select('field_data_' . $new_name, 'data') ->fields('data'); foreach ($data as $key => $value) { $check_for_field->condition($key, $value); } $results = $check_for_field->execute(); // Check if there is data from the old field in the new field. $insert = TRUE; while ($record = $results->fetchAssoc()) { $insert = FALSE; break; } // If there is no data from old field in new field, insert the old field data into the new field. if ($insert) { db_insert('field_data_' . $new_name) ->fields($data) ->execute(); } } } // Step through each old revision and set it to the new revision. foreach ($revision_new as $revision) { // If there is a new revision, insert the old revision. if (db_table_exists('field_revision_' . $new_name)) { // Get the data from the new revision. $check_for_revision = db_select('field_revision_' . $new_name, 'data') ->fields('data'); foreach ($revision as $key => $value) { $check_for_field->condition($key, $value); } $results = $check_for_field->execute(); // Check if there is data from the old revision in the new revision. $insert = TRUE; if ($record = $results->fetchAssoc()) { $insert = FALSE; break; } // If there is no old revision in the new revision, insert the old revision in the new revision. if ($insert) { db_insert('field_revision_' . $new_name) ->fields($revision) ->execute(); } } } } // Perform feature revert to place new instances of fields. 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') ->condition('bundle', 'uw_virtual_site_homepage', '=') ->execute() ->fetchAll(); foreach ($result as $item) { $faculty_value = _get_faculty_list_value($item->field_uw_faculty_value); $data = array( 'entity_type' => 'node', 'bundle' => 'uw_virtual_site_homepage', 'deleted' => 0, 'entity_id' => $item->entity_id, 'revision_id' => $item->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') ->condition('bundle', 'uw_virtual_site_homepage', '=') ->execute() ->fetchAll(); foreach ($result2 as $item2) { $faculty_value2 = _get_faculty_list_value($item2->field_uw_faculty_value); $data2 = array( 'entity_type' => 'node', 'bundle' => 'uw_virtual_site_homepage', 'deleted' => 0, 'entity_id' => $item2->entity_id, 'revision_id' => $item2->revision_id, 'language' => 'und', 'delta' => 0, 'field_uw_faculty_list_value' => $faculty_value2, ); drupal_write_record('field_revision_field_uw_faculty_list', $data2); } } 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'); } } /** * Implements hook_update_N(). * * Perform feature revert. */ function uw_virtual_site_homepage_update_7102() { // Perform feature revert to place new instances of fields. features_revert_module('uw_virtual_site_homepage'); } /** * Implements hook_update_N(). * * Perform feature revert. */ function uw_virtual_site_homepage_update_7103() { // Perform feature revert to place new instances of fields. features_revert_module('uw_virtual_site_homepage'); } /** * Implements hook_update_N(). * * Update to use site footer logos from brand site. */ function uw_virtual_site_homepage_update_7104() { // Set defaults for api variables. variable_set('uw_site_footer_api_version', '1.0'); variable_set('uw_site_footer_api_server', 'uwaterloo.ca'); variable_set('uw_site_footer_api_site', 'brand'); variable_set('uw_site_footer_ignore_certificates', 0); // Update the facilty logo list field to not used previous keys // and allowed values function. $field_name = 'field_uw_faculty_list_logo'; $field_definition = db_query("SELECT id, data FROM field_config WHERE field_name = :field_name LIMIT 1", array(':field_name' => $field_name))->fetchAll(); $data = unserialize($field_definition[0]->data); $data['settings']['allowed_values'] = []; $data['settings']['allowed_values_function'] = '_uw_virtual_site_homepage_site_footer_allowed_values'; db_update('field_config') ->condition('field_name', $field_name) ->fields(['data' => serialize($data)]) ->execute(); // Get the nodes that are site footers. $nodes = node_load_multiple(array(), array('type' => 'uw_virtual_site_homepage')); foreach ($nodes as $node) { if (isset($node->field_uw_faculty_list_logo) && !empty($node->field_uw_faculty_list_logo)) { $node->field_uw_faculty_list_logo = [ 'und' => [ '0' => [ 'value' => _uw_virtual_site_homepage_get_logo_name($node->field_uw_faculty_list_logo['und'][0]['value']), ], ], ]; node_save($node); } } } /** * Helper function. * * Return the name of the site footer logo, given the key. */ function _uw_virtual_site_homepage_get_logo_name($logo_key = NULL, $with_nids = FALSE) { // If there is no key, return. if (!$logo_key) { return; } // The array that stores all the old information about the logos. $logos = array( 'UWaterloo_logo' => $with_nids ? 356 : 'University of Waterloo', 'UWaterloo_Applied_Health_Sciences' => $with_nids ? 366 : 'Applied Health Sciences', 'UWaterloo_Applied_Health_Sciences_Kinesiology' => $with_nids ? 320 : 'Applied Health Sciences - Kinesiology', 'UWaterloo_Applied_Health_Sciences_PublicHealth' => $with_nids ? 319 : 'Applied Health Sciences - Public Health', 'UWaterloo_Applied_Health_Sciences_Recreation_Lesiure' => $with_nids ? 321 : 'Applied Health Sciences - Recreation and Leisure Studies', 'UWaterloo_Arts' => $with_nids ? 365 : 'Arts', 'UWaterloo_Arts_Anthropology' => $with_nids ? 322 : 'Arts - Anthropology', 'UWaterloo_Arts_Classical_Studies' => $with_nids ? 323 : 'Arts - Classical Studies', 'UWaterloo_Arts_Communication_Arts' => $with_nids ? 324 : 'Arts - Communication_Arts', 'UWaterloo_Arts_Economics' => $with_nids ? 325 : 'Arts - Economics', 'UWaterloo_Arts_English_Language_Literature' => $with_nids ? 326 : 'Arts - English Language Literature', 'UWaterloo_Arts_FineArts' => $with_nids ? 327 : 'Arts - Fine Arts', 'UWaterloo_Arts_French' => $with_nids ? 328 : 'Arts - French', 'UWaterloo_Arts_Germanic_Slavic_Studies' => $with_nids ? 330 : 'Arts - Germanic Slavic Studies', 'UWaterloo_Arts_History' => $with_nids ? 331 : 'Arts - History', 'UWaterloo_Arts_Philosophy' => $with_nids ? 344 : 'Arts - Philosophy', 'UWaterloo_Arts_Political_Science' => $with_nids ? 345 : 'Arts - Political Science', 'UWaterloo_Arts_Psychology' => $with_nids ? 346 : 'Arts - Psychology', 'UWaterloo_Arts_Religious_Studies' => $with_nids ? 348 : 'Arts - Religious Studies', 'UWaterloo_Arts_School_of_Accounting_and_Finance' => $with_nids ? 378 : 'Arts - School of Accounting and Finance', 'UWaterloo_Arts_Sociology_and_Legal_Studies' => $with_nids ? 354 : 'Arts - Sociology and Legal Studies', 'UWaterloo_Arts_Spanish_and_Latin_American_Studies' => $with_nids ? 355 : 'Arts - Spanish and Latin American Studies', 'UWaterloo_Engineering' => $with_nids ? 368 : 'Engineering', 'UWaterloo_Engineering_wordmark' => $with_nids ? 360 : 'Engineering wordmark', 'UWaterloo_Engineering_Architecture' => $with_nids ? 377 : 'Engineering - Architecture', 'UWaterloo_Engineering_Chemical_Engineering' => $with_nids ? 334 : 'Engineering - Chemical Engineering', 'UWaterloo_Engineering_Civil_Environmental_Engineering' => $with_nids ? 336 : 'Engineering - Civil Environmental Engineering', 'UWaterloo_Engineering_Electrical_Computer_Engineering' => $with_nids ? 340 : 'Engineering - Electrical Computer Engineering', 'UWaterloo_Engineering_Management_Sciences' => $with_nids ? 342 : 'Engineering - Management Sciences', 'UWaterloo_Engineering_Mechanical_Engineering' => $with_nids ? 343 : 'Engineering - Mechanical Engineering', 'UWaterloo_Engineering_Systems_Design_Engineering' => $with_nids ? 358 : 'Engineering - Systems Design Engineering', 'UWaterloo_Environment' => $with_nids ? 367 : 'Environment', 'UWaterloo_Environment_50th_Anniversary' => $with_nids ? 403 : 'Environment - 50th Anniversary', 'UWaterloo_Environment_Environment_Enterprise_Development' => $with_nids ? 376 : 'Environment - Environment Enterprise Development', 'UWaterloo_Environment_Enviromental_Resources_and_Sustainability' => $with_nids ? 375 : 'Environment - Enviromental Resources and Sustainability', 'UWaterloo_Environment_Geography_Environmental_and_Management' => $with_nids ? 329 : 'Environment - Geography Environmental and Management', 'UWaterloo_Environment_Knowledge_Intergration' => $with_nids ? 341 : 'Environment - Knowledge Intergration', 'UWaterloo_Environment_Planning' => $with_nids ? 372 : 'Environment - Planning', 'UWaterloo_Mathematics' => $with_nids ? 369 : 'Mathematics', 'UWaterloo_Math_Applied_Math' => $with_nids ? 332 : 'Mathematics - Applied Math', 'UWaterloo_Math_Combinatorics_and_Optimization' => $with_nids ? 338 : 'Mathematics - Combinatorics and Optimization', 'UWaterloo_Math_Computer_Science' => $with_nids ? 379 : 'Mathematics - Computer Science', 'UWaterloo_Math_Pure_Math' => $with_nids ? 347 : 'Mathematics - Pure Math', 'UWaterloo_Math_Statistics_Actuarial_Science' => $with_nids ? 357 : 'Mathematics - Statistics Actuarial Science', 'UWaterloo_Science' => $with_nids ? 370 : 'Science', 'UWaterloo_Science_Biology' => $with_nids ? 333 : 'Science - Biology', 'UWaterloo_Science_Chemistry' => $with_nids ? 335 : 'Science - Chemistry', 'UWaterloo_Science_Earth_and_Environmental_Science' => $with_nids ? 339 : 'Science - Earth and Environmental Science', 'UWaterloo_Science_Optometry_and_Vision_Science' => $with_nids ? 374 : 'Science - Optometry and Vision Science', 'UWaterloo_Sciecne_Pharmacy' => $with_nids ? 373 : 'Science - Pharmacy', 'UWaterloo_Science_Physics_and_Astronomy' => $with_nids ? 402 : 'Science - Physics and Astronomy', 'conrad_grebel' => $with_nids ? 389 : 'Conrad Grebel', 'renison_university_college' => $with_nids ? 391 : 'Renison University College', 'st_jeromes_university' => $with_nids ? 392 : 'St. Jerome\'s University', 'st_pauls' => $with_nids ? 393 : 'St. Paul\'s University College', 'McMaster_University' => $with_nids ? 390 : 'McMaster University', 'Print_and_Retail_Solutions' => $with_nids ? 364 : 'Print and Retail Solutions', 'Survey_Research_Centre' => $with_nids ? 394 : 'Survey Research Centre', 'Sustainable_Development_Solutions_Network_(SDSN)_Canada' => $with_nids ? 395 : 'Sustainable Development Solutions Network (SDSN) Canada', 'University_of_Guelph' => $with_nids ? 396 : 'University of Guelph', 'Waterloo_Centre_for_Microbial_Research' => $with_nids ? 398 : 'Waterloo Centre for Microbial Research', 'Waterloo_Institute_for_Complexity_and_Innovation' => $with_nids ? 399 : 'Waterloo Institute for Complexity and Innovation', 'Water_Institute' => $with_nids ? 397 : 'Water Institute', 'Western_University' => $with_nids ? 400 : 'Western University', 'Wilfrid_Laurier_University' => $with_nids ? 401 : 'Wilfrid Laurier University', 'UWaterloo_Arts_Stratford_School_Interaction_Design_Business' => $with_nids ? 371 : 'Arts - Stratford School of Interaction Design and Business', 'UWaterloo_Engineering_Conrad_School_of_Entrepreneurship_and_Business' => $with_nids ? 380 : 'Conrad School of Entrepreneurship and Business', ); // If there is a logo with the key return it, // if there is not logo simply return. if (isset($logos[$logo_key])) { return $logos[$logo_key]; } else { return; } } /** * 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, 'university of waterloo') !== FALSE) { $faculty_list_value = 'default'; } if (strpos($faculty_name, 'faculty of applied health sciences') !== FALSE) { $faculty_list_value = 'ahs'; } if (strpos($faculty_name, 'faculty of arts') !== FALSE || strpos($faculty_name, 'arts') !== FALSE) { $faculty_list_value = 'arts'; } if (strpos($faculty_name, 'faculty of engineering') !== FALSE || strpos($faculty_name, 'engineering') !== FALSE) { $faculty_list_value = 'engineering'; } if (strpos($faculty_name, 'faculty of environment') !== FALSE) { $faculty_list_value = 'environment'; } if (strpos($faculty_name, 'faculty of mathematics') !== FALSE || strpos($faculty_name, 'mathematics') !== FALSE) { $faculty_list_value = 'math'; } if (strpos($faculty_name, 'faculty of science') !== FALSE) { $faculty_list_value = 'science'; } if (strpos($faculty_name, 'conrad grebel university college') !== FALSE) { $faculty_list_value = 'cgc'; } if (strpos($faculty_name, 'renison university college') !== FALSE) { $faculty_list_value = 'ren'; } if (strpos($faculty_name, 'st. jerome') !== FALSE) { $faculty_list_value = 'stj'; } if (strpos($faculty_name, 'st. paul') !== FALSE) { $faculty_list_value = 'stp'; } return $faculty_list_value; } /** * Helper function to get the new field information. */ function _get_new_field($name) { switch ($name) { case "field_uw_email_homepage": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array(), 'field_name' => 'field_uw_email_homepage', 'foreign keys' => array( 'format' => array( 'columns' => array( 'format' => 'format', ), 'table' => 'filter_format', ), ), 'indexes' => array( 'format' => array( 0 => 'format', ), ), 'locked' => 0, 'module' => 'text', 'settings' => array( 'max_length' => 255, ), 'translatable' => 0, 'type' => 'text', ); return $new_field; case "field_uw_email_homepage": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array(), 'field_name' => 'field_uw_email_homepage', 'foreign keys' => array( 'format' => array( 'columns' => array( 'format' => 'format', ), 'table' => 'filter_format', ), ), 'indexes' => array( 'format' => array( 0 => 'format', ), ), 'locked' => 0, 'module' => 'text', 'settings' => array( 'max_length' => 255, ), 'translatable' => 0, 'type' => 'text', ); return $new_field; case "field_uw_extension": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array(), 'field_name' => 'field_uw_extension', 'foreign keys' => array( 'format' => array( 'columns' => array( 'format' => 'format', ), 'table' => 'filter_format', ), ), 'indexes' => array( 'format' => array( 0 => 'format', ), ), 'locked' => 0, 'module' => 'text', 'settings' => array( 'max_length' => 255, ), 'translatable' => 0, 'type' => 'text', ); return $new_field; case "field_uw_faculty": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array(), 'field_name' => 'field_uw_faculty', 'foreign keys' => array( 'format' => array( 'columns' => array( 'format' => 'format', ), 'table' => 'filter_format', ), ), 'indexes' => array( 'format' => array( 0 => 'format', ), ), 'locked' => 0, 'module' => 'text', 'settings' => array( 'max_length' => 255, ), 'translatable' => 0, 'type' => 'text', ); return $new_field; case "field_uw_office_hours": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array(), 'field_name' => 'field_uw_office_hours', 'foreign keys' => array( 'format' => array( 'columns' => array( 'format' => 'format', ), 'table' => 'filter_format', ), ), 'indexes' => array( 'format' => array( 0 => 'format', ), ), 'locked' => 0, 'module' => 'text', 'settings' => array(), 'translatable' => 0, 'type' => 'text_long', ); return $new_field; case "field_uw_office_location": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array(), 'field_name' => 'field_uw_office_location', 'foreign keys' => array( 'format' => array( 'columns' => array( 'format' => 'format', ), 'table' => 'filter_format', ), ), 'indexes' => array( 'format' => array( 0 => 'format', ), ), 'locked' => 0, 'module' => 'text', 'settings' => array( 'max_length' => 255, ), 'translatable' => 0, 'type' => 'text', ); return $new_field; case "field_uw_phone_number": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array(), 'field_name' => 'field_uw_phone_number', 'foreign keys' => array( 'format' => array( 'columns' => array( 'format' => 'format', ), 'table' => 'filter_format', ), ), 'indexes' => array( 'format' => array( 0 => 'format', ), ), 'locked' => 0, 'module' => 'text', 'settings' => array( 'max_length' => 255, ), 'translatable' => 0, 'type' => 'text', ); return $new_field; case "field_uw_profile_image": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array(), 'field_name' => 'field_uw_profile_image', 'foreign keys' => array( 'fid' => array( 'columns' => array( 'fid' => 'fid', ), 'table' => 'file_managed', ), ), 'indexes' => array( 'fid' => array( 0 => 'fid', ), ), 'locked' => 0, 'module' => 'image', 'settings' => array( 'default_image' => 0, 'uri_scheme' => 'public', ), 'translatable' => 0, 'type' => 'image', ); return $new_field; case "field_uw_site_description": $new_field = array( 'active' => 1, 'cardinality' => 1, 'deleted' => 0, 'entity_types' => array( 0 => 'node', ), 'field_name' => 'field_uw_site_description', 'foreign keys' => array( 'format' => array( 'columns' => array( 'format' => 'format', ), 'table' => 'filter_format', ), ), 'indexes' => array( 'format' => array( 0 => 'format', ), ), 'locked' => 0, 'module' => 'text', 'settings' => array(), 'translatable' => 0, 'type' => 'text_with_summary', ); return $new_field; } }