| 5 |
*/ |
*/ |
| 6 |
function nodeaccess_install() { |
function nodeaccess_install() { |
| 7 |
// Create tables. |
// Create tables. |
| 8 |
drupal_install_schema('nodeaccess'); |
switch ($GLOBALS['db_type']) { |
| 9 |
|
case 'mysql': |
| 10 |
|
case 'mysqli': |
| 11 |
|
db_query("CREATE TABLE {nodeaccess} ( |
| 12 |
|
nid int(10) unsigned NOT NULL default '0', |
| 13 |
|
gid int(10) unsigned NOT NULL default '0', |
| 14 |
|
realm varchar(255) NOT NULL default '', |
| 15 |
|
grant_view tinyint(1) unsigned NOT NULL default '0', |
| 16 |
|
grant_update tinyint(1) unsigned NOT NULL default '0', |
| 17 |
|
grant_delete tinyint(1) unsigned NOT NULL default '0', |
| 18 |
|
PRIMARY KEY (nid,gid,realm) |
| 19 |
|
)"); /*!40100 DEFAULT CHARACTER SET utf8 */ |
| 20 |
|
db_query("CREATE TABLE {nodeaccess_role_alias} ( |
| 21 |
|
rid int(10) unsigned NOT NULL default '0', |
| 22 |
|
name varchar(50) NOT NULL default '', |
| 23 |
|
weight int(3) NOT NULL default '0', |
| 24 |
|
PRIMARY KEY (rid) |
| 25 |
|
)"); |
| 26 |
|
break; |
| 27 |
|
case 'pgsql': |
| 28 |
|
db_query("CREATE TABLE {nodeaccess} ( |
| 29 |
|
nid int_unsigned NOT NULL default '0', |
| 30 |
|
gid int_unsigned NOT NULL default '0', |
| 31 |
|
realm varchar(255) NOT NULL default '', |
| 32 |
|
grant_view smallint_unsigned NOT NULL default '0', |
| 33 |
|
grant_update smallint_unsigned NOT NULL default '0', |
| 34 |
|
grant_delete smallint_unsigned NOT NULL default '0', |
| 35 |
|
PRIMARY KEY (nid,gid,realm) |
| 36 |
|
)"); |
| 37 |
|
db_query("CREATE TABLE {nodeaccess_role_alias} ( |
| 38 |
|
rid int_unsigned NOT NULL default '0', |
| 39 |
|
name varchar(50) NOT NULL default '', |
| 40 |
|
weight smallint NOT NULL default '0', |
| 41 |
|
PRIMARY KEY (rid) |
| 42 |
|
)"); |
| 43 |
|
break; |
| 44 |
|
} |
| 45 |
// Set up default permissions to be view for authenticated and |
// Set up default permissions to be view for authenticated and |
| 46 |
// anonymous users, and all permissions for author. |
// anonymous users, and all permissions for author. |
| 47 |
$grants = array(); |
$grants = array(); |
| 61 |
} |
} |
| 62 |
|
|
| 63 |
/** |
/** |
|
* Implementation of hook_schema(). |
|
|
*/ |
|
|
function nodeaccess_schema() { |
|
|
$schema['nodeaccess'] = array( |
|
|
'fields' => array( |
|
|
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
|
'gid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
|
'realm' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), |
|
|
'grant_view' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
|
'grant_update' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
|
'grant_delete' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) |
|
|
), |
|
|
'primary key' => array('nid', 'gid', 'realm') |
|
|
); |
|
|
$schema['nodeaccess_role_alias'] = array( |
|
|
'fields' => array( |
|
|
'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
|
|
'name' => array('type' => 'varchar', 'length' => 50, 'not null' => TRUE, 'default' => ''), |
|
|
'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) |
|
|
), |
|
|
'primary key' => array('rid') |
|
|
); |
|
|
return $schema; |
|
|
} |
|
|
|
|
|
/** |
|
| 64 |
* Implementations of hook_update_N(). |
* Implementations of hook_update_N(). |
| 65 |
*/ |
*/ |
| 66 |
function nodeaccess_update_1() { |
function nodeaccess_update_1() { |
| 67 |
// Create new nodeaccess table. |
// Create new nodeaccess table. |
| 68 |
$schema['nodeaccess'] = array( |
switch ($GLOBALS['db_type']) { |
| 69 |
'fields' => array( |
case 'mysql': |
| 70 |
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
case 'mysqli': |
| 71 |
'gid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
db_query("CREATE TABLE {nodeaccess} ( |
| 72 |
'realm' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), |
nid int(10) unsigned NOT NULL default '0', |
| 73 |
'grant_view' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
gid int(10) unsigned NOT NULL default '0', |
| 74 |
'grant_update' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
realm varchar(255) NOT NULL default '', |
| 75 |
'grant_delete' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) |
grant_view tinyint(1) unsigned NOT NULL default '0', |
| 76 |
), |
grant_update tinyint(1) unsigned NOT NULL default '0', |
| 77 |
'primary key' => array('nid', 'gid', 'realm') |
grant_delete tinyint(1) unsigned NOT NULL default '0', |
| 78 |
); |
PRIMARY KEY (nid,gid,realm) |
| 79 |
$ret = array(); |
)"); /*!40100 DEFAULT CHARACTER SET utf8 */ |
| 80 |
db_create_table($ret, 'nodeaccess', $schema['nodeaccess']); |
break; |
| 81 |
|
case 'pgsql': |
| 82 |
|
db_query("CREATE TABLE {nodeaccess} ( |
| 83 |
|
nid int_unsigned NOT NULL default '0', |
| 84 |
|
gid int_unsigned NOT NULL default '0', |
| 85 |
|
realm varchar(255) NOT NULL default '', |
| 86 |
|
grant_view smallint_unsigned NOT NULL default '0', |
| 87 |
|
grant_update smallint_unsigned NOT NULL default '0', |
| 88 |
|
grant_delete smallint_unsigned NOT NULL default '0', |
| 89 |
|
PRIMARY KEY (nid,gid,realm) |
| 90 |
|
)"); |
| 91 |
|
break; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
// Update format of content type specific variables. |
// Update format of content type specific variables. |
| 95 |
foreach (node_get_types() as $type => $name) { |
foreach (node_get_types() as $type => $name) { |
| 118 |
$row->nid, $row->gid, $row->realm, $row->grant_view, $row->grant_update, $row->grant_delete); |
$row->nid, $row->gid, $row->realm, $row->grant_view, $row->grant_update, $row->grant_delete); |
| 119 |
} |
} |
| 120 |
} |
} |
|
return $ret; |
|
| 121 |
} |
} |
| 122 |
|
|
| 123 |
function nodeaccess_update_2() { |
function nodeaccess_update_2() { |
| 127 |
|
|
| 128 |
function nodeaccess_update_3() { |
function nodeaccess_update_3() { |
| 129 |
// Create new nodeaccess_role_alias table. |
// Create new nodeaccess_role_alias table. |
| 130 |
$schema['nodeaccess_role_alias'] = array( |
switch ($GLOBALS['db_type']) { |
| 131 |
'fields' => array( |
case 'mysql': |
| 132 |
'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
case 'mysqli': |
| 133 |
'name' => array('type' => 'varchar', 'length' => 50, 'not null' => TRUE, 'default' => ''), |
db_query("CREATE TABLE {nodeaccess_role_alias} ( |
| 134 |
'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) |
rid int(10) unsigned NOT NULL default '0', |
| 135 |
), |
name varchar(50) NOT NULL default '', |
| 136 |
'primary key' => array('rid') |
weight int(3) NOT NULL default '0', |
| 137 |
); |
PRIMARY KEY (rid) |
| 138 |
$ret = array(); |
)"); |
| 139 |
db_create_table($ret, 'nodeaccess_role_alias', $schema['nodeaccess_role_alias']); |
break; |
| 140 |
|
case 'pgsql': |
| 141 |
|
db_query("CREATE TABLE {nodeaccess_role_alias} ( |
| 142 |
|
rid int_unsigned NOT NULL default '0', |
| 143 |
|
name varchar(50) NOT NULL default '', |
| 144 |
|
weight smallint NOT NULL default '0', |
| 145 |
|
PRIMARY KEY (rid) |
| 146 |
|
)"); |
| 147 |
|
break; |
| 148 |
|
} |
| 149 |
// Set up default alias names to match role names and default |
// Set up default alias names to match role names and default |
| 150 |
// weights to 0. Do this for allowed roles only. |
// weights to 0. Do this for allowed roles only. |
| 151 |
$allowedrole = variable_get('nodeaccess-roles', array()); |
$allowedrole = variable_get('nodeaccess-roles', array()); |
| 157 |
// Set up all permissions to be editable by default. |
// Set up all permissions to be editable by default. |
| 158 |
$grant_prefs = array('view' => 1, 'edit' => 1, 'delete' => 1); |
$grant_prefs = array('view' => 1, 'edit' => 1, 'delete' => 1); |
| 159 |
variable_set('nodeaccess-grants', $grant_prefs); |
variable_set('nodeaccess-grants', $grant_prefs); |
|
return $ret; |
|
| 160 |
} |
} |
| 161 |
|
|
| 162 |
/** |
/** |
| 174 |
variable_del('nodeaccess_' . $type); |
variable_del('nodeaccess_' . $type); |
| 175 |
} |
} |
| 176 |
// Remove tables. |
// Remove tables. |
| 177 |
drupal_uninstall_schema('nodeaccess'); |
db_query("DROP TABLE {nodeaccess}"); |
| 178 |
|
db_query("DROP TABLE {nodeaccess_role_alias}"); |
| 179 |
} |
} |
| 180 |
|
|
| 181 |
?> |
?> |