1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Install, update and uninstall functions for the forum_access module.
|
6
|
*
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* Implements hook_install().
|
11
|
*/
|
12
|
function forum_access_install() {
|
13
|
db_update('system')
|
14
|
->fields(array('weight' => 2))
|
15
|
->condition('name', 'forum_access')
|
16
|
->execute();
|
17
|
|
18
|
if ($vid = variable_get('forum_nav_vocabulary', FALSE)) {
|
19
|
$result = db_query("SELECT t.tid FROM {taxonomy_term_data} t LEFT JOIN {forum_access} fa ON t.tid = fa.tid WHERE fa.tid IS NULL AND t.vid = :vid", array(
|
20
|
':vid' => $vid
|
21
|
));
|
22
|
$grant_create_by_rid = array(
|
23
|
DRUPAL_ANONYMOUS_RID => 0,
|
24
|
DRUPAL_AUTHENTICATED_RID => 1,
|
25
|
);
|
26
|
foreach ($result as $td) {
|
27
|
foreach ($grant_create_by_rid as $rid => $grant_create) {
|
28
|
db_insert('forum_access')
|
29
|
->fields(array(
|
30
|
'tid' => $td->tid,
|
31
|
'rid' => $rid,
|
32
|
'grant_view' => 1,
|
33
|
'grant_update' => 0,
|
34
|
'grant_delete' => 0,
|
35
|
'grant_create' => $grant_create,
|
36
|
'priority' => 0,
|
37
|
))
|
38
|
->execute();
|
39
|
}
|
40
|
}
|
41
|
}
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Implements hook_schema().
|
46
|
*/
|
47
|
function forum_access_schema() {
|
48
|
$schema['forum_access'] = array(
|
49
|
'description' => 'The Forum Access control table.',
|
50
|
'fields' => array(
|
51
|
'tid' => array(
|
52
|
'description' => 'The {taxonomy_term_data}.tid to which this {forum_access} entry applies.',
|
53
|
'type' => 'int',
|
54
|
'not null' => TRUE,
|
55
|
'default' => 0),
|
56
|
'rid' => array(
|
57
|
'description' => 'The {role}.rid to which this {forum_access} entry applies.',
|
58
|
'type' => 'int',
|
59
|
'not null' => TRUE,
|
60
|
'default' => 0),
|
61
|
'grant_view' => array(
|
62
|
'description' => 'Whether to grant "view" permission.',
|
63
|
'type' => 'int',
|
64
|
'size' => 'tiny',
|
65
|
'unsigned' => TRUE,
|
66
|
'not null' => TRUE,
|
67
|
'default' => 0),
|
68
|
'grant_update' => array(
|
69
|
'description' => 'Whether to grant "update" permission.',
|
70
|
'type' => 'int',
|
71
|
'size' => 'tiny',
|
72
|
'unsigned' => TRUE,
|
73
|
'not null' => TRUE,
|
74
|
'default' => 0),
|
75
|
'grant_delete' => array(
|
76
|
'description' => 'Whether to grant "delete" permission.',
|
77
|
'type' => 'int',
|
78
|
'size' => 'tiny',
|
79
|
'unsigned' => TRUE,
|
80
|
'not null' => TRUE,
|
81
|
'default' => 0),
|
82
|
'grant_create' => array(
|
83
|
'description' => 'Whether to grant "create" permission.',
|
84
|
'type' => 'int',
|
85
|
'size' => 'tiny',
|
86
|
'unsigned' => TRUE,
|
87
|
'not null' => TRUE,
|
88
|
'default' => 0),
|
89
|
'priority' => array(
|
90
|
'description' => 'The priority of this grant.',
|
91
|
'type' => 'int',
|
92
|
'size' => 'small',
|
93
|
'not null' => TRUE,
|
94
|
'default' => 0)),
|
95
|
'primary key' => array('tid', 'rid'),
|
96
|
'indexes' => array('rid' => array('rid')),
|
97
|
'foreign keys' => array(
|
98
|
'tid' => array('taxonomy_term_data' => 'tid'),
|
99
|
'rid' => array('role' => 'rid')),
|
100
|
);
|
101
|
return $schema;
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Implements hook_enable().
|
106
|
*/
|
107
|
function forum_access_enable() {
|
108
|
variable_del('forum_access_rids'); // clear cache
|
109
|
_forum_access_update_table();
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* Adds missing default records to the {forum_acces} table.
|
114
|
*/
|
115
|
function _forum_access_update_table() {
|
116
|
$tids = db_query("SELECT td.tid FROM {taxonomy_term_data} td LEFT JOIN {forum_access} fa ON td.tid = fa.tid WHERE td.vid = :vid AND fa.tid IS NULL", array(
|
117
|
'vid' => _forum_access_get_vid(),
|
118
|
))->fetchCol();
|
119
|
foreach ($tids as $tid) {
|
120
|
$record = array(
|
121
|
'tid' => $tid,
|
122
|
'rid' => DRUPAL_ANONYMOUS_RID,
|
123
|
'grant_view' => 1,
|
124
|
);
|
125
|
drupal_write_record('forum_access', $record);
|
126
|
$record['rid'] = DRUPAL_AUTHENTICATED_RID;
|
127
|
$record['grant_create'] = 1;
|
128
|
drupal_write_record('forum_access', $record);
|
129
|
}
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* Implements hook_disable().
|
134
|
*/
|
135
|
function forum_access_disable() {
|
136
|
forum_access_enabled(FALSE);
|
137
|
}
|
138
|
|
139
|
/*
|
140
|
* Implements hook_uninstall().
|
141
|
*/
|
142
|
function forum_access_uninstall() {
|
143
|
variable_del('forum_access_allowed_comment_edit_administration_elements');
|
144
|
variable_del('forum_access_allowed_comment_links_for_create');
|
145
|
variable_del('forum_access_allowed_comment_links_for_udpate');
|
146
|
variable_del('forum_access_allowed_comment_links_for_delete');
|
147
|
variable_del('forum_access_allowed_node_edit_elements');
|
148
|
variable_del('forum_access_allowed_node_edit_options');
|
149
|
variable_del('forum_access_batch_threshold');
|
150
|
variable_del('forum_access_default_template_tid');
|
151
|
variable_del('forum_access_new_template_tid');
|
152
|
variable_del('forum_access_provide_moderators_template_variable');
|
153
|
variable_del('forum_access_rids');
|
154
|
variable_del('forum_access_update_limit');
|
155
|
}
|
156
|
|
157
|
function forum_access_update_last_removed() {
|
158
|
return 6105;
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* Change our {acl} table records from 'name' to 'number' (D6 legacy).
|
163
|
*/
|
164
|
function forum_access_update_6106() {
|
165
|
db_update('acl')->expression('number', 'name')->condition('module', 'forum_access')->isNotNull('name')->execute();
|
166
|
db_update('acl')->fields(array('name' => NULL))->condition('module', 'forum_access')->isNotNull('name')->execute();
|
167
|
}
|
168
|
|
169
|
/**
|
170
|
* Remove the D6 Forum Moderator role which is not needed anymore.
|
171
|
*/
|
172
|
function forum_access_update_7001() {
|
173
|
// We don't need the Forum Moderator temporary role anymore.
|
174
|
if ($moderator_rid = (int) variable_get('forum_access_moderator_rid', NULL)) {
|
175
|
user_role_delete($moderator_rid);
|
176
|
variable_del('forum_access_moderator_rid');
|
177
|
}
|
178
|
}
|
179
|
|
180
|
/**
|
181
|
* Remove the obsolete 'forum_access_D5_legacy_mode' variable.
|
182
|
*/
|
183
|
function forum_access_update_7002() {
|
184
|
variable_del('forum_access_D5_legacy_mode');
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* Drop tid index and add primary key to forum_access table.
|
189
|
*/
|
190
|
function forum_access_update_7003() {
|
191
|
db_drop_index('forum_access', 'tid');
|
192
|
db_add_primary_key('forum_access', array('tid', 'rid'));
|
193
|
}
|