link.install 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. variable_del('link_default_protocol');
  35. }
  36. /**
  37. * Implements hook_field_schema().
  38. */
  39. function link_field_schema($field) {
  40. return array(
  41. 'columns' => array(
  42. 'url' => array(
  43. 'type' => 'varchar',
  44. // Maximum URLs length.
  45. 'length' => 2048,
  46. 'not null' => FALSE,
  47. 'sortable' => TRUE,
  48. ),
  49. 'title' => array(
  50. 'type' => 'varchar',
  51. 'length' => 255,
  52. 'not null' => FALSE,
  53. 'sortable' => TRUE,
  54. ),
  55. 'attributes' => array(
  56. 'type' => 'text',
  57. 'size' => 'medium',
  58. 'not null' => FALSE,
  59. ),
  60. ),
  61. );
  62. }
  63. /**
  64. * Implements hook_update_last_removed().
  65. */
  66. function link_update_last_removed() {
  67. return 6001;
  68. }
  69. /**
  70. * Implements hook_update_N().
  71. *
  72. * Handles moving settings data from field_config.data to
  73. * field_config_instance.data.
  74. */
  75. function link_update_7000() {
  76. // For each field that is a link field, we need to copy the settings from the
  77. // general field level down to the instance.
  78. $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
  79. foreach ($result as $field) {
  80. $field_data = unserialize($field->data);
  81. $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
  82. foreach ($instances as $instance) {
  83. // If this field has been updated already, we want to skip it.
  84. $instance_data = unserialize($instance->data);
  85. $update_instance = FALSE;
  86. if (!isset($instance_data['settings']['title'])) {
  87. foreach ($field_data['settings'] as $key => $value) {
  88. if (!isset($instance_data['settings'][$key])) {
  89. $instance_data['settings'][$key] = $value;
  90. $update_instance = TRUE;
  91. }
  92. }
  93. if ($update_instance) {
  94. // Update the database.
  95. db_update('field_config_instance')
  96. ->fields(array('data' => serialize($instance_data)))
  97. ->condition('id', $instance->id)
  98. ->execute();
  99. }
  100. }
  101. }
  102. }
  103. return t("Instance settings have been set with the data from the field settings.");
  104. }
  105. /**
  106. * Renames all displays from foobar to link_foobar.
  107. */
  108. function link_update_7001() {
  109. // Update the display type for each link field type.
  110. $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
  111. foreach ($result as $field) {
  112. $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
  113. foreach ($instances as $instance) {
  114. // If this field has been updated already, we want to skip it.
  115. $instance_data = unserialize($instance->data);
  116. $update_instance = FALSE;
  117. foreach ($instance_data['display'] as $display_name => $display_data) {
  118. if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
  119. $instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
  120. $update_instance = TRUE;
  121. }
  122. }
  123. if ($update_instance) {
  124. db_update('field_config_instance')
  125. ->fields(array('data' => serialize($instance_data)))
  126. ->condition('id', $instance->id)
  127. ->execute();
  128. }
  129. }
  130. }
  131. }
  132. /**
  133. * Rebuild the menu cache to make the settings page use the correct permission.
  134. */
  135. function link_update_7100() {
  136. variable_set('menu_rebuild_needed', TRUE);
  137. }