Révision 4eeb3b46
Ajouté par Assos Assos il y a presque 8 ans
drupal7/sites/all/modules/uuid/uuid.entity.inc | ||
---|---|---|
11 | 11 |
class UuidEntityException extends Exception {} |
12 | 12 |
|
13 | 13 |
/** |
14 |
* Helper function that returns entity info for all supported core modules, |
|
15 |
* relevant for UUID functionality. |
|
14 |
* Returns entity info for all supported core entities. |
|
16 | 15 |
* |
17 | 16 |
* @see uuid_entity_info() |
18 | 17 |
* @see uuid_schema_alter() |
... | ... | |
98 | 97 |
*/ |
99 | 98 |
function uuid_entity_property_info_alter(&$info) { |
100 | 99 |
foreach (entity_get_info() as $entity_type => $entity_info) { |
101 |
if (isset($entity_info['uuid']) && $entity_info['uuid'] == TRUE
|
|
100 |
if (isset($entity_info['uuid']) && $entity_info['uuid'] == TRUE |
|
102 | 101 |
&& !empty($entity_info['entity keys']['uuid']) |
103 | 102 |
&& empty($info[$entity_type]['properties'][$entity_info['entity keys']['uuid']])) { |
104 | 103 |
$info[$entity_type]['properties'][$entity_info['entity keys']['uuid']] = array( |
... | ... | |
107 | 106 |
'description' => t('The universally unique ID.'), |
108 | 107 |
'schema field' => $entity_info['entity keys']['uuid'], |
109 | 108 |
); |
110 |
if (!empty($entity_info['entity keys']['revision uuid'])
|
|
109 |
if (!empty($entity_info['entity keys']['revision uuid']) |
|
111 | 110 |
&& empty($info[$entity_type]['properties'][$entity_info['entity keys']['revision uuid']])) { |
112 | 111 |
$info[$entity_type]['properties'][$entity_info['entity keys']['revision uuid']] = array( |
113 | 112 |
'label' => t('Revision UUID'), |
... | ... | |
341 | 340 |
} |
342 | 341 |
} |
343 | 342 |
else { |
344 |
throw new UuidEntityException(t('Trying to operate on a @type entity, which doesn\'t support UUIDs.', array('@type' => $info['label'])));
|
|
343 |
throw new UuidEntityException(t("Trying to operate on a @type entity, which doesn\'t support UUIDs.", array('@type' => $info['label'])));
|
|
345 | 344 |
} |
346 | 345 |
} |
347 | 346 |
|
... | ... | |
382 | 381 |
return entity_delete($entity_type, $id); |
383 | 382 |
} |
384 | 383 |
else { |
385 |
throw new UuidEntityException(t('Trying to delete a @type entity, which doesn\'t support UUIDs.', array('@type' => $info['label'])));
|
|
384 |
throw new UuidEntityException(t("Trying to delete a @type entity, which doesn\'t support UUIDs.", array('@type' => $info['label'])));
|
|
386 | 385 |
} |
387 | 386 |
} |
388 | 387 |
|
... | ... | |
392 | 391 |
* @todo |
393 | 392 |
* Limit the query. |
394 | 393 |
* |
395 |
* @param $entity_type |
|
394 |
* @param string $entity_type
|
|
396 | 395 |
* The entity type we should be dealing with. |
397 |
* @param $uuids |
|
398 |
* An array of UUIDs for which we should find their entity IDs. If $revision
|
|
396 |
* @param array $uuids
|
|
397 |
* List of UUIDs for which we should find their entity IDs. If $revision
|
|
399 | 398 |
* is TRUE this should be revision UUIDs instead. |
400 |
* @param $revision |
|
399 |
* @param bool $revision
|
|
401 | 400 |
* If TRUE the revision IDs is returned instead. |
402 |
* @return |
|
403 |
* Array of entity IDs keyed by their UUIDs. If $revision is TRUE revision |
|
401 |
* |
|
402 |
* @return array |
|
403 |
* List of entity IDs keyed by their UUIDs. If $revision is TRUE revision |
|
404 | 404 |
* IDs and UUIDs are returned instead. |
405 | 405 |
*/ |
406 | 406 |
function entity_get_id_by_uuid($entity_type, $uuids, $revision = FALSE) { |
... | ... | |
437 | 437 |
$result = db_select($table, 't') |
438 | 438 |
->fields('t', array($uuid_key, $id_key)) |
439 | 439 |
->condition($uuid_key, array_values($uuids), 'IN') |
440 |
->execute();
|
|
441 |
$result = $result->fetchAllKeyed();
|
|
440 |
->execute() |
|
441 |
->fetchAllKeyed(); |
|
442 | 442 |
$cache = &drupal_static('entity_uuid_id_cache', array()); |
443 | 443 |
$cache[$entity_type][(int) $revision] += $result; |
444 | 444 |
return $result + $cached_ids; |
... | ... | |
462 | 462 |
* @todo |
463 | 463 |
* Limit the query. |
464 | 464 |
* |
465 |
* @param $entity_type |
|
465 |
* @param string $entity_type
|
|
466 | 466 |
* The entity type we should be dealing with. |
467 |
* @param $ids |
|
468 |
* An array of entity IDs for which we should find their UUIDs. If $revision
|
|
467 |
* @param array $ids
|
|
468 |
* List of entity IDs for which we should find their UUIDs. If $revision
|
|
469 | 469 |
* is TRUE this should be revision IDs instead. |
470 |
* @param $revision |
|
470 |
* @param bool $revision
|
|
471 | 471 |
* If TRUE the revision UUIDs is returned instead. |
472 |
* @return |
|
473 |
* Array of entity UUIDs keyed by their IDs. If $revision is TRUE revision |
|
472 |
* |
|
473 |
* @return array |
|
474 |
* List of entity UUIDs keyed by their IDs. If $revision is TRUE revision |
|
474 | 475 |
* IDs and UUIDs are returned instead. |
475 | 476 |
*/ |
476 | 477 |
function entity_get_uuid_by_id($entity_type, $ids, $revision = FALSE) { |
... | ... | |
511 | 512 |
->execute() |
512 | 513 |
->fetchAllKeyed(); |
513 | 514 |
$cache = &drupal_static('entity_uuid_id_cache', array()); |
514 |
$cache[$entity_type][(int) $revision]+= array_flip($result); |
|
515 |
$cache[$entity_type][(int) $revision] += array_flip($result);
|
|
515 | 516 |
return $result + $cached_ids; |
516 | 517 |
} |
517 | 518 |
|
... | ... | |
525 | 526 |
* @todo |
526 | 527 |
* Add tests for this function. |
527 | 528 |
* |
528 |
* @param $objects |
|
529 |
* An array of objects that should get $properties changed. Can be either an
|
|
529 |
* @param array $objects
|
|
530 |
* List of objects that should get $properties changed. Can be either an
|
|
530 | 531 |
* entity object or a field items array. |
531 |
* @param $entity_type |
|
532 |
* @param string $entity_type
|
|
532 | 533 |
* The type of entity that all $properties refers to. |
533 |
* @param $properties |
|
534 |
* @param array $properties
|
|
534 | 535 |
* An array of properties that should be changed. All properties must refer to |
535 | 536 |
* the same type of entity (the one referenced in $entity_type). |
536 | 537 |
*/ |
... | ... | |
581 | 582 |
* @todo |
582 | 583 |
* Add tests for this function. |
583 | 584 |
* |
584 |
* @param $objects |
|
585 |
* An array of objects that should get $properties changed. Can be either an
|
|
585 |
* @param array $objects
|
|
586 |
* List of objects that should get $properties changed. Can be either an
|
|
586 | 587 |
* entity object or a field items array. |
587 |
* @param $entity_type |
|
588 |
* @param string $entity_type
|
|
588 | 589 |
* The type of entity that all $properties refers to. |
589 |
* @param $properties |
|
590 |
* @param array $properties
|
|
590 | 591 |
* An array of properties that should be changed. All properties must refer to |
591 | 592 |
* the same type of entity (the one referenced in $entity_type). |
592 | 593 |
*/ |
Formats disponibles : Unified diff
Weekly update of contrib modules