function uuid_update_7103 in Universally Unique IDentifier 7
Clean up entities created by uuid_default_entities_example module.
Modify the labels of all example entities created by the now removed uuid_default_entities_example.module to make it clear they're examples. Also remove the administrator role of any example user.
File
- ./
uuid.install, line 258 - Install, update and uninstall functions for the uuid module.
Code
function uuid_update_7103() {
// These are UUIDs of all the example entities that might exist after having
// installed uuid_default_entities_example.module.
$info = entity_get_info();
$uuids = array(
'node' => array(
'b0558664-c94b-3674-d9df-3e1696b2e471',
'5e3d8bbe-a1f2-f2d4-fdc0-71e6c23aa837',
),
'user' => array(
'7cf875e6-dc15-4404-f190-5a7c3e91d14c',
),
);
// We can't assume taxonomy is enabled.
if (isset($info['taxonomy_term'])) {
$uuids['taxonomy_term'] = array(
'bcb92ce8-2236-e264-65c8-0c163ae716d1',
'4293a15c-531a-6164-7d1b-668ed019a6bd',
'af738a46-f278-cf84-d94d-9e03879fd71e',
);
}
foreach (array_keys($uuids) as $entity_type) {
$info = entity_get_info($entity_type);
$entity_ids = entity_get_id_by_uuid($entity_type, $uuids[$entity_type]);
$entities = entity_load($entity_type, $entity_ids);
foreach ($entities as $entity) {
// Update the label to make it clear this is example content.
$entity->{$info['entity keys']['label']} = $entity->{$info['entity keys']['label']} . ' (UUID example)';
// Remove the administrator role from any user.
if ($entity_type == 'user' && ($rid = array_search('administrator', $entity->roles))) {
unset($entity->roles[$rid]);
}
entity_save($entity_type, $entity);
}
}
}