diff.install 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * @file
  4. * Provides uninstallation functions.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function diff_install() {
  10. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('diff view changes'));
  11. user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('diff view changes'));
  12. }
  13. /**
  14. * Implements hook_uninstall().
  15. */
  16. function diff_uninstall() {
  17. // Bulk delete entity based variables.
  18. $prefixes = array(
  19. 'diff_enable_revisions_page_',
  20. 'diff_show_',
  21. 'diff_view_mode_',
  22. 'diff_admin_path_',
  23. 'diff_default_state_',
  24. 'diff_additional_options_',
  25. );
  26. foreach ($prefixes as $prefix) {
  27. db_delete('variable')
  28. ->condition('name', db_like($prefix) . '%', 'LIKE')
  29. ->execute();
  30. }
  31. // Delete global variables.
  32. variable_del('diff_context_lines_trailing');
  33. variable_del('diff_context_lines_leading');
  34. variable_del('diff_theme');
  35. variable_del('diff_radio_behavior', '');
  36. foreach (field_info_fields() as $field) {
  37. variable_del("diff_{$field['module']}_field_{$field['type']}_default_options");
  38. }
  39. }
  40. /**
  41. * Updates the existing system variables to target the entity type and bundle.
  42. */
  43. function diff_update_7300() {
  44. $node_types = array_keys(node_type_get_types());
  45. foreach ($node_types as $bundle) {
  46. $type_variables = array(
  47. 'show_preview_changes',
  48. 'enable_revisions_page',
  49. 'show_diff_inline',
  50. );
  51. foreach ($type_variables as $prefix) {
  52. $setting = variable_get($prefix . '_' . $bundle, NULL);
  53. if (isset($setting)) {
  54. variable_del($prefix . '_' . $bundle);
  55. variable_set('diff_' . $prefix . '_node_' . $bundle, $setting);
  56. }
  57. }
  58. }
  59. }
  60. /**
  61. * Renames some internal settings names.
  62. */
  63. function diff_update_7303() {
  64. // Get current values.
  65. $radio = variable_get('diff_script_revisioning', 'simple');
  66. $leading = variable_get('diff_leading_context_lines', 2);
  67. $trailing = variable_get('diff_trailing_context_lines', 2);
  68. // Create new variable names.
  69. variable_set('diff_radio_behavior', $radio);
  70. variable_set('diff_context_lines_leading', $leading);
  71. variable_set('diff_context_lines_trailing', $trailing);
  72. // Delete old variables.
  73. variable_del('diff_script_revisioning');
  74. variable_del('diff_leading_context_lines');
  75. variable_del('diff_trailing_context_lines');
  76. }
  77. /**
  78. * Removes unused variable settings and merges inline diff block settings.
  79. */
  80. function diff_update_7304() {
  81. // This is now always applied to text fields.
  82. variable_del('diff_normalise_text');
  83. // Merge the content type settings for the inline diff block into a single
  84. // variable.
  85. $node_types = array_keys(node_type_get_types());
  86. $enabled_types = array();
  87. foreach ($node_types as $node_type) {
  88. if (variable_get('diff_show_diff_inline_node_' . $node_type, FALSE)) {
  89. $enabled_types[$node_type] = $node_type;
  90. }
  91. variable_del('diff_show_diff_inline_node_' . $node_type);
  92. }
  93. variable_set('diff_show_diff_inline_node_bundles', $enabled_types);
  94. // Warn users that these settings are altered.
  95. drupal_set_message(t('Diff <em>Inline differences</em> content type settings are now located within the <em>Inline differences</em> block settings.'));
  96. }
  97. /**
  98. * Updates to normalize the new view mode settings.
  99. */
  100. function diff_update_7305() {
  101. // Rebuild the menus.
  102. variable_set('menu_rebuild_needed', TRUE);
  103. // Removed the enforced entity view mode.
  104. db_delete('variable')
  105. ->condition('name', db_like('diff_view_mode_standard_node_') . '%', 'LIKE')
  106. ->execute();
  107. // Removes the configurable view mode for the inline diff block, as this
  108. // is fairly meaningless and confusing to users.
  109. db_delete('variable')
  110. ->condition('name', db_like('diff_view_mode_inline_') . '%', 'LIKE')
  111. ->execute();
  112. }
  113. /**
  114. * Sets the optional additional node properties to render so that the title
  115. * still shows by default when doing node comparisons.
  116. */
  117. function diff_update_7306() {
  118. variable_set('diff_additional_options_node', array('title' => 'title'));
  119. }
  120. /**
  121. * Grants access to the Diff "View Changes" button permission to all users
  122. * if the Diff module is enabled. You need to manually update the permissions
  123. * if the module is currently disabled.
  124. */
  125. function diff_update_7307() {
  126. // The update hooks run even if disabled, and this throws an error.
  127. if (module_exists('diff')) {
  128. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('diff view changes'));
  129. user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('diff view changes'));
  130. }
  131. }