link.install 3.6 KB

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