| 5 |
*/ |
*/ |
| 6 |
function nodeaccess_install() { |
function nodeaccess_install() { |
| 7 |
// Create tables. |
// Create tables. |
| 8 |
switch ($GLOBALS['db_type']) { |
drupal_install_schema('nodeaccess'); |
|
case 'mysql': |
|
|
case 'mysqli': |
|
|
db_query("CREATE TABLE {nodeaccess} ( |
|
|
nid int(10) unsigned NOT NULL default '0', |
|
|
gid int(10) unsigned NOT NULL default '0', |
|
|
realm varchar(255) NOT NULL default '', |
|
|
grant_view tinyint(1) unsigned NOT NULL default '0', |
|
|
grant_update tinyint(1) unsigned NOT NULL default '0', |
|
|
grant_delete tinyint(1) unsigned NOT NULL default '0', |
|
|
PRIMARY KEY (nid,gid,realm) |
|
|
)"); /*!40100 DEFAULT CHARACTER SET utf8 */ |
|
|
db_query("CREATE TABLE {nodeaccess_role_alias} ( |
|
|
rid int(10) unsigned NOT NULL default '0', |
|
|
name varchar(50) NOT NULL default '', |
|
|
weight int(3) NOT NULL default '0', |
|
|
PRIMARY KEY (rid) |
|
|
)"); |
|
|
break; |
|
|
case 'pgsql': |
|
|
db_query("CREATE TABLE {nodeaccess} ( |
|
|
nid int_unsigned NOT NULL default '0', |
|
|
gid int_unsigned NOT NULL default '0', |
|
|
realm varchar(255) NOT NULL default '', |
|
|
grant_view smallint_unsigned NOT NULL default '0', |
|
|
grant_update smallint_unsigned NOT NULL default '0', |
|
|
grant_delete smallint_unsigned NOT NULL default '0', |
|
|
PRIMARY KEY (nid,gid,realm) |
|
|
)"); |
|
|
db_query("CREATE TABLE {nodeaccess_role_alias} ( |
|
|
rid int_unsigned NOT NULL default '0', |
|
|
name varchar(50) NOT NULL default '', |
|
|
weight smallint NOT NULL default '0', |
|
|
PRIMARY KEY (rid) |
|
|
)"); |
|
|
break; |
|
|
} |
|
| 9 |
// Set up default permissions to be view for authenticated and |
// Set up default permissions to be view for authenticated and |
| 10 |
// anonymous users, and all permissions for author. |
// anonymous users, and all permissions for author. |
| 11 |
$grants = array(); |
$grants = array(); |
| 25 |
} |
} |
| 26 |
|
|
| 27 |
/** |
/** |
| 28 |
|
* Implementation of hook_schema(). |
| 29 |
|
*/ |
| 30 |
|
function nodeaccess_schema() { |
| 31 |
|
$schema['nodeaccess'] = array( |
| 32 |
|
'fields' => array( |
| 33 |
|
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 34 |
|
'gid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 35 |
|
'realm' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), |
| 36 |
|
'grant_view' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 37 |
|
'grant_update' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 38 |
|
'grant_delete' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) |
| 39 |
|
), |
| 40 |
|
'primary key' => array('nid', 'gid', 'realm') |
| 41 |
|
); |
| 42 |
|
$schema['nodeaccess_role_alias'] = array( |
| 43 |
|
'fields' => array( |
| 44 |
|
'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 45 |
|
'name' => array('type' => 'varchar', 'length' => 50, 'not null' => TRUE, 'default' => ''), |
| 46 |
|
'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) |
| 47 |
|
), |
| 48 |
|
'primary key' => array('rid') |
| 49 |
|
); |
| 50 |
|
return $schema; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
/** |
| 54 |
* Implementations of hook_update_N(). |
* Implementations of hook_update_N(). |
| 55 |
*/ |
*/ |
| 56 |
function nodeaccess_update_1() { |
function nodeaccess_update_1() { |
| 57 |
// Create new nodeaccess table. |
// Create new nodeaccess table. |
| 58 |
switch ($GLOBALS['db_type']) { |
$schema['nodeaccess'] = array( |
| 59 |
case 'mysql': |
'fields' => array( |
| 60 |
case 'mysqli': |
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 61 |
db_query("CREATE TABLE {nodeaccess} ( |
'gid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 62 |
nid int(10) unsigned NOT NULL default '0', |
'realm' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), |
| 63 |
gid int(10) unsigned NOT NULL default '0', |
'grant_view' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 64 |
realm varchar(255) NOT NULL default '', |
'grant_update' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 65 |
grant_view tinyint(1) unsigned NOT NULL default '0', |
'grant_delete' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0) |
| 66 |
grant_update tinyint(1) unsigned NOT NULL default '0', |
), |
| 67 |
grant_delete tinyint(1) unsigned NOT NULL default '0', |
'primary key' => array('nid', 'gid', 'realm') |
| 68 |
PRIMARY KEY (nid,gid,realm) |
); |
| 69 |
)"); /*!40100 DEFAULT CHARACTER SET utf8 */ |
$ret = array(); |
| 70 |
break; |
db_create_table($ret, 'nodeaccess', $schema['nodeaccess']); |
|
case 'pgsql': |
|
|
db_query("CREATE TABLE {nodeaccess} ( |
|
|
nid int_unsigned NOT NULL default '0', |
|
|
gid int_unsigned NOT NULL default '0', |
|
|
realm varchar(255) NOT NULL default '', |
|
|
grant_view smallint_unsigned NOT NULL default '0', |
|
|
grant_update smallint_unsigned NOT NULL default '0', |
|
|
grant_delete smallint_unsigned NOT NULL default '0', |
|
|
PRIMARY KEY (nid,gid,realm) |
|
|
)"); |
|
|
break; |
|
|
} |
|
| 71 |
|
|
| 72 |
// Update format of content type specific variables. |
// Update format of content type specific variables. |
| 73 |
foreach (node_get_types() as $type => $name) { |
foreach (node_get_types() as $type => $name) { |
| 96 |
$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); |
| 97 |
} |
} |
| 98 |
} |
} |
| 99 |
|
return $ret; |
| 100 |
} |
} |
| 101 |
|
|
| 102 |
function nodeaccess_update_2() { |
function nodeaccess_update_2() { |
| 106 |
|
|
| 107 |
function nodeaccess_update_3() { |
function nodeaccess_update_3() { |
| 108 |
// Create new nodeaccess_role_alias table. |
// Create new nodeaccess_role_alias table. |
| 109 |
switch ($GLOBALS['db_type']) { |
$schema['nodeaccess_role_alias'] = array( |
| 110 |
case 'mysql': |
'fields' => array( |
| 111 |
case 'mysqli': |
'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), |
| 112 |
db_query("CREATE TABLE {nodeaccess_role_alias} ( |
'name' => array('type' => 'varchar', 'length' => 50, 'not null' => TRUE, 'default' => ''), |
| 113 |
rid int(10) unsigned NOT NULL default '0', |
'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) |
| 114 |
name varchar(50) NOT NULL default '', |
), |
| 115 |
weight int(3) NOT NULL default '0', |
'primary key' => array('rid') |
| 116 |
PRIMARY KEY (rid) |
); |
| 117 |
)"); |
$ret = array(); |
| 118 |
break; |
db_create_table($ret, 'nodeaccess_role_alias', $schema['nodeaccess_role_alias']); |
|
case 'pgsql': |
|
|
db_query("CREATE TABLE {nodeaccess_role_alias} ( |
|
|
rid int_unsigned NOT NULL default '0', |
|
|
name varchar(50) NOT NULL default '', |
|
|
weight smallint NOT NULL default '0', |
|
|
PRIMARY KEY (rid) |
|
|
)"); |
|
|
break; |
|
|
} |
|
| 119 |
// Set up default alias names to match role names and default |
// Set up default alias names to match role names and default |
| 120 |
// weights to 0. Do this for allowed roles only. |
// weights to 0. Do this for allowed roles only. |
| 121 |
$allowedrole = variable_get('nodeaccess-roles', array()); |
$allowedrole = variable_get('nodeaccess-roles', array()); |
| 127 |
// Set up all permissions to be editable by default. |
// Set up all permissions to be editable by default. |
| 128 |
$grant_prefs = array('view' => 1, 'edit' => 1, 'delete' => 1); |
$grant_prefs = array('view' => 1, 'edit' => 1, 'delete' => 1); |
| 129 |
variable_set('nodeaccess-grants', $grant_prefs); |
variable_set('nodeaccess-grants', $grant_prefs); |
| 130 |
|
return $ret; |
| 131 |
} |
} |
| 132 |
|
|
| 133 |
/** |
/** |
| 145 |
variable_del('nodeaccess_' . $type); |
variable_del('nodeaccess_' . $type); |
| 146 |
} |
} |
| 147 |
// Remove tables. |
// Remove tables. |
| 148 |
db_query("DROP TABLE {nodeaccess}"); |
drupal_uninstall_schema('nodeaccess'); |
|
db_query("DROP TABLE {nodeaccess_role_alias}"); |
|
| 149 |
} |
} |
| 150 |
|
|
| 151 |
?> |
?> |