-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinactive_user.module
More file actions
124 lines (110 loc) · 4.16 KB
/
inactive_user.module
File metadata and controls
124 lines (110 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* @file
* Contains inactive_user.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\EntityTypeInterface;
define('DAY_MINUS_FIVE_MINUTES', (60 * 60 * 23) + (60 * 55));
define('ONE_DAY', 60 * 60 * 24);
define('TWO_DAYS', 60 * 60 * 24 * 2);
define('THRE_DAYS', 60 * 60 * 24 * 3);
define('ONE_WEEK', 60 * 60 * 24 * 7);
define('TWO_WEEKS', 60 * 60 * 24 * 2 * 7);
define('THRE_WEEKS', 60 * 60 * 24 * 3 * 7);
define('FOUR_WEEKS', 60 * 60 * 24 * 4 * 7);
define('ONE_MONTH', 60 * 60 * 24 * 30);
define('TWO_MONTHS', 60 * 60 * 24 * 2 * 30);
define('THRE_MONTHS', 60 * 60 * 24 * 3 * 30);
define('SIX_MONTHS', 60 * 60 * 24 * 6 * 30);
define('NINE_MONTHS', 60 * 60 * 24 * 9 * 30);
define('ONE_YEAR', 60 * 60 * 24 * 365);
define('ONE_AND_HALF_YEARS', 60 * 60 * 24 * (365 + 182));
define('TWO_YEARS', 60 * 60 * 24 * 2 * 365);
/**
* Implements hook_help().
*/
function inactive_user_help($route_name,
RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the inactive_user module.
case 'help.page.inactive_user':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The inactive_user module provides Drupal administrators with an automatic
way to manage inactive user accounts. This module has two goals: to help
keep users coming back to your site by reminding them when they\'ve been away
for a configurable period of time, and to cleanup unused accounts.
One or more of the following actions can be automatically taken for users that
have exceeded configurable periods of inactivity:
- send an email to the user
- send an email to the site administrator
- block the account (a warning can first be issued, and notification can
be sent to the user and/or site administrator when the action occurs)
- delete the account (a warning can first be issued, and notification can
be sent to the user and/or site administrator when the action occurs)
- optionally prevent deletion of user that have created site content
All events triggered by this module are logged via the watchdog.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_cron().
*/
function inactive_user_cron() {
\Drupal::service('inactive_user.notify')->runCron();
}
/**
* Implements hook_entity_base_field_info().
*
* @param EntityTypeInterface $entity_type
*
* @return array
*/
function inactive_user_entity_base_field_info(EntityTypeInterface $entity_type) {
if ($entity_type->id() === 'user') {
// Add a property just to user.
$fields = [];
$fields['notified_admin'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Admin notifier'))
->setDescription(t('The user notifier flag.'));
$fields['notified_user'] = BaseFieldDefinition::create('boolean')
->setLabel(t('User notifier'))
->setDescription(t('The user notifier flag.'));
$fields['warned_user_block_timestamp'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Timestamp warning'))
->setDescription(t('The warned user block timestamp.'));
$fields['notified_user_block'] = BaseFieldDefinition::create('boolean')
->setLabel(t('User block warning'))
->setDescription(t('The user block warning flag.'));
$fields['notified_admin_block'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Admin block warning'))
->setDescription(t('The admin block warning flag.'));
$fields['warned_user_delete_timestamp'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('User delete timestamp'))
->setDescription(t('The user delete timestamp.'));
$fields['protected'] = BaseFieldDefinition::create('boolean')
->setLabel(t('User protected flag'))
->setDescription(t('The user protected flag.'));
return $fields;
}
}
/**
* Implements hook_mail().
*/
function inactive_user_mail($key,
&$message,
$params) {
$options = array(
'langcode' => $message['langcode'],
);
switch ($key) {
case 'inactive_user_notice':
$message['from'] = $params['from'];
$message['subject'] = $params['subject'];
$message['body'][] = $params['message'];
break;
}
}