forked from backdrop-contrib/flag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flag.install
278 lines (263 loc) · 8.46 KB
/
flag.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
/**
* @file
* Flag module install/schema/update hooks.
*/
/**
* Implements hook_schema().
*/
function flag_schema() {
$schema = array();
$schema['flag'] = array(
'description' => 'All available flags in the system.',
'fields' => array(
'fid' => array(
'description' => 'The unique ID for this particular flag.',
'type' => 'serial',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
),
'entity_type' => array(
'description' => 'The flag type, such as one of "node", "comment", or "user".',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
),
'name' => array(
'description' => 'The machine-name for this flag.',
'type' => 'varchar',
'length' => '32',
'not null' => FALSE,
'default' => '',
),
'title' => array(
'description' => 'The human-readable title for this flag.',
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'default' => '',
),
'global' => array(
'description' => 'Whether this flag state should act as a single toggle to all users across the site.',
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
'default' => 0,
),
'options' => array(
'description' => 'The options and configuration of this flag.',
'type' => 'text',
'not null' => FALSE,
),
),
'primary key' => array('fid'),
'unique keys' => array(
'name' => array('name'),
),
);
$schema['flagging'] = array(
'description' => 'Objects that have been flagged.',
'fields' => array(
'flagging_id' => array(
'description' => 'The unique ID for this particular tag.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'fid' => array(
'description' => 'The unique flag ID this object has been flagged with, from {flag}.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'entity_type' => array(
'description' => 'The flag type, eg "node", "comment", "user".',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
),
'entity_id' => array(
'description' => 'The unique ID of the object, such as either the {cid}, {uid}, or {nid}.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => 'The user ID by whom this object was flagged.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sid' => array(
'description' => "The user's numeric sid from the session_api table.",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'timestamp' => array(
'description' => 'The UNIX time stamp representing when the flag was set.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-size' => 11,
),
),
'primary key' => array('flagging_id'),
'unique keys' => array(
'fid_entity_id_uid_sid' => array('fid', 'entity_id', 'uid', 'sid'),
),
'indexes' => array(
'entity_type_uid_sid' => array('entity_type', 'uid', 'sid'),
'entity_type_entity_id_uid_sid' => array(
'entity_type',
'entity_id',
'uid',
'sid',
),
'entity_id_fid' => array('entity_id', 'fid'),
),
);
$schema['flag_types'] = array(
'description' => 'The entity bundles that are affected by a flag.',
'fields' => array(
'fid' => array(
'description' => 'The unqiue flag ID as defined for the flag in {flag}.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'type' => array(
'description' => 'The entity bundles that can be flagged by this fid.',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
),
),
'indexes' => array(
'fid' => array('fid'),
),
);
$schema['flag_counts'] = array(
'description' => 'The number of times an item has been flagged.',
'fields' => array(
'fid' => array(
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'entity_type' => array(
'description' => 'The flag type, usually one of "node", "comment", "user".',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
),
'entity_id' => array(
'description' => 'The unique ID of the content, usually either the {cid}, {uid}, or {nid}.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
'count' => array(
'description' => 'The number of times this object has been flagged for this flag.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-width' => '10',
),
'last_updated' => array(
'description' => 'The UNIX time stamp representing when the flag was last updated.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'disp-size' => 11,
),
),
'primary key' => array('fid', 'entity_id'),
'indexes' => array(
'fid_entity_type' => array('fid', 'entity_type'),
'entity_type_entity_id' => array('entity_type', 'entity_id'),
'fid_count' => array('fid', 'count'),
'fid_last_updated' => array('fid', 'last_updated'),
),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function flag_uninstall() {
backdrop_set_message(t('Flag has been uninstalled, but some per-flag permissions may remain (sorry).'));
}
/**
* Implements hook_requirements().
*/
function flag_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
if (module_exists('translation') && !module_exists('translation_helpers')) {
$requirements['flag_translation'] = array(
'title' => $t('Flag'),
'severity' => REQUIREMENT_ERROR,
'description' => $t('To have the flag module work with translations, you need to install and enable the <a href="http://drupal.org/project/translation_helpers">Translation helpers</a> module.'),
'value' => $t('Translation helpers module not found.'),
);
}
if (module_exists('session_api')) {
if (file_exists('./robots.txt')) {
$flag_path = url('flag') . '/';
// We don't use url() because this may return an absolute URL when
// language negotiation is set to 'domain'.
$flag_path = parse_url($flag_path, PHP_URL_PATH);
$robots_string = 'Disallow: ' . $flag_path;
$contents = file_get_contents('./robots.txt');
if (strpos($contents, $robots_string) === FALSE) {
$requirements['flag_robots'] = array(
'title' => $t('Flag robots.txt problem'),
'severity' => REQUIREMENT_WARNING,
'description' => $t('Flag module may currently be used with anonymous users, however the robots.txt file does not exclude the "@flag-path" path, which may cause search engines to randomly flag and unflag content when they index the site. It is highly recommended to add "@robots-string" to your robots.txt file (located in the root of your Backdrop CMS installation).', array('@flag-path' => $flag_path, '@robots-string' => $robots_string)),
'value' => $t('Search engines flagging content'),
);
}
}
}
}
return $requirements;
}
/**
* Implements hook_update_last_removed().
*/
function flag_update_last_removed() {
return 7306;
}
/**
* Move flag settings from variables to config.
*/
function flag_update_1000() {
// Migrate variables to config.
$config = config('flag.settings');
$config->set('flag_default_flag_status', update_variable_get('flag_default_flag_status', array()));
$config->save();
// @todo look for flag_[flag_name]_default_[node_type] variables?
// Delete variables.
update_variable_del('flag_default_flag_status');
}