function lingotek_entity_translation_delete_translations in Lingotek Translation 7.7
Delete local translations from the Entity Translation table
1 call to lingotek_entity_translation_delete_translations()
- lingotek_delete_field_translations in ./
lingotek.util.inc - Delete translations for field based entities
File
- ./
lingotek.util.inc, line 2899 - Utility functions.
Code
function lingotek_entity_translation_delete_translations($entity_type, $entity) {
global $user;
if (!module_exists('entity_translation') || !entity_translation_enabled($entity_type)) {
return;
}
if ($entity_type == 'node' && !entity_translation_node_supported_type($entity->type)) {
return;
}
// Lock reading for writing to the entity translation table
// since many ET entries may be written concurrently
for ($i = 0; $i < 10; $i++) {
$acquired = lock_acquire('lingotek_entity_translation');
if ($acquired) {
break;
}
sleep($i + 1);
}
if (!$acquired) {
LingotekLog::error("Failed to obtain lock to write Entity Translation status.", array());
return;
}
list($id, $vid, $bundle) = lingotek_entity_extract_ids($entity_type, $entity);
$source_langcode = array(
lingotek_entity_langcode($entity_type, $entity),
);
try {
db_delete('entity_translation')
->condition('entity_type', $entity_type)
->condition('entity_id', $id)
->condition('language', $source_langcode, 'NOT IN')
->execute();
db_delete('entity_translation_revision')
->condition('entity_type', $entity_type)
->condition('entity_id', $id)
->condition('language', $source_langcode, 'NOT IN')
->execute();
} catch (PDOException $e) {
LingotekLog::error("Failed to delete translation from entity", array());
}
lock_release('lingotek_entity_translation');
return;
}