This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
forked from drupalprojects/entityqueue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entityqueue.install
279 lines (259 loc) · 8.17 KB
/
entityqueue.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
279
<?php
/**
* @file
* Install, update and uninstall functions for the Entityqueue module.
*/
/**
* Implements hook_schema().
*/
function entityqueue_schema() {
$schema['entityqueue_queue'] = array(
'description' => 'Stores global information for each queue.',
// CTools exportability.
'export' => array(
'key' => 'name',
'identifier' => 'queue',
'primary key' => 'name',
'object' => 'EntityQueue',
'admin_title' => 'label',
'default hook' => 'entityqueue_default_queues',
'api' => array(
'owner' => 'entityqueue',
'api' => 'entityqueue_default',
'minimum_version' => 1,
'current_version' => 1,
),
'create callback' => 'entityqueue_queue_create',
'load callback' => 'entityqueue_queue_load',
'load multiple callback' => 'entityqueue_queue_load_multiple',
'save callback' => 'entityqueue_queue_save',
'delete callback' => 'entityqueue_queue_delete',
),
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The machine-readable name of this queue.',
),
'label' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The human-readable name of this queue.',
),
'language' => array(
'description' => 'The {languages}.language of this queue.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'handler' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The handler plugin that manages this queue.',
),
'target_type' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The target entity type of this queue.',
),
'settings' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'description' => 'Serialized settings containing the queue properties that do not warrant a dedicated column.',
),
),
'primary key' => array('name'),
);
$schema['entityqueue_subqueue'] = array(
'description' => 'Stores global information for each subqueue.',
'fields' => array(
'subqueue_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique subqueue ID.',
),
'queue' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The queue (bundle) of this subqueue.',
),
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The machine-readable name of this subqueue.',
),
'label' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The human-readable name of this subqueue.',
),
'language' => array(
'description' => 'The {languages}.language of this subqueue.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'module' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'The name of the module that created this subqueue.',
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
'description' => 'The {users}.uid who created this subqueue.',
),
'data' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'description' => 'Serialized data containing the subqueue properties that do not warrant a dedicated column.',
),
),
'primary key' => array('subqueue_id'),
'unique keys' => array(
'name' => array('name'),
),
'indexes' => array(
'queue' => array('queue'),
'module' => array('module'),
'uid' => array('uid'),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function entityqueue_install() {
// Add entityreference fields for queues that are defined in code.
$install = &drupal_static(__FUNCTION__);
$install = TRUE;
$queues = ctools_export_crud_load_all('entityqueue_queue');
foreach ($queues as $name => $queue) {
if (!empty($queue->in_code_only)) {
_entityqueue_queue_ensure_instance($queue);
}
}
$install = FALSE;
entity_info_cache_clear();
}
/**
* Implements hook_uninstall().
*/
function entityqueue_uninstall() {
// Delete entityqueue's field instances.
$queues = variable_get('entityqueue_queue_names', array());
foreach ($queues as $name) {
field_attach_delete_bundle('entityqueue_subqueue', $name);
}
// Build an array of entityreference field names created by entityqueue.
$eq_fields = variable_get('entityqueue_field_names', array());
$eq_fields = array_unique($eq_fields);
// Remove fields attached to entity queues (bundles).
foreach ($eq_fields as $field_name) {
field_delete_field($field_name);
}
variable_del('entityqueue_queue_names');
variable_del('entityqueue_field_names');
}
/**
* Add "language" column to all entityqueue tables.
*/
function entityqueue_update_7000() {
// Update the existing entities, with the default language.
$langcode = language_default()->language;
// Add column to main queue table and update existing queues.
$column = array(
'description' => 'The {languages}.language of this queue.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
);
db_add_field('entityqueue_queue', 'language', $column);
db_update('entityqueue_queue')
->fields(array(
'language' => $langcode,
))
->execute();
// Add column to subqueue table and update existing subqueues.
$column = array(
'description' => 'The {languages}.language of this subqueue.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
);
db_add_field('entityqueue_subqueue', 'language', $column);
db_update('entityqueue_subqueue')
->fields(array(
'language' => $langcode,
))
->execute();
}
/**
* Sets variables for keeping track of field names and queue names.
*/
function entityqueue_update_7001() {
module_load_include('module', 'entityqueue');
ctools_include('export');
ctools_include('entityqueue_queue.class', 'entityqueue');
// Retrieve all queues (from database + default queues).
$db_queues = db_query("SELECT name, target_type FROM {entityqueue_queue}")->fetchAllKeyed();
$entityqueue_schema = entityqueue_schema();
$default_queues = _ctools_export_get_defaults('entityqueue_queue', $entityqueue_schema['entityqueue_queue']['export']);
$queue_names = array_merge(array_keys($db_queues), array_keys($default_queues));
variable_set('entityqueue_queue_names', $queue_names);
$target_types = array_unique(array_values($db_queues));
foreach ($default_queues as $queue) {
if (!in_array($queue->target_type, $target_types)) {
$target_types[] = $queue->target_type;
}
}
$field_names = array();
foreach ($target_types as $target_type) {
$field_names[] = _entityqueue_get_target_field_name($target_type);
}
variable_set('entityqueue_field_names', $field_names);
// Mark the update as no longer broken.
variable_set('entityqueue_broken_update_7001', FALSE);
}
/**
* Re-runs the fixed version of entityqueue_update_7001().
*
* @see http://www.drupal.org/node/2297599
*/
function entityqueue_update_7002() {
$ret = '';
if (variable_get('entityqueue_broken_update_7001', TRUE)) {
$ret = t('Ran fixed version of entityqueue_update_7001.');
entityqueue_update_7001(); // Run the update again.
}
// Now that the update is complete, we can remove our variable, since this
// update won't run again.
variable_del('entityqueue_broken_update_7001');
return $ret;
}