link.install 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * @file
  4. * Install file for the link module.
  5. */
  6. /**
  7. * Upgrade notes:
  8. * Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:
  9. */
  10. /**
  11. * Implements hook_field_schema().
  12. */
  13. function link_field_schema($field) {
  14. return array(
  15. 'columns' => array(
  16. 'url' => array(
  17. 'type' => 'varchar',
  18. // Maximum URLs length.
  19. 'length' => 2048,
  20. 'not null' => FALSE,
  21. 'sortable' => TRUE,
  22. ),
  23. 'title' => array(
  24. 'type' => 'varchar',
  25. 'length' => 255,
  26. 'not null' => FALSE,
  27. 'sortable' => TRUE,
  28. ),
  29. 'attributes' => array(
  30. 'type' => 'text',
  31. 'size' => 'medium',
  32. 'not null' => FALSE,
  33. ),
  34. ),
  35. );
  36. }
  37. /**
  38. * Implements hook_update_last_removed().
  39. */
  40. function link_update_last_removed() {
  41. return 6001;
  42. }
  43. /**
  44. * Handles moving settings data from field_config.data to field_config_instance.data.
  45. */
  46. function link_update_7000() {
  47. // For each field that is a link field, we need to copy the settings from the general field level down to the instance.
  48. //$field_data = array();
  49. $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
  50. foreach ($result as $field) {
  51. $field_id = $field->id;
  52. $name = $field->field_name;
  53. $field_data = unserialize($field->data);
  54. $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field_id));
  55. foreach ($instances as $instance) {
  56. // If this field has been updated already, we want to skip it.
  57. $instance_data = unserialize($instance->data);
  58. $update_instance = FALSE;
  59. if (!isset($instance_data['settings']['title'])) {
  60. foreach ($field_data['settings'] as $key => $value) {
  61. if (!isset($instance_data['settings'][$key])) {
  62. $instance_data['settings'][$key] = $value;
  63. $update_instance = TRUE;
  64. }
  65. }
  66. if ($update_instance) {
  67. // update the database.
  68. $num_updated = db_update('field_config_instance')
  69. ->fields(array('data' => serialize($instance_data)))
  70. ->condition('id', $instance->id)
  71. ->execute();
  72. }
  73. }
  74. }
  75. }
  76. return t("Instance settings have been set with the data from the field settings.");
  77. }
  78. /**
  79. * Renames all displays from foobar to link_foobar
  80. */
  81. function link_update_7001() {
  82. // Update the display type for each link field type.
  83. $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
  84. foreach ($result as $field) {
  85. $field_id = $field->id;
  86. $name = $field->field_name;
  87. $field_data = unserialize($field->data);
  88. $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field_id));
  89. foreach ($instances as $instance) {
  90. // If this field has been updated already, we want to skip it.
  91. $instance_data = unserialize($instance->data);
  92. $update_instance = FALSE;
  93. foreach ($instance_data['display'] as $display_name => $display_data) {
  94. if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
  95. $instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
  96. $update_instance = TRUE;
  97. }
  98. }
  99. if ($update_instance) {
  100. db_update('field_config_instance')
  101. ->fields(array('data' => serialize($instance_data)))
  102. ->condition('id', $instance->id)
  103. ->execute();
  104. }
  105. }
  106. }
  107. }