profile2.install
5.89 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
* @file
* Install, update and uninstall functions for the profile module.
*/
/**
* Implements hook_install().
*/
function profile2_install() {
// Add an initial profile type, but only if installed manually. In case the
// module is installed via an installation profile, skip that.
if (!drupal_installation_attempted()) {
$type = entity_create('profile2_type', array(
'type' => 'main',
'label' => t('Main profile'),
'weight' => 0,
'data' => array('registration' => TRUE, 'use_page' => TRUE),
));
$type->save();
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('edit own main profile', 'view own main profile'));
drupal_set_message(t('A main profile type has been created and assigned to all users. Go to the <a href="!url">Profile types</a> page to add some fields or to configure further profile types.', array('!url' => url('admin/structure/profiles'))));
}
}
/**
* Implements hook_schema().
*/
function profile2_schema() {
$schema['profile'] = array(
'description' => 'Stores profile items.',
'fields' => array(
'pid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique profile item ID.',
),
'type' => array(
'description' => 'The {profile_type}.type of this profile.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
'description' => "The {users}.uid of the associated user.",
),
'label' => array(
'description' => 'A human-readable label for this profile.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the profile was created.',
'type' => 'int',
'not null' => FALSE,
),
'changed' => array(
'description' => 'The Unix timestamp when the profile was most recently saved.',
'type' => 'int',
'not null' => FALSE,
),
),
'indexes' => array(
'uid' => array('uid'),
),
'foreign keys' => array(
'uid' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'type' => array(
'table' => 'profile_type',
'columns' => array('type' => 'type'),
),
),
'primary key' => array('pid'),
);
$schema['profile_type'] = array(
'description' => 'Stores information about all defined profile types.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique profile type ID.',
),
'type' => array(
'description' => 'The machine-readable name of this profile type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The human-readable name of this profile type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'The weight of this profile type in relation to others.',
),
'data' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of additional data related to this profile type.',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// Set the default to ENTITY_CUSTOM without using the constant as it is
// not safe to use it at this point.
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('id'),
'unique keys' => array(
'type' => array('type'),
),
);
return $schema;
}
/**
* Add in the exportable entity db columns as required by the entity API.
*/
function profile2_update_7100() {
db_add_field('profile_type', 'status', array(
'type' => 'int',
'not null' => TRUE,
'default' => ENTITY_CUSTOM,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
));
db_add_field('profile_type', 'module', array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
));
}
/**
* Add a label column to profiles.
*/
function profile2_update_7101() {
db_add_field('profile', 'label', array(
'description' => 'A human-readable label for this profile.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
$types = db_select('profile_type', 'p')
->fields('p')
->execute()
->fetchAllAssoc('type');
// Initialize with the type label.
foreach ($types as $type_name => $type) {
db_update('profile')
->fields(array(
'label' => $type->label,
))
->condition('type', $type_name)
->execute();
}
}
/**
* Add a created and a changed column to profiles.
*/
function profile2_update_7102() {
db_add_field('profile', 'created', array(
'description' => 'The Unix timestamp when the profile was created.',
'type' => 'int',
'not null' => FALSE,
));
db_add_field('profile', 'changed', array(
'description' => 'The Unix timestamp when the profile was most recently saved.',
'type' => 'int',
'not null' => FALSE,
));
}