Issue
- When updating web content within a task executor, if the web content structure includes an image field (fileEntry), the update JournalArticle updateArticle(article.getUserId(), article.getGroupId(), article.getFolderId(), article.getArticleId(),article.getVersion(), content, serviceContext) process fails.
- The failure occurs during the web content validation process when retrieving the associated FileEntry. The underlying issue is that
CompanyThreadLocal.getCompanyId()returns 0 within the task executor's context, preventing the system from identifying the correct company and retrieving the FileEntry.
com.liferay.document.library.kernel.exception.NoSuchFileEntryException
com.liferay.exportimport.kernel.exception.ExportImportContentValidationException: com.liferay.document.library.kernel.exception.NoSuchFileEntryException
at com.liferay.exportimport.internal.exportimport.content.processor.DLReferencesExportImportContentProcessor._validateDLReferences(DLReferencesExportImportContentProcessor.java:913)
Environment
- Liferay DXP 2024.Q1.2+
Resolution
- To resolve this issue, explicitly set the company ID in the task executor's thread. You can obtain the company ID from the
JournalArticleobject itself. Here's an example of how to do this within thedoExecutemethod of your task executor:@Override
public void doExecute(DispatchTrigger dispatchTrigger, DispatchTaskExecutorOutput dispatchTaskExecutorOutput) throws PortalException {
JournalArticle article = ...; // Get your JournalArticle object
CompanyThreadLocal.setCompanyId(article.getCompanyId());
try {
// Perform web content update operations here
} catch (Exception e) {
log.error(e);
}
}
NOTE: The following resolution requires customization and should only be implemented at the discretion of your team. Liferay Support will not be able to assist with designing or implementing customizations.
Additional Information
- Task executors run in a background thread and do not have this information readily available. Therefore, you must set it manually.