Révision 4eeb3b46
Ajouté par Assos Assos il y a presque 8 ans
drupal7/sites/all/modules/uuid/uuid.core.inc | ||
---|---|---|
32 | 32 |
if ($entity_type == 'node') { |
33 | 33 |
entity_property_uuid_to_id($entity, 'user', array('uid', 'revision_uid')); |
34 | 34 |
entity_property_uuid_to_id($entity, 'node', 'tnid'); |
35 |
|
|
36 |
// A node always must have an author. |
|
37 |
if (empty($entity->uid)) { |
|
38 |
global $user; |
|
39 |
$entity->uid = $user->uid; |
|
40 |
} |
|
35 | 41 |
} |
36 | 42 |
} |
37 | 43 |
|
... | ... | |
39 | 45 |
* Implements hook_entity_uuid_save(). |
40 | 46 |
*/ |
41 | 47 |
function node_entity_uuid_save(&$entity, $entity_type) { |
42 |
// When a node is translated, the source node's tnid is set to it's own nid. When deploying |
|
43 |
// the node for the first time the tnid can't be translated to an nid until after the node has been saved. |
|
44 |
// So if the entity's tnid is still a uuid at this point it needs to be translated to an nid. |
|
48 |
/* |
|
49 |
* When a node is translated, the source node's tnid is set to it's own nid. |
|
50 |
* When deploying the node for the first time the tnid can't be translated |
|
51 |
* to an nid until after the node has been saved. So if the entity's tnid |
|
52 |
* is still a uuid at this point it needs to be translated to an nid. |
|
53 |
*/ |
|
45 | 54 |
if ($entity_type == 'node' && uuid_is_valid($entity->tnid)) { |
46 | 55 |
entity_property_uuid_to_id($entity, 'node', 'tnid'); |
47 | 56 |
db_update('node') |
... | ... | |
80 | 89 |
* Implements hook_entity_uuid_presave(). |
81 | 90 |
*/ |
82 | 91 |
function user_entity_uuid_presave(&$entity, $entity_type) { |
83 |
if ($entity_type == 'user') { |
|
84 |
if (!empty($entity->picture)) { |
|
85 |
$uuids = entity_get_id_by_uuid('file', array($entity->picture['uuid'])); |
|
86 |
$fid = current($uuids); |
|
87 |
if (!$entity->is_new) { |
|
88 |
$entity->picture = file_load($fid); |
|
89 |
} |
|
90 |
else { |
|
91 |
$entity->picture = $fid; |
|
92 |
} |
|
93 |
} |
|
92 |
if ($entity_type != 'user') { |
|
93 |
return; |
|
94 |
} |
|
95 |
|
|
96 |
/* |
|
97 |
* We need to ensure new user's passwords are encrypted. The Services module |
|
98 |
* transparently encrypts the password for new users. md5() is used by |
|
99 |
* users who's accounts were migrated from Drupal 6 and who haven't updated |
|
100 |
* their password. |
|
101 |
*/ |
|
102 |
if (isset($entity->pass) |
|
103 |
&& (!('$S$D' == substr($entity->pass, 0, 4)) || preg_match('/^[a-f0-9]{32}$/', $entity->pass))) { |
|
104 |
// Ensure user's password is hashed. |
|
105 |
$entity->pass = user_hash_password($entity->pass); |
|
106 |
} |
|
107 |
|
|
108 |
if (empty($entity->picture)) { |
|
109 |
return; |
|
110 |
} |
|
111 |
|
|
112 |
$uuids = entity_get_id_by_uuid('file', array($entity->picture['uuid'])); |
|
113 |
$fid = current($uuids); |
|
114 |
if (!$entity->is_new) { |
|
115 |
$entity->picture = file_load($fid); |
|
116 |
} |
|
117 |
else { |
|
118 |
$entity->picture = $fid; |
|
94 | 119 |
} |
95 | 120 |
} |
96 | 121 |
|
... | ... | |
120 | 145 |
break; |
121 | 146 |
|
122 | 147 |
case 'comment': |
148 |
// entity_make_entity_local() may have unset cid, add back if necessary. |
|
149 |
if (!isset($entity->cid)) { |
|
150 |
$entity->cid = NULL; |
|
151 |
} |
|
123 | 152 |
entity_property_uuid_to_id($entity, 'user', array('uid', 'u_uid')); |
124 | 153 |
entity_property_uuid_to_id($entity, 'node', 'nid'); |
125 | 154 |
break; |
... | ... | |
140 | 169 |
*/ |
141 | 170 |
function file_entity_uuid_presave(&$entity, $entity_type) { |
142 | 171 |
if ($entity_type == 'file') { |
172 |
// entity_make_entity_local() may have unset fid, add back if necessary. |
|
173 |
if (!isset($entity->fid)) { |
|
174 |
$entity->fid = NULL; |
|
175 |
} |
|
143 | 176 |
entity_property_uuid_to_id($entity, 'user', 'uid'); |
144 | 177 |
|
145 | 178 |
// Write the new file to the local filesystem. |
146 |
if (isset($entity->file_contents)) { |
|
179 |
if (isset($entity->file_contents) && !empty($entity->filesize)) {
|
|
147 | 180 |
// Don't try to write it if it uses a stream wrapper that isn't writeable |
148 | 181 |
// (for example, if it is a remotely-hosted video). |
149 | 182 |
$scheme = file_uri_scheme($entity->uri); |
... | ... | |
185 | 218 |
} |
186 | 219 |
|
187 | 220 |
$directory = drupal_dirname($uri); |
188 |
file_prepare_directory($directory, FILE_CREATE_DIRECTORY); |
|
189 |
$entity->uri = file_unmanaged_save_data(base64_decode($entity->file_contents), $uri, $replace); |
|
221 |
if (!empty($directory) && file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) { |
|
222 |
$entity->uri = file_unmanaged_save_data(base64_decode($entity->file_contents), $uri, $replace); |
|
223 |
} |
|
190 | 224 |
} |
191 | 225 |
} |
192 | 226 |
} |
... | ... | |
230 | 264 |
* Implements hook_entity_uuid_load(). |
231 | 265 |
*/ |
232 | 266 |
function field_entity_uuid_load(&$entities, $entity_type) { |
233 |
foreach ($entities as $i => $entity) {
|
|
267 |
foreach ($entities as $entity) { |
|
234 | 268 |
list(, , $bundle_name) = entity_extract_ids($entity_type, $entity); |
235 | 269 |
$instances = field_info_instances($entity_type, $bundle_name); |
236 | 270 |
|
... | ... | |
327 | 361 |
|
328 | 362 |
/** |
329 | 363 |
* Implements hook_field_uuid_load(). |
364 |
* |
|
330 | 365 |
* Kept here because it is in D8 core. |
331 | 366 |
*/ |
332 | 367 |
function entityreference_field_uuid_load($entity_type, $entity, $field, $instance, $langcode, &$items) { |
... | ... | |
337 | 372 |
|
338 | 373 |
/** |
339 | 374 |
* Implements hook_field_uuid_presave(). |
375 |
* |
|
340 | 376 |
* Kept here because it is in D8 core. |
341 | 377 |
*/ |
342 | 378 |
function entityreference_field_uuid_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { |
... | ... | |
358 | 394 |
* Implements hook_uuid_entities_features_export_entity_alter(). |
359 | 395 |
*/ |
360 | 396 |
function node_uuid_entities_features_export_entity_alter(&$entity, $entity_type) { |
361 |
if ($entity_type == 'node') { |
|
362 |
foreach (array('data', 'name', 'picture', 'revision_uid', 'last_comment_timestamp') as $property) { |
|
363 |
if (property_exists($entity, $property)) { |
|
364 |
unset($entity->{$property}); |
|
365 |
} |
|
397 |
if ('node' != $entity_type) { |
|
398 |
return; |
|
399 |
} |
|
400 |
|
|
401 |
$properties = array( |
|
402 |
'data', |
|
403 |
'name', |
|
404 |
'picture', |
|
405 |
'revision_uid', |
|
406 |
'last_comment_timestamp', |
|
407 |
); |
|
408 |
foreach ($properties as $property) { |
|
409 |
if (property_exists($entity, $property)) { |
|
410 |
unset($entity->{$property}); |
|
366 | 411 |
} |
367 | 412 |
} |
368 | 413 |
} |
369 | 414 |
|
370 | 415 |
/** |
371 |
* Implementations hook_uuid_entities_features_export_entity_alter().
|
|
416 |
* Implements hook_uuid_entities_features_export_entity_alter(). |
|
372 | 417 |
*/ |
373 | 418 |
function user_uuid_entities_features_export_entity_alter(&$entity, $entity_type) { |
374 |
if ($entity_type == 'user') { |
|
375 |
foreach (array('data', 'access', 'login') as $property) { |
|
376 |
if (property_exists($entity, $property)) { |
|
377 |
unset($entity->{$property}); |
|
378 |
} |
|
419 |
if ('user' != $entity_type) { |
|
420 |
return; |
|
421 |
} |
|
422 |
|
|
423 |
foreach (array('data', 'access', 'login') as $property) { |
|
424 |
if (property_exists($entity, $property)) { |
|
425 |
unset($entity->{$property}); |
|
379 | 426 |
} |
380 | 427 |
} |
381 | 428 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules