function lingotek_post_update_lingotek_config_metadata_job_id in Lingotek Translation 8.2
Update job ids for config metadata, replacing invalid chars.
File
- ./
lingotek.post_update.php, line 99 - Post update functions for Lingotek.
Code
function lingotek_post_update_lingotek_config_metadata_job_id(&$sandbox = NULL) {
\Drupal::classResolver(ConfigEntityUpdater::class)
->update($sandbox, 'lingotek_config_metadata', function (LingotekConfigMetadata $metadata) {
$lingotek = \Drupal::service('lingotek');
$job_id = $metadata
->getJobId();
if (preg_match('@[\\/\\\\]+@', $job_id)) {
$new_job_id = str_replace('/', '-', $job_id);
$new_job_id = str_replace('\\', '-', $new_job_id);
$metadata
->setJobId($new_job_id);
if ($new_job_id !== $job_id && ($document_id = $metadata
->getDocumentId())) {
try {
$lingotek
->updateDocument($document_id, NULL, NULL, NULL, NULL, $new_job_id);
} catch (LingotekApiException $exception) {
\Drupal::logger('lingotek')
->error("Update of job_id %job failed for document %document", [
'%job' => $new_job_id,
'%document' => $document_id,
]);
}
}
return TRUE;
}
return FALSE;
});
}