simple_access.install in Simple Access 7.2
Same filename and directory in other branches
Installation for Simple Access
File
simple_access.installView source
<?php
/**
* @file
* Installation for Simple Access
*/
/**
* Implements hook_install().
*/
function simple_access_install() {
db_update('system')
->fields(array(
'weight' => 9,
))
->condition('name', 'simple_access')
->execute();
$t = get_t();
drupal_set_message($t('simple access has created the required tables.'));
}
/**
* Implements hook_uninstall().
*/
function simple_access_uninstall() {
variable_del('simple_access_display');
variable_del('simple_access_showgroups');
drupal_set_message(t('simple access has been uninstalled'));
}
/**
* Implements hook_enable().
*/
function simple_access_enable() {
drupal_set_message(t('To fully activate simple_access you also need to !rebuild_permissions.', array(
'!rebuild_permissions' => l(t('rebuild permissions'), 'admin/reports/status/rebuild'),
)));
}
/**
* Implements hook_disable().
*/
function simple_access_disable() {
drupal_set_message(t('To fully disable simple_access you also need to !rebuild_permissions.', array(
'!rebuild_permissions' => l(t('rebuild permissions'), 'admin/reports/status/rebuild'),
)));
}
/**
* Implements hook_schema().
*/
function simple_access_schema() {
$schema = array();
$schema['simple_access_node'] = array(
'description' => 'Define all permissions for each node',
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'gid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sa_view' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sa_update' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sa_delete' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'nid',
'gid',
),
);
$schema['simple_access_owner'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
'sa_view' => array(
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'disp-width' => '3',
),
'sa_update' => array(
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'disp-width' => '3',
),
'sa_delete' => array(
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'disp-width' => '3',
),
),
'primary key' => array(
'nid',
),
);
$schema['simple_access_groups'] = array(
'fields' => array(
'gid' => array(
'type' => 'serial',
'not null' => TRUE,
'disp-width' => '11',
),
'name' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
),
'weight' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'gid',
),
);
$schema['simple_access_roles'] = array(
'fields' => array(
'gid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'gid',
'rid',
),
);
$schema['simple_access_profiles'] = array(
'fields' => array(
'pid' => array(
'type' => 'serial',
'not null' => TRUE,
'disp-width' => '11',
),
'name' => array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
),
'weight' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'pid',
),
);
$schema['simple_access_profiles_access'] = array(
'fields' => array(
'pid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'gid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sa_view' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sa_update' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sa_delete' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'pid',
'gid',
),
);
$schema['simple_access_profiles_node'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'pid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'nid',
'pid',
),
);
return $schema;
}
/**
* Updates
*/
/**
* Implements hook_update_last_removed().
*/
function simple_access_update_last_removed() {
return 6201;
}
/**
* Fix up missing primary key on {simple_access_profiles_node}.
*/
function simple_access_update_7201() {
db_drop_primary_key('simple_access_profiles_node');
// Find any duplicate records and remove them so the index can be built.
$result = db_query('SELECT nid, pid FROM {simple_access_profiles_node} GROUP BY nid, pid HAVING COUNT(*) > 1');
foreach ($result as $row) {
db_query('DELETE FROM {simple_access_profiles_node} WHERE nid = :nid AND pid = :pid', array(
':nid' => $row->nid,
':pid' => $row->pid,
));
db_query('INSERT INTO {simple_access_profiles_node} (nid, pid) VALUES (:nid, :pid)', array(
':nid' => $row->nid,
':pid' => $row->pid,
));
}
db_add_primary_key('simple_access_profiles_node', array(
'nid',
'pid',
));
}
/**
* Update variable names.
*/
function simple_access_update_7202(&$sandbox) {
// Only write new variables when they are not default values.
$var = variable_get('sa_display', array(
'view',
));
if ($var != array(
'view',
)) {
variable_set('simple_access_display', $var);
}
$var = variable_get('sa_showgroups', 0);
if ($var != 0) {
variable_set('simple_access_showgroups', $var);
}
variable_del('sa_display');
variable_del('sa_showgroups');
return t('Updated variable names from sa_* to simple_access_*');
}
Functions
Name | Description |
---|---|
simple_access_disable | Implements hook_disable(). |
simple_access_enable | Implements hook_enable(). |
simple_access_install | Implements hook_install(). |
simple_access_schema | Implements hook_schema(). |
simple_access_uninstall | Implements hook_uninstall(). |
simple_access_update_7201 | Fix up missing primary key on {simple_access_profiles_node}. |
simple_access_update_7202 | Update variable names. |
simple_access_update_last_removed | Implements hook_update_last_removed(). |