Issue
After upgrading from a previous version of Liferay DXP, the server fails to start up correctly and throws a DuplicateFolderNameException in the logs. The error indicates that a folder named image.default.company.logo already exists.
ERROR [main][UpgradeExecutor:333] A folder already exists with name image.default.company.logo
com.liferay.document.library.kernel.exception.DuplicateFolderNameException: A folder already exists with name image.default.company.logo
at com.liferay.portlet.documentlibrary.service.impl.DLFolderLocalServiceImpl.validateFolder(DLFolderLocalServiceImpl.java:1441)
...
at com.liferay.commerce.product.internal.model.listener.AddRepositoryIdInitialRequestPortalInstanceLifecycleListener.doPortalInstanceRegistered(AddRepositoryIdInitialRequestPortalInstanceLifecycleListener.java:112)
This issue occurs because a Liferay Commerce startup process attempts to create a default folder that already exists due to orphaned data from the previous version.
Environment
- Liferay DXP Quarterly Releases
Resolution
The solution is to remove the orphaned repository and folder records by running a Groovy script. As a prerequisite, it is highly recommended to perform a full backup of the database and the document library.
-
Check there is at least one DLFolder with the name '
image.default.company.logo':select * from DLFolder d where name = 'image.default.company.logo'
-
Check no DLFileEntry exists related to any of the '
image.default.company.logo' related repositories:select * from dlfileentry where repositoryId in (select repositoryId from Repository r where name = 'image.default.company.logo' AND portletId = "com.liferay.commerce.product");
-
Find the Repository IDs related to 'image.default.company.logo' and Commerce Portlet:
SELECT repositoryId FROM Repository WHERE name = 'image.default.company.logo' AND portletId = 'com.liferay.commerce.product';
Take note of the
repositoryIdsreturned by this query. -
Run the Cleanup Script
Navigate to Control Panel → Server Administration → Script and execute the following Groovy script. Replace the
xwith the IDs you found in the previous step.import java.util.Arrays; import java.util.List; import com.liferay.portal.kernel.service.RepositoryLocalServiceUtil; List<Integer> repositoryIdList = Arrays.asList(x,x,x,x,x); for (int i = 0; i < repositoryIdList.size(); i++) { RepositoryLocalServiceUtil.deleteRepository(Long.valueOf(repositoryIdList.get(i))); }This script will delete the problematic repository and its associated folder. You must then perform a reindex.
Please backup your ddbb and DL before running this script.
After these steps, the error should no longer appear during startup.