tac_lite.install 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @file
  4. * Installation functions for tac_lite.
  5. * TODO: All updates need proper error handling and responses
  6. */
  7. /**
  8. * Implementation of hook_install().
  9. *
  10. * Ensure that tac_lite hooks are invoked after taxonomy module hooks.
  11. */
  12. function tac_lite_install() {
  13. $taxonomy_weight = db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'")->fetchField();
  14. $num_updated = db_update('system')
  15. ->fields(array(
  16. 'weight' => $taxonomy_weight + 9,
  17. ))
  18. ->condition('name', 'tac_lite')
  19. ->execute();
  20. // Note that it is not necessary to rebuild the node access table here, as
  21. // that will be done when module settings are saved.
  22. }
  23. /**
  24. * Implements hook_uninstall().
  25. *
  26. * Clean up tac_lite variables.
  27. */
  28. function tac_lite_uninstall() {
  29. for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
  30. variable_del('tac_lite_config_scheme_' . $i);
  31. variable_del('tac_lite_grants_scheme_' . $i);
  32. }
  33. variable_del('tac_lite_schemes');
  34. variable_del('tac_lite_categories');
  35. }
  36. /**
  37. * Ensure that tac_lite hooks are invoked after taxonomy module hooks.
  38. */
  39. function tac_lite_update_1() {
  40. $taxonomy_weight = db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'")->fetchField();
  41. $num_updated = db_update('system')
  42. ->fields(array(
  43. 'weight' => $taxonomy_weight + 9,
  44. ))
  45. ->condition('name', 'tac_lite')
  46. ->execute();
  47. }
  48. /**
  49. * Ensure that the node_access table is thoroughly cleaned up in Drupal 5 update.
  50. */
  51. function tac_lite_update_2() {
  52. node_access_rebuild(); // Would batch mode help here?
  53. // Assume success and return with message.
  54. return t('Rebuilt node access table for tac_lite module.');
  55. }
  56. /**
  57. * Introducing schemes. Rename tac_lite_default_grants to tac_lite_grants_scheme_1.
  58. */
  59. function tac_lite_update_3() {
  60. $num_updated = db_update('variable')
  61. ->fields(array(
  62. 'name' => 'tac_lite_grants_scheme_1',
  63. ))
  64. ->condition('name', 'tac_lite_default_grants')
  65. ->execute();
  66. }
  67. /**
  68. * Start of updates to Drupal 6.x-1.2. Start using Drupal standard
  69. * update numbers.
  70. */
  71. /**
  72. * Rename permission from "administer_tac_lite" to "administer
  73. * tac_lite" for UI consistency.
  74. */
  75. function tac_lite_update_6001() {
  76. // TODO: Please review to make sure this is handling this update properly for this version of code. (only change was formatting and table name)
  77. $result = db_query("SELECT * FROM {role_permission} WHERE perm LIKE '%administer_tac_lite%'");
  78. foreach ($result as $permission) {
  79. $perm = str_replace('administer_tac_lite', 'administer tac_lite', $permission->perm);
  80. //db_query("UPDATE {permission} SET perm = '". db_escape_string($perm) ."' WHERE rid =". $permission->rid);
  81. $num_updated = db_update('permission')
  82. ->fields(array(
  83. 'perm' => $perm,
  84. ))
  85. ->condition('rid', $permission->rid)
  86. ->execute();
  87. }
  88. }
  89. /**
  90. * The tac_lite.module now supports an option to apply access by taxonomy to unpublished nodes as well as published content. The default behavior is that tac_lite has no effect on unpublished content. You should review each of your tac_lite schemes and, optionally, adjust this setting before rebuilding node access permissions.
  91. */
  92. function tac_lite_update_7001() {
  93. // See https://drupal.org/node/1918272 for details.
  94. drupal_set_message(t('Please review each of your <a href="!url">taxonomy access control schemes</a>. If necessary, adjust the new option to affect access to unpublished content. Then rebuild content access permissions.', array(
  95. '!url' => url('admin/config/people/tac_lite'),
  96. )));
  97. node_access_needs_rebuild(TRUE);
  98. }
  99. /**
  100. * Rebuild node_access permissions, for sites upgrading from tac_lite 1.0 (or
  101. * 1.1) to 1.2. This will fix a bug in which some nodes were erroneously added
  102. * to the node_access table. You will be prompted to rebuild access permissions
  103. * after the update process is complete. (See the status report page.)
  104. */
  105. function tac_lite_update_7002() {
  106. node_access_needs_rebuild(TRUE);
  107. }