| 1 |
<?php
|
| 2 |
// $Id: image_gallery_access.install,v 1.9 2009/09/20 00:10:16 salvis Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install().
|
| 6 |
*/
|
| 7 |
function image_gallery_access_install() {
|
| 8 |
drupal_install_schema('image_gallery_access');
|
| 9 |
db_query("UPDATE {system} SET weight = 2 WHERE name = 'image_gallery_access'");
|
| 10 |
|
| 11 |
if (function_exists('_image_gallery_get_vid') && ($vid = _image_gallery_get_vid())) {
|
| 12 |
foreach (array(DRUPAL_ANONYMOUS_RID => 0, DRUPAL_AUTHENTICATED_RID => 1) as $rid => $grant_create) {
|
| 13 |
db_query("
|
| 14 |
INSERT INTO {image_gallery_access} (tid, rid, grant_view, grant_update, grant_delete, grant_create, priority)
|
| 15 |
SELECT t.tid, %d, 1, 0, 0, %d, 0
|
| 16 |
FROM {image_gallery_access} iga RIGHT JOIN {term_data} t ON iga.tid = t.tid AND t.vid = %d AND iga.rid <> %d
|
| 17 |
WHERE iga.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 image_gallery_access_schema() {
|
| 28 |
$schema['image_gallery_access'] = array(
|
| 29 |
'description' => t('The base Image Gallery Access Control table.'),
|
| 30 |
'fields' => array(
|
| 31 |
'tid' => array(
|
| 32 |
'description' => t('The {term_data}.tid to which this {image_gallery_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 {image_gallery_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 image_gallery_access_uninstall() {
|
| 87 |
drupal_uninstall_schema('image_gallery_access');
|
| 88 |
variable_del('image_gallery_access_batch_threshold');
|
| 89 |
variable_del('image_gallery_access_default_template_tid');
|
| 90 |
variable_del('image_gallery_access_new_template_tid');
|
| 91 |
variable_del('image_gallery_access_provide_moderators_template_variable');
|
| 92 |
}
|
| 93 |
|
| 94 |
/**
|
| 95 |
* Purge orphaned grants that were left behind when deleting roles.
|
| 96 |
*/
|
| 97 |
function image_gallery_access_update_1() {
|
| 98 |
$ret = array();
|
| 99 |
db_query("DELETE FROM {image_gallery_access} WHERE rid NOT IN (SELECT rid from {role})");
|
| 100 |
db_query("DELETE FROM {node_access} WHERE realm = 'image_gallery_access' AND gid NOT IN (SELECT rid from {role})");
|
| 101 |
return $ret;
|
| 102 |
}
|
| 103 |
|
| 104 |
/**
|
| 105 |
* Add a priority column (will probably not be used until D6).
|
| 106 |
*/
|
| 107 |
function image_gallery_access_update_2() {
|
| 108 |
$ret = array();
|
| 109 |
db_add_field($ret, 'image_gallery_access', 'priority', array(
|
| 110 |
'description' => t('The priority of this grant.'),
|
| 111 |
'type' => 'int',
|
| 112 |
'size' => 'small',
|
| 113 |
'not null' => TRUE,
|
| 114 |
'default' => 0));
|
| 115 |
return $ret;
|
| 116 |
}
|