function entity_update_tests_update_8001 in Entity Update 8
Same name and namespace in other branches
- 2.0.x tests/modules/entity_update_tests/entity_update_tests.install \entity_update_tests_update_8001()
Update 01 - Example for update an entity type 'entity_update_tests_cnt'.
File
- modules/
entity_update_tests/ entity_update_tests.install, line 16 - Entity update test module (entity_update_tests).
Code
function entity_update_tests_update_8001() {
// Entity checking process : Get current entities list.
$ids_old = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
// Get entity type.
$entity_type = \Drupal::entityTypeManager()
->getStorage('entity_update_tests_cnt');
// Make Update Using safeUpdateMain methode.
if (!EntityUpdate::safeUpdateMain($entity_type
->getEntityType())) {
// Your codes if update failed.
throw new UpdateException('Entity update failed.');
}
// Entity checking process : Compare with new list entities list.
$ids_new = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
// Compare two lists.
$result = array_diff($ids_old, $ids_new);
if (!empty($result)) {
// Your codes if update checking failed.
throw new UpdateException('Entity update checking failed.');
}
return "Entity update success";
}