Commit fb2e1f8c authored by Bobík's avatar Bobík
Browse files

Issue #1182006 by Seph - Automatic expiration of authkeys.

parent a7a7d2af
......@@ -65,16 +65,21 @@ function node_authlink_update_7100(&$sandbox) {
// Cleanup
field_delete_field('field_node_authlink_authkey');
}
function node_authlink_update_7101(&$sandbox) {
variable_del('node_authlink_types');
}
/**
* Inplementation of hook_uninstall().
*/
function node_authlink_uninstall() {
$node_types = variable_get('node_authlink_types', array());
variable_del('node_authlink_types');
$node_types = node_type_get_types();
foreach ($node_types as $node_type)
variable_del('node_authlink_type_' . $node_type . '_grants');
foreach ($node_types as $node_type) {
variable_del('node_authlink_enable_' . $node_type->type);
variable_del('node_authlink_grants_' . $node_type->type);
variable_del('node_authlink_expire_' . $node_type->type);
}
}
......
......@@ -32,6 +32,17 @@ function node_authlink_form_node_type_form_alter(&$form, &$form_state) {
'#description' => t('What operations will be temporarily given to authorised user for the node. This not affect users who is authorised yet.'),
);
// Time periods: none, 1 day, 1 week, 4 weeks
$period = drupal_map_assoc(array(0, 86400, 604800, 2419200), 'format_interval');
$period[0] = '<' . t('disabled') . '>';
$form['node_authlink']['node_authlink_expire'] = array(
'#type' => 'select',
'#title' => t('Regenerate authkeys after'),
'#default_value' => variable_get('node_authlink_expire_' . $form['#node_type']->type, 0),
'#options' => $period,
'#description' => t('Keys older than selected time will be regenerated by cron run.'),
);
$form['node_authlink']['node_authlink_batch'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
......@@ -221,4 +232,33 @@ function node_authlink_node_insert($node) {
->execute();
}
/**
* Implementation of hook_cron().
*/
function node_authlink_cron() {
$node_types = node_type_get_types();
foreach ($node_types as $type) {
$expire = variable_get('node_authlink_expire_' . $type->type, 0);
if(!$expire)
continue;
// NIDs of expired keys
$query = db_select('node', 'n');
$query->leftJoin('node_authlink_nodes', 'a', 'n.nid = a.nid');
$query->fields('n', array('nid'))
->condition('n.type', $type->type)
->condition('a.created', time() - $expire, '<');
$nids = $query->execute()->fetchCol();
// Regenerate keys
foreach ($nids as $nid) {
db_delete('node_authlink_nodes')
->condition('nid', $nid)
->execute();
node_authlink_node_insert($nid);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment