| 1 |
<?php
|
| 2 |
// $Id: forum_access.install,v 1.12 2009/08/27 23:44:59 salvis Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install().
|
| 6 |
*/
|
| 7 |
function forum_access_install() {
|
| 8 |
drupal_install_schema('forum_access');
|
| 9 |
db_query("UPDATE {system} SET weight = 2 WHERE name = 'forum_access'");
|
| 10 |
|
| 11 |
if ($vid = variable_get('forum_nav_vocabulary', FALSE)) {
|
| 12 |
foreach (array(DRUPAL_ANONYMOUS_RID => 0, DRUPAL_AUTHENTICATED_RID => 1) as $rid => $grant_create) {
|
| 13 |
db_query("
|
| 14 |
INSERT INTO {forum_access} (tid, rid, grant_view, grant_update, grant_delete, grant_create, priority)
|
| 15 |
SELECT t.tid, %d, 1, 0, 0, %d, 0
|
| 16 |
FROM {forum_access} fa RIGHT JOIN {term_data} t ON fa.tid = t.tid AND t.vid = %d AND fa.rid <> %d
|
| 17 |
WHERE fa.tid IS NULL",
|
| 18 |
$rid, $grant_create, DRUPAL_AUTHENTICATED_RID, $vid
|
| 19 |
);
|
| 20 |
}
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Implementation of hook_schema().
|
| 26 |
*/
|
| 27 |
function forum_access_schema() {
|
| 28 |
$schema['forum_access'] = array(
|
| 29 |
'description' => t('The base Forum Access Control table.'),
|
| 30 |
'fields' => array(
|
| 31 |
'tid' => array(
|
| 32 |
'description' => t('The {term_data}.tid to which this {forum_access} entry applies.'),
|
| 33 |
'type' => 'int',
|
| 34 |
'not null' => TRUE,
|
| 35 |
'default' => 0),
|
| 36 |
'rid' => array(
|
| 37 |
'description' => t('The {role}.rid to which this {forum_access} entry applies.'),
|
| 38 |
'type' => 'int',
|
| 39 |
'not null' => TRUE,
|
| 40 |
'default' => 0),
|
| 41 |
'grant_view' => array(
|
| 42 |
'description' => t('Whether to grant "view" permission.'),
|
| 43 |
'type' => 'int',
|
| 44 |
'size' => 'tiny',
|
| 45 |
'unsigned' => TRUE,
|
| 46 |
'not null' => TRUE,
|
| 47 |
'default' => 0),
|
| 48 |
'grant_update' => array(
|
| 49 |
'description' => t('Whether to grant "update" permission.'),
|
| 50 |
'type' => 'int',
|
| 51 |
'size' => 'tiny',
|
| 52 |
'unsigned' => TRUE,
|
| 53 |
'not null' => TRUE,
|
| 54 |
'default' => 0),
|
| 55 |
'grant_delete' => array(
|
| 56 |
'description' => t('Whether to grant "delete" permission.'),
|
| 57 |
'type' => 'int',
|
| 58 |
'size' => 'tiny',
|
| 59 |
'unsigned' => TRUE,
|
| 60 |
'not null' => TRUE,
|
| 61 |
'default' => 0),
|
| 62 |
'grant_create' => array(
|
| 63 |
'description' => t('Whether to grant "create" permission.'),
|
| 64 |
'type' => 'int',
|
| 65 |
'size' => 'tiny',
|
| 66 |
'unsigned' => TRUE,
|
| 67 |
'not null' => TRUE,
|
| 68 |
'default' => 0),
|
| 69 |
'priority' => array(
|
| 70 |
'description' => t('The priority of this grant.'),
|
| 71 |
'type' => 'int',
|
| 72 |
'size' => 'small',
|
| 73 |
'not null' => TRUE,
|
| 74 |
'default' => 0)),
|
| 75 |
'indexes' => array(
|
| 76 |
'tid' => array('tid'),
|
| 77 |
'rid' => array('rid')),
|
| 78 |
);
|
| 79 |
return $schema;
|
| 80 |
}
|
| 81 |
|
| 82 |
|
| 83 |
/*
|
| 84 |
* Implementation of hook_uninstall
|
| 85 |
*/
|
| 86 |
function forum_access_uninstall() {
|
| 87 |
drupal_uninstall_schema('forum_access');
|
| 88 |
variable_del('forum_access_allowed_node_edit_elements');
|
| 89 |
variable_del('forum_access_allowed_node_edit_options');
|
| 90 |
variable_del('forum_access_batch_threshold');
|
| 91 |
variable_del('forum_access_default_template_tid');
|
| 92 |
variable_del('forum_access_new_template_tid');
|
| 93 |
variable_del('forum_access_provide_moderators_template_variable');
|
| 94 |
}
|
| 95 |
|
| 96 |
/**
|
| 97 |
* Purge orphaned grants that were left behind when deleting roles.
|
| 98 |
*/
|
| 99 |
function forum_access_update_1() {
|
| 100 |
$ret = array();
|
| 101 |
db_query("DELETE FROM {forum_access} WHERE rid NOT IN (SELECT rid from {role})");
|
| 102 |
db_query("DELETE FROM {node_access} WHERE realm = 'forum_access' AND gid NOT IN (SELECT rid from {role})");
|
| 103 |
return $ret;
|
| 104 |
}
|
| 105 |
|
| 106 |
/**
|
| 107 |
* Add a priority column (will probably not be used until D6).
|
| 108 |
*/
|
| 109 |
function forum_access_update_2() {
|
| 110 |
$ret = array();
|
| 111 |
db_add_field($ret, 'forum_access', 'priority', array(
|
| 112 |
'description' => t('The priority of this grant.'),
|
| 113 |
'type' => 'int',
|
| 114 |
'size' => 'small',
|
| 115 |
'not null' => TRUE,
|
| 116 |
'default' => 0));
|
| 117 |
return $ret;
|
| 118 |
}
|
| 119 |
|
| 120 |
/**
|
| 121 |
* Warn users upgrading from Drupal 5.
|
| 122 |
*/
|
| 123 |
function forum_access_update_6100() {
|
| 124 |
drupal_set_message('<b>Upgrading Forum Access from Drupal 5? Then please read:</b><br />In Drupal 5, comment posting was not restricted by Forum Access; users with <em>View</em> access (and the <em>post comments</em> permission) were always allowed to post forum comments. Starting with Drupal 6, posting comments is now restricted to users with <em>Post</em> access. If you prefer the old behavior, then go to '. l('Forum Settings', 'admin/content/forum/settings', array('fragment' => 'edit-forum-admin-settings-forum-access')) .' and turn <em>Drupal 5 legacy mode</em> on.', 'warning', FALSE);
|
| 125 |
return array();
|
| 126 |
}
|
| 127 |
|