commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / modules / contact / contact.install
1 <?php
2
3 /**
4 * @file
5 * Install, update and uninstall functions for the contact module.
6 */
7
8 /**
9 * Implements hook_schema().
10 */
11 function contact_schema() {
12 $schema['contact'] = array(
13 'description' => 'Contact form category settings.',
14 'fields' => array(
15 'cid' => array(
16 'type' => 'serial',
17 'unsigned' => TRUE,
18 'not null' => TRUE,
19 'description' => 'Primary Key: Unique category ID.',
20 ),
21 'category' => array(
22 'type' => 'varchar',
23 'length' => 255,
24 'not null' => TRUE,
25 'default' => '',
26 'description' => 'Category name.',
27 'translatable' => TRUE,
28 ),
29 'recipients' => array(
30 'type' => 'text',
31 'not null' => TRUE,
32 'size' => 'big',
33 'description' => 'Comma-separated list of recipient e-mail addresses.',
34 ),
35 'reply' => array(
36 'type' => 'text',
37 'not null' => TRUE,
38 'size' => 'big',
39 'description' => 'Text of the auto-reply message.',
40 ),
41 'weight' => array(
42 'type' => 'int',
43 'not null' => TRUE,
44 'default' => 0,
45 'description' => "The category's weight.",
46 ),
47 'selected' => array(
48 'type' => 'int',
49 'not null' => TRUE,
50 'default' => 0,
51 'size' => 'tiny',
52 'description' => 'Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)',
53 ),
54 ),
55 'primary key' => array('cid'),
56 'unique keys' => array(
57 'category' => array('category'),
58 ),
59 'indexes' => array(
60 'list' => array('weight', 'category'),
61 ),
62 );
63
64 return $schema;
65 }
66
67 /**
68 * Implements hook_install().
69 */
70 function contact_install() {
71 // Insert a default contact category.
72 db_insert('contact')
73 ->fields(array(
74 'category' => 'Website feedback',
75 'recipients' => variable_get('site_mail', ini_get('sendmail_from')),
76 'selected' => 1,
77 'reply' => '',
78 ))
79 ->execute();
80 }
81
82 /**
83 * Implements hook_uninstall().
84 */
85 function contact_uninstall() {
86 variable_del('contact_default_status');
87 variable_del('contact_threshold_limit');
88 variable_del('contact_threshold_window');
89 }
90
91 /**
92 * Implements hook_update_dependencies().
93 */
94 function contact_update_dependencies() {
95 // contact_update_7001() relies on the {role_permission} table being updated
96 // to the new format and filled with data.
97 $dependencies['contact'][7001] = array(
98 'system' => 7007,
99 );
100
101 // contact_update_7002() relies on the {role_permission} table having the
102 // module field, which is created in user_update_7006().
103 $dependencies['contact'][7002] = array(
104 'user' => 7006,
105 );
106
107 return $dependencies;
108 }
109
110 /**
111 * @addtogroup updates-6.x-to-7.x
112 * @{
113 */
114
115 /**
116 * Rename the threshold limit variable.
117 */
118 function contact_update_7000() {
119 variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5));
120 variable_del('contact_hourly_threshold');
121 }
122
123 /**
124 * Rename the administer contact forms permission.
125 */
126 function contact_update_7001() {
127 db_update('role_permission')
128 ->fields(array('permission' => 'administer contact forms'))
129 ->condition('permission', 'administer site-wide contact form')
130 ->execute();
131 }
132
133 /**
134 * Enable the 'access user contact forms' for registered users by default.
135 */
136 function contact_update_7002() {
137 // Do not use user_role_grant_permission() since it relies on
138 // hook_permission(), which will not run for contact module if it is
139 // disabled.
140 db_merge('role_permission')
141 ->key(array(
142 'rid' => DRUPAL_AUTHENTICATED_RID,
143 'permission' => 'access user contact forms',
144 'module' => 'contact',
145 ))
146 ->execute();
147 }
148
149 /**
150 * Change the weight column to normal int.
151 */
152 function contact_update_7003() {
153 db_drop_index('contact', 'list');
154 db_change_field('contact', 'weight', 'weight', array(
155 'type' => 'int',
156 'not null' => TRUE,
157 'default' => 0,
158 'description' => "The category's weight.",
159 ), array(
160 'indexes' => array(
161 'list' => array('weight', 'category'),
162 ),
163 ));
164 }
165
166 /**
167 * @} End of "addtogroup updates-6.x-to-7.x".
168 */