forked from gapple/drupal-persistent_login
-
Notifications
You must be signed in to change notification settings - Fork 0
/
persistent_login.install
executable file
·139 lines (125 loc) · 5.22 KB
/
persistent_login.install
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* @file
* Implementation of installation/uninstallation hooks.
*/
/**
* Implementation of hook_schema().
*/
function persistent_login_schema() {
$schema = array();
$schema['persistent_login'] = array(
'description' => 'Stores Persistent Login (PL) information for users that check Remember me when they log in. If this info matches an anonymous user\'s PL cookie, they are logged in automatically. See http://jaspan.com/improved_persistent_login_cookie_best_practice for details on the technique used.',
'fields' => array(
'uid' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1,
'description' => 'The {users}.uid this row is for.',
),
'series' => array('type' => 'varchar', 'length' => 32, 'not null' => 1,
'description' => 'The long-lived series identifying the PL token sequence.',
),
'token' => array('type' => 'varchar', 'length' => 32, 'not null' => 1,
'description' => 'The single-use PL login token.',
),
'expires' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1,
'description' => 'The expiration date for this series of tokens.',
),
),
'primary key' => array('uid', 'series'),
'indexes' => array(
'expires' => array('expires'),
'uid_expires' => array('uid', 'expires'),
),
);
$schema['persistent_login_history'] = array(
'description' => 'Stores previous entries from the {persistent_login} table just before they are erased; currently used. The uid, series, token, and expires fields are copied verbatim.',
'fields' => array(
'uid' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1),
'series' => array('type' => 'varchar', 'length' => 32, 'not null' => 1),
'token' => array('type' => 'varchar', 'length' => 32, 'not null' => 1),
'expires' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1),
'at' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1,
'description' => 'When this entry was copied from the {persistent_login} table.',
),
'why' => array('type' => 'varchar', 'length' => 255, 'not null' => 1,
'description' => 'Why this entry was deleted from the {persistent_login} table.',
),
),
'primary key' => array('uid', 'series', 'token'),
'indexes' => array(
'expires' => array('at'),
),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function persistent_login_install() {
drupal_install_schema('persistent_login');
}
/**
* Implementation of hook_uninstall().
*/
function persistent_login_uninstall() {
drupal_uninstall_schema('persistent_login');
// Delete all module variables.
variable_del('persistent_login_welcome');
variable_del('persistent_login_maxlife');
variable_del('persistent_login_maxlogins');
variable_del('persistent_login_secure');
variable_del('persistent_login_pages');
variable_del('persistent_login_cookie_prefix');
}
/**
* Update Persistent Login to Drupal 6.x. Previous versions of PL
* always re-created its tables from scratch at every update so we do
* not really know what state we are in. Luckily, PL data can be
* wiped safely; users will just have to log in again. So, here we
* drop and re-create the tables to a known state, and henceforth
* we'll know what we have.
*/
function persistent_login_update_6000() {
$ret = array();
// Some versions of persistent_login (wrongly) did not use hook_init
// and so may not have bootstrap set in the system table.
$ret[] = update_sql("UPDATE {system} SET bootstrap = 1 WHERE name = 'persistent_login'");
$ret[] = update_sql('DROP TABLE IF EXISTS {persistent_login}');
$ret[] = update_sql('DROP TABLE IF EXISTS {persistent_login_history}');
$schema['persistent_login'] = array(
'fields' => array(
'uid' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1),
'series' => array('type' => 'varchar', 'length' => 32, 'not null' => 1),
'token' => array('type' => 'varchar', 'length' => 32, 'not null' => 1),
'expires' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1),
),
'primary key' => array('uid', 'series'),
'indexes' => array(
'expires' => array('expires'),
),
);
db_create_table($ret, 'persistent_login', $schema['persistent_login']);
$schema['persistent_login_history'] = array(
'fields' => array(
'uid' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1),
'series' => array('type' => 'varchar', 'length' => 32, 'not null' => 1),
'token' => array('type' => 'varchar', 'length' => 32, 'not null' => 1),
'expires' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1),
'at' => array('type' => 'int', 'unsigned' => 1, 'not null' => 1),
'why' => array('type' => 'varchar', 'length' => 255, 'not null' => 1),
),
'primary key' => array('uid', 'series', 'token'),
'indexes' => array(
'expires' => array('at'),
),
);
db_create_table($ret, 'persistent_login_history', $schema['persistent_login_history']);
return $ret;
}
/**
* Add new index by uid, expires to Persistent Login table.
*/
function persistent_login_update_6001() {
$ret = array();
db_add_index($ret, 'persistent_login', 'uid_expires', array('uid', 'expires'));
return $ret;
}