link.install 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @file
  4. * Install file for the link module.
  5. */
  6. /**
  7. * Upgrade notes.
  8. *
  9. * Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:.
  10. */
  11. /**
  12. * Implements hook_install().
  13. */
  14. function link_install() {
  15. // Notify the user they may want to install token.
  16. if (!module_exists('token')) {
  17. $t = get_t();
  18. drupal_set_message($t('If you install the <a href="!url" target="blank">Token</a>, static title can use any other entity field as its value.', array(
  19. '!url' => 'http://drupal.org/project/token',
  20. )));
  21. }
  22. }
  23. /**
  24. * Removes unused link_extra_domains variable.
  25. */
  26. function link_update_7002() {
  27. variable_del('link_extra_domains');
  28. }
  29. /**
  30. * Implements hook_uninstall().
  31. */
  32. function link_uninstall() {
  33. variable_del('link_allowed_domains');
  34. }
  35. /**
  36. * Implements hook_field_schema().
  37. */
  38. function link_field_schema($field) {
  39. return array(
  40. 'columns' => array(
  41. 'url' => array(
  42. 'type' => 'varchar',
  43. // Maximum URLs length.
  44. 'length' => 2048,
  45. 'not null' => FALSE,
  46. 'sortable' => TRUE,
  47. ),
  48. 'title' => array(
  49. 'type' => 'varchar',
  50. 'length' => 255,
  51. 'not null' => FALSE,
  52. 'sortable' => TRUE,
  53. ),
  54. 'attributes' => array(
  55. 'type' => 'text',
  56. 'size' => 'medium',
  57. 'not null' => FALSE,
  58. ),
  59. ),
  60. );
  61. }
  62. /**
  63. * Implements hook_update_last_removed().
  64. */
  65. function link_update_last_removed() {
  66. return 6001;
  67. }
  68. /**
  69. * Implements hook_update_N().
  70. *
  71. * Handles moving settings data from field_config.data to
  72. * field_config_instance.data.
  73. */
  74. function link_update_7000() {
  75. // For each field that is a link field, we need to copy the settings from the
  76. // general field level down to the instance.
  77. $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
  78. foreach ($result as $field) {
  79. $field_data = unserialize($field->data);
  80. $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
  81. foreach ($instances as $instance) {
  82. // If this field has been updated already, we want to skip it.
  83. $instance_data = unserialize($instance->data);
  84. $update_instance = FALSE;
  85. if (!isset($instance_data['settings']['title'])) {
  86. foreach ($field_data['settings'] as $key => $value) {
  87. if (!isset($instance_data['settings'][$key])) {
  88. $instance_data['settings'][$key] = $value;
  89. $update_instance = TRUE;
  90. }
  91. }
  92. if ($update_instance) {
  93. // Update the database.
  94. db_update('field_config_instance')
  95. ->fields(array('data' => serialize($instance_data)))
  96. ->condition('id', $instance->id)
  97. ->execute();
  98. }
  99. }
  100. }
  101. }
  102. return t("Instance settings have been set with the data from the field settings.");
  103. }
  104. /**
  105. * Renames all displays from foobar to link_foobar.
  106. */
  107. function link_update_7001() {
  108. // Update the display type for each link field type.
  109. $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
  110. foreach ($result as $field) {
  111. $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
  112. foreach ($instances as $instance) {
  113. // If this field has been updated already, we want to skip it.
  114. $instance_data = unserialize($instance->data);
  115. $update_instance = FALSE;
  116. foreach ($instance_data['display'] as $display_name => $display_data) {
  117. if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
  118. $instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
  119. $update_instance = TRUE;
  120. }
  121. }
  122. if ($update_instance) {
  123. db_update('field_config_instance')
  124. ->fields(array('data' => serialize($instance_data)))
  125. ->condition('id', $instance->id)
  126. ->execute();
  127. }
  128. }
  129. }
  130. }