Projet

Général

Profil

Paste
Télécharger (4,98 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / nodeaccess / nodeaccess.install @ c2ac6d1d

1
<?php
2

    
3
/**
4
 * @file
5
 * Install/uninstall functions for Nodeaccess.
6
 */
7

    
8
/**
9
 * Implements hook_enable().
10
 */
11
function nodeaccess_enable() {
12
}
13

    
14
/**
15
 * Implements hook_disable().
16
 */
17
function nodeaccess_disable() {
18
  nodeaccess_disabling(TRUE);
19
}
20

    
21
/**
22
 * Implements hook_install().
23
 */
24
function nodeaccess_install() {
25
  // Set up default permissions to be view for authenticated and
26
  // anonymous users, and all permissions for author.
27
  $grants = array();
28
  $role_perms = user_role_permissions(array(1 => 1, 2 => 2));
29
  $role_perms[1]['access content'] = isset($role_perms[1]['access content'])?
30
                                      intval($role_perms[1]['access content']) : 0;
31
  $role_perms[2]['access content'] = isset($role_perms[2]['access content'])?
32
                                      intval($role_perms[2]['access content']) : 0;
33
  // Anonymous user setting.
34
  $grants[] = array(
35
    'gid' => 1,
36
    'realm' => 'nodeaccess_rid',
37
    'grant_view' => $role_perms[1]['access content'],
38
  );
39
  // Authenticated user setting.
40
  $grants[] = array(
41
    'gid' => 2,
42
    'realm' => 'nodeaccess_rid',
43
    'grant_view' => $role_perms[2]['access content'],
44
  );
45
  $author_prefs = array();
46
  foreach (node_type_get_types() as $type => $name) {
47
    // We check the edit permissions for anonymous and authenticated users.
48
    $edit_perm = 'edit any ' . $type . ' content';
49
    $role_perms[1][$edit_perm] = isset($role_perms[1][$edit_perm])?
50
                                      intval($role_perms[1][$edit_perm]) : 0;
51
    $role_perms[2][$edit_perm] = isset($role_perms[2][$edit_perm])?
52
                                      intval($role_perms[2][$edit_perm]) : 0;
53
    $grants[0]['grant_update'] = $role_perms[1][$edit_perm];
54
    $grants[1]['grant_update'] = $role_perms[2][$edit_perm];
55
    // We check the delete permissions for anonymous and authenticated users.
56
    $delete_perm = 'delete any ' . $type . ' content';
57
    $role_perms[1][$delete_perm] = isset($role_perms[1][$delete_perm])?
58
                                      intval($role_perms[1][$delete_perm]) : 0;
59
    $role_perms[2][$delete_perm] = isset($role_perms[2][$delete_perm])?
60
                                      intval($role_perms[2][$delete_perm]) : 0;
61
    $grants[0]['grant_delete'] = $role_perms[1][$delete_perm];
62
    $grants[1]['grant_delete'] = $role_perms[2][$delete_perm];
63
    variable_set('nodeaccess_' . $type, $grants);
64
    $author_prefs[$type] = array(
65
      'grant_view' => 0,
66
      'grant_update' => 0,
67
      'grant_delete' => 0,
68
    );
69
  }
70
  variable_set('nodeaccess_authors', $author_prefs);
71
  // Set up all permissions to be editable by default.
72
  $grant_prefs = array('view' => 1, 'edit' => 1, 'delete' => 1);
73
  variable_set('nodeaccess-grants', $grant_prefs);
74
}
75

    
76
/**
77
 * Implements hook_schema().
78
 */
79
function nodeaccess_schema() {
80
  $schema['nodeaccess'] = array(
81
    'fields' => array(
82
      'nid' => array(
83
        'type' => 'int',
84
        'unsigned' => TRUE,
85
        'not null' => TRUE,
86
        'default' => 0,
87
      ),
88
      'gid' => array(
89
        'type' => 'int',
90
        'unsigned' => TRUE,
91
        'not null' => TRUE,
92
        'default' => 0,
93
      ),
94
      'realm' => array(
95
        'type' => 'varchar',
96
        'length' => 255,
97
        'not null' => TRUE,
98
        'default' => '',
99
      ),
100
      'grant_view'  => array(
101
        'type' => 'int',
102
        'size' => 'tiny',
103
        'unsigned' => TRUE,
104
        'not null' => TRUE,
105
        'default' => 0,
106
      ),
107
      'grant_update' => array(
108
        'type' => 'int',
109
        'size' => 'tiny',
110
        'unsigned' => TRUE,
111
        'not null' => TRUE,
112
        'default' => 0,
113
      ),
114
      'grant_delete' => array(
115
        'type' => 'int',
116
        'size' => 'tiny',
117
        'unsigned' => TRUE,
118
        'not null' => TRUE,
119
        'default' => 0,
120
      ),
121
    ),
122
    'primary key' => array('nid', 'gid', 'realm'),
123
  );
124
  $schema['nodeaccess_role_alias'] = array(
125
    'fields' => array(
126
      'rid' => array(
127
        'type' => 'int',
128
        'unsigned' => TRUE,
129
        'not null' => TRUE,
130
        'default' => 0,
131
      ),
132
      'name' => array(
133
        'type' => 'varchar',
134
        'length' => 50,
135
        'not null' => TRUE,
136
        'default' => '',
137
      ),
138
      'weight' => array(
139
        'type' => 'int',
140
        'not null' => TRUE,
141
        'default' => 0,
142
      ),
143
    ),
144
    'primary key' => array('rid'),
145
  );
146
  return $schema;
147
}
148

    
149
/**
150
 * Implements hook_uninstall().
151
 */
152
function nodeaccess_uninstall() {
153
  // Remove variables.
154
  variable_del('nodeaccess-priority');
155
  variable_del('nodeaccess-preserve');
156
  variable_del('nodeaccess-grants');
157
  variable_del('nodeaccess-roles');
158
  variable_del('nodeaccess-types');
159
  variable_del('nodeaccess_authors');
160
  foreach (node_type_get_types() as $type => $name) {
161
    variable_del('nodeaccess_' . $type);
162
    variable_del('nodeaccess_' . $type . '_userreference');
163
  }
164
  // Remove tables.
165
  drupal_uninstall_schema('nodeaccess');
166
}
167

    
168
/**
169
 * Flag nodeaccess permissions as needing a rebuild. Rebuild permissions from the status page.
170
 */
171
function nodeaccess_update_7105() {
172
  node_access_needs_rebuild();
173
}