Skip to content

Commit

Permalink
Fixing issue where adjusting locale of copied elements failed for some
Browse files Browse the repository at this point in the history
locale configuration scenarios.
  • Loading branch information
tHerrmann committed Aug 5, 2019
1 parent 2ae0215 commit 878d1ba
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/org/opencms/i18n/tools/CmsContainerPageCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ public CmsContainerPageCopier(CmsObject cms) {
/**
* Converts locales for the copied container element.<p>
*
* @param elementResource the copied container element
* @param elementResource the copied container element resource
* @param originalResource the original container element resource
*
* @throws CmsException if something goes wrong
*/
public void adjustLocalesForElement(CmsResource elementResource) throws CmsException {
public void adjustLocalesForElement(CmsResource elementResource, CmsResource originalResource) throws CmsException {

if (m_copyMode != CopyMode.smartCopyAndChangeLocale) {
return;
Expand All @@ -195,6 +197,15 @@ public void adjustLocalesForElement(CmsResource elementResource) throws CmsExcep
Locale newLocale = OpenCms.getLocaleManager().getDefaultLocale(m_cms, m_targetFolder);
CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file);
try {
if (content.hasLocale(newLocale)) {
// check if the new locale was already present in the original resource, it may have been created automatically
CmsFile origFile = m_cms.readFile(originalResource);
CmsXmlContent origContent = CmsXmlContentFactory.unmarshal(m_cms, origFile);
if (!origContent.hasLocale(newLocale)) {
// the target locale was not present in the original, remove it to ensure the source locale is moved
content.removeLocale(newLocale);
}
}
content.moveLocale(oldLocale, newLocale);
LOG.info("Replacing locale " + oldLocale + " -> " + newLocale + " for " + elementResource.getRootPath());
file.setContents(content.marshal());
Expand Down Expand Up @@ -320,7 +331,7 @@ public CmsContainerElementBean replaceContainerElement(
CmsLockActionRecord record = null;
try {
record = CmsLockUtil.ensureLock(m_cms, resourceCopy);
adjustLocalesForElement(resourceCopy);
adjustLocalesForElement(resourceCopy, originalResource);
} finally {
if ((record != null) && (record.getChange() == LockChange.locked)) {
m_cms.unlockResource(resourceCopy);
Expand Down

0 comments on commit 878d1ba

Please sign in to comment.