Projet

Général

Profil

Paste
Télécharger (5,71 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / forum_access / forum_access.install @ 87dbc3bf

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
    'indexes'         => array(
96
      'tid'           => array('tid'),
97
      'rid'           => array('rid')),
98
    'foreign keys'    => array(
99
      'tid'           => array('taxonomy_term_data' => 'tid'),
100
      'rid'           => array('role' => 'rid')),
101
  );
102
  return $schema;
103
}
104

    
105
/**
106
 * Implements hook_enable().
107
 */
108
function forum_access_enable() {
109
  variable_del('forum_access_rids'); // clear cache
110
  _forum_access_update_table();
111
}
112

    
113
/**
114
 * Adds missing default records to the {forum_acces} table.
115
 */
116
function _forum_access_update_table() {
117
  $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(
118
    'vid' => _forum_access_get_vid(),
119
  ))->fetchCol();
120
  foreach ($tids as $tid) {
121
    $record = array(
122
      'tid' => $tid,
123
      'rid' => DRUPAL_ANONYMOUS_RID,
124
      'grant_view' => 1,
125
    );
126
    drupal_write_record('forum_access', $record);
127
    $record['rid'] = DRUPAL_AUTHENTICATED_RID;
128
    $record['grant_create'] = 1;
129
    drupal_write_record('forum_access', $record);
130
  }
131
}
132

    
133
/**
134
 * Implements hook_disable().
135
 */
136
function forum_access_disable() {
137
  forum_access_enabled(FALSE);
138
}
139

    
140
/*
141
 * Implements hook_uninstall().
142
 */
143
function forum_access_uninstall() {
144
  variable_del('forum_access_allowed_comment_edit_administration_elements');
145
  variable_del('forum_access_allowed_comment_links_for_create');
146
  variable_del('forum_access_allowed_comment_links_for_udpate');
147
  variable_del('forum_access_allowed_comment_links_for_delete');
148
  variable_del('forum_access_allowed_node_edit_elements');
149
  variable_del('forum_access_allowed_node_edit_options');
150
  variable_del('forum_access_batch_threshold');
151
  variable_del('forum_access_default_template_tid');
152
  variable_del('forum_access_new_template_tid');
153
  variable_del('forum_access_provide_moderators_template_variable');
154
  variable_del('forum_access_rids');
155
  variable_del('forum_access_update_limit');
156
}
157

    
158
function forum_access_update_last_removed() {
159
  return 6105;
160
}
161

    
162
/**
163
 * Change our {acl} table records from 'name' to 'number' (D6 legacy).
164
 */
165
function forum_access_update_6106() {
166
  db_update('acl')->expression('number', 'name')->condition('module', 'forum_access')->isNotNull('name')->execute();
167
  db_update('acl')->fields(array('name' => NULL))->condition('module', 'forum_access')->isNotNull('name')->execute();
168
}
169

    
170
/**
171
 * Remove the D6 Forum Moderator role which is not needed anymore.
172
 */
173
function forum_access_update_7001() {
174
  // We don't need the Forum Moderator temporary role anymore.
175
  if ($moderator_rid = variable_get('forum_access_moderator_rid', NULL)) {
176
    user_role_delete($moderator_rid);
177
    variable_del('forum_access_moderator_rid');
178
  }
179
}
180

    
181
/**
182
 * Remove the obsolete 'forum_access_D5_legacy_mode' variable.
183
 */
184
function forum_access_update_7002() {
185
  variable_del('forum_access_D5_legacy_mode');
186
}