front_page.install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the front page module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function front_page_install() {
  10. }
  11. /**
  12. * Implements hook_uninstall().
  13. */
  14. function front_page_uninstall() {
  15. variable_del('front_page_enable');
  16. variable_del('front_page_breadcrumb');
  17. variable_del('front_page_breadcrumb_redirect');
  18. variable_del('special_notice_time');
  19. variable_del('special_notice_text');
  20. }
  21. /**
  22. * Implements hook_schema().
  23. */
  24. function front_page_schema() {
  25. $schema['front_page'] = array(
  26. 'description' => 'Stores Front Page settings.',
  27. 'fields' => array(
  28. 'rid' => array(
  29. 'type' => 'int',
  30. 'not null' => TRUE,
  31. 'unsigned' => TRUE,
  32. 'description' => 'Primary Key: Role ID.',
  33. ),
  34. 'mode' => array(
  35. 'type' => 'varchar',
  36. 'length' => 10,
  37. 'not null' => TRUE,
  38. 'default' => '',
  39. 'description' => 'The mode the front page will operate in for the selected role.',
  40. ),
  41. 'data' => array(
  42. 'type' => 'text',
  43. 'not null' => TRUE,
  44. 'size' => 'big',
  45. 'description' => 'Contains the data for the selected mode. This could be a path or html to display.',
  46. ),
  47. 'filter_format' => array(
  48. 'type' => 'varchar',
  49. 'length' => 255,
  50. 'not null' => TRUE,
  51. 'default' => '',
  52. 'description' => 'The filter format to apply to the data.',
  53. ),
  54. 'weight' => array(
  55. 'type' => 'int',
  56. 'default' => 0,
  57. 'description' => 'The weight of the front page setting.',
  58. )
  59. ),
  60. 'primary key' => array('rid'),
  61. 'indexes' => array(
  62. 'weight' => array('weight'),
  63. ),
  64. );
  65. return $schema;
  66. }
  67. /**
  68. * Update 7200 - Add table if not already added, transfer data into the table and correct special notice times.
  69. */
  70. function front_page_update_7200() {
  71. if (!db_table_exists('front_page')) {
  72. $schema = drupal_get_schema_unprocessed('front_page');
  73. _drupal_schema_initialize($schema, 'front_page', FALSE);
  74. if (isset($schema['front_page'])) {
  75. db_create_table('front_page', $schema['front_page']);
  76. }
  77. // need to add front page data from variables table to new table.
  78. $formats = filter_formats();
  79. $formats = drupal_map_assoc(array_keys($formats));
  80. $default_format = array_shift($formats);
  81. $php_format = isset($formats['php_code']) ? 'php_code' : $default_format;
  82. $roles = user_roles();
  83. foreach ($roles as $rid => $role_name) {
  84. $mode = variable_get('front_' . $rid . '_type', '');
  85. if (!empty($mode)) {
  86. switch ($mode) {
  87. case 'themed':
  88. case 'full':
  89. $data = variable_get('front_' . $rid . '_text', '');
  90. $format = $default_format;
  91. if (variable_get('front_' . $rid . '_php', 0)) {
  92. $format = $php_format;
  93. }
  94. break;
  95. case 'redirect':
  96. case 'alias':
  97. $data = variable_get('front_' . $rid . '_redirect', '');
  98. $format = '';
  99. break;
  100. default:
  101. $mode = '';
  102. $format = '';
  103. $data = '';
  104. break;
  105. }
  106. $weight = $rid * -1;
  107. db_merge('front_page')
  108. ->key(array('rid' => $rid))
  109. ->fields(array(
  110. 'mode' => $mode,
  111. 'data' => $data,
  112. 'filter_format' => $format,
  113. 'weight' => $weight,
  114. ))
  115. ->execute();
  116. variable_del('front_' . $rid . '_type');
  117. variable_del('front_' . $rid . '_text');
  118. variable_del('front_' . $rid . '_php');
  119. variable_del('front_' . $rid . '_redirect');
  120. }
  121. }
  122. }
  123. if (variable_get('site_frontpage', 'node') == 'front_page') {
  124. variable_set('site_frontpage', 'node');
  125. }
  126. }
  127. function front_page_update_7201() {
  128. variable_del('special_notice_time');
  129. variable_del('special_notice_text');
  130. variable_del('front_page_breadcrumb');
  131. $path = variable_get('front_page_breadcrumb_redirect', '');
  132. variable_set('front_page_home_link_path', $path);
  133. variable_del('front_page_breadcrumb_redirect');
  134. }