-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombo_field_storage.module
More file actions
294 lines (258 loc) · 8.52 KB
/
combo_field_storage.module
File metadata and controls
294 lines (258 loc) · 8.52 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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
/**
* @file
* Implementation of the field storage API for MongoDB.
*/
/*
* Implements hook_views_data()
*
* Mocks the implementation of field_view_data on behalf of combo_field_storage fields
*
* Field modules can implement hook_field_views_data() to override
* the default behavior for adding fields as per usual.
*/
function combo_field_storage_views_data() {
$data = array();
foreach (field_info_fields() as $field) {
if ($field['storage']['type'] != 'combo_field_storage') {
continue;
}
$module = $field['module'];
$result = (array) module_invoke($module, 'field_views_data', $field);
if (empty($result)) {
$result = field_views_field_default_views_data($field);
}
drupal_alter('field_views_data', $result, $field, $module);
if (is_array($result)) {
$data = drupal_array_merge_deep($result, $data);
}
}
return $data;
}
/**
* Implements hook_field_storage_info().
*/
function combo_field_storage_field_storage_info() {
return array(
'combo_field_storage' => array(
'label' => t('Combo MongoDB and SQL field storage'),
'description' => t('Stores nodes and fields in both MongoDB and SQL.'),
),
);
}
/**
* Implements hook_field_storage_details().
*/
function combo_field_storage_field_storage_details($field) {
// Return the details on the SQL field
return field_sql_storage_field_storage_details($field);
}
/**
* Implements hook_field_storage_create_field().
*/
function combo_field_storage_field_storage_create_field($field) {
// Create the SQL tables
field_sql_storage_field_storage_create_field($field);
}
/**
* Implements hook_field_storage_update_field().
*/
function combo_field_storage_field_storage_update_field($field, $prior_field, $has_data) {
// Update the SQL tables
field_sql_storage_field_storage_update_field($field, $prior_field, $has_data);
}
/**
* Implements hook_field_storage_delete_field().
*/
function combo_field_storage_field_storage_delete_field($field) {
// Delete the SQL tables
field_sql_storage_field_storage_delete_field($field);
}
/**
* Implements hook_field_storage_load().
*/
function combo_field_storage_field_storage_load($entity_type, $entities, $age, $fields, $options) {
// Load entities only from MongoDB
return mongodb_field_storage_field_storage_load($entity_type, $entities, $age, $fields, $options);
}
/**
* Implements hook_field_storage_write().
*/
function combo_field_storage_field_storage_write($entity_type, $entity, $op, $fields, $entity_write = FALSE) {
// Write to both MongoDB and the SQL database
//mongodb_field_storage_field_storage_write($entity_type, $entity, $op, $fields, $entity_write);
//field_sql_storage_field_storage_write($entity_type, $entity, $op, $fields);
$args = array(
array(
'type' => 'function',
'call' => 'mongodb_field_storage_field_storage_write',
'args' => array($entity_type, $entity, $op, $fields, $entity_write),
),
array(
'type' => 'function',
'call' => 'field_sql_storage_field_storage_write',
'args' => array($entity_type, $entity, $op, $fields),
),
array(
'type' => 'function',
'call' => 'watchdog',
'args' => array('combo_field_storage_thread-httprl', 'non-dual insert done', array(), WATCHDOG_DEBUG),
),
);
combo_field_storage_nonblock($args);
}
/**
* Implement hook_field_storage_delete().
*
* This function deletes data for all fields for an entity from the database.
*/
function combo_field_storage_field_storage_delete($entity_type, $entity, $fields) {
// Delete from both MongoDB and the SQL database
//mongodb_field_storage_field_storage_delete($entity_type, $entity, $fields);
//field_sql_storage_field_storage_delete($entity_type, $entity, $fields);
$args = array(
array(
'type' => 'function',
'call' => 'mongodb_field_storage_field_storage_delete',
'args' => array($entity_type, $entity, $fields),
),
array(
'type' => 'function',
'call' => 'field_sql_storage_field_storage_delete',
'args' => array($entity_type, $entity, $fields),
),
array(
'type' => 'function',
'call' => 'watchdog',
'args' => array('combo_field_storage_thread-httprl', 'non-dual delete done', array(), WATCHDOG_DEBUG),
),
);
combo_field_storage_nonblock($args);
}
/**
* Implement hook_field_storage_delete_revision().
*
* This function actually deletes the data from the database.
*/
function combo_field_storage_field_storage_delete_revision($entity_type, $entity, $fields) {
// Delete from both MongoDB and the SQL database
//mongodb_field_storage_field_storage_delete_revision($entity_type, $entity, $fields);
//field_sql_storage_field_storage_delete_revision($entity_type, $entity, $fields);
$args = array(
array(
'type' => 'function',
'call' => 'mongodb_field_storage_field_storage_delete_revision',
'args' => array($entity_type, $entity, $fields),
),
array(
'type' => 'function',
'call' => 'field_sql_storage_field_storage_delete_revision',
'args' => array($entity_type, $entity, $fields),
),
array(
'type' => 'function',
'call' => 'watchdog',
'args' => array('combo_field_storage_thread-httprl', 'non-dual delete revision done', array(), WATCHDOG_DEBUG),
),
);
combo_field_storage_nonblock($args);
}
/**
* Implement hook_field_storage_delete_instance().
*
* This function simply marks for deletion all data associated with the field.
*/
function combo_field_storage_field_storage_delete_instance($instance) {
// Delete from both MongoDB and the SQL database
//mongodb_field_storage_field_storage_delete_instance($instance);
//field_sql_storage_field_storage_delete_instance($instance);
$args = array(
array(
'type' => 'function',
'call' => 'mongodb_field_storage_field_storage_delete_instance',
'args' => array($instance),
),
array(
'type' => 'function',
'call' => 'field_sql_storage_field_storage_delete_instance',
'args' => array($instance),
),
array(
'type' => 'function',
'call' => 'watchdog',
'args' => array('combo_field_storage_thread-httprl', 'non-dual delete instance done', array(), WATCHDOG_DEBUG),
),
);
combo_field_storage_nonblock($args);
}
/**
* Implements hook_entity_query_alter().
*
* Alter the entity info.
*/
function combo_field_storage_entity_query_alter($query) {
$query->executeCallback = 'combo_field_storage_query';
}
/**
* Implements hook_field_storage_query().
*
* Execute an EntityFieldQuery.
*/
function combo_field_storage_query($query) {
// Only do entity field queries on MongoDB
return mongodb_field_storage_query($query);
}
/**
* Implements hook_field_attach_rename_bundle().
*/
function combo_field_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
// Let MongoDB and the SQL database act on a bundle rename
//mongodb_combo_field_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new);
//field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new);
$args = array(
array(
'type' => 'function',
'call' => 'mongodb_combo_field_storage_field_attach_rename_bundle',
'args' => array($entity_type, $bundle_old, $bundle_new),
),
array(
'type' => 'function',
'call' => 'field_sql_storage_field_attach_rename_bundle',
'args' => array($entity_type, $bundle_old, $bundle_new),
),
array(
'type' => 'function',
'call' => 'watchdog',
'args' => array('combo_field_storage_thread-httprl', 'non-dual rename bundle done', array(), WATCHDOG_DEBUG),
),
);
combo_field_storage_nonblock($args);
}
/**
* Implements hook_field_attach_delete.
*/
function combo_field_storage_field_attach_delete($entity_type, $entity) {
// Delete entities in both MongoDB only
mongodb_field_storage_field_attach_delete($entity_type, $entity);
}
/**
* Helper function for httprl non-blocking
*/
function combo_field_storage_nonblock($args) {
// Bail out here if background callbacks are disabled.
if (!httprl_is_background_callback_capable()) {
return FALSE;
}
// Pass the current session to the sub request.
if (!empty($_COOKIE[session_name()])) {
$options = array('headers' => array('Cookie' => session_name() . '=' . $_COOKIE[session_name()] . ';'));
}
else {
$options = array();
}
$callback_options = array(array('options' => $options), &$args);
// Queue up the request.
httprl_queue_background_callback($callback_options);
// Execute request.
httprl_send_request();
}