From 1d026039a8590b25c63d77e8beaff16835299080 Mon Sep 17 00:00:00 2001 From: freddyDOTCMS <147462678+freddyDOTCMS@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:47:05 -0600 Subject: [PATCH] =?UTF-8?q?Fixing=20error=20when=20try=20to=20publish=20a?= =?UTF-8?q?=20Template=20and=20the=20Unqiue=20feilds=20dat=E2=80=A6=20(#30?= =?UTF-8?q?965)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Proposed Changes * RUn the afterPublish method just for Contentlet --- .../business/VersionableAPIImpl.java | 4 +-- .../templates/business/TemplateAPITest.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPIImpl.java b/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPIImpl.java index 243dffc331c8..199b0ab8c542 100644 --- a/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPIImpl.java +++ b/dotCMS/src/main/java/com/dotmarketing/business/VersionableAPIImpl.java @@ -524,6 +524,8 @@ public void setLive ( final Versionable versionable ) throws DotDataException, D newInfo.setLiveInode(versionable.getInode()); newInfo.setPublishDate(new Date()); versionableFactory.saveContentletVersionInfo( newInfo, true ); + + uniqueFieldValidationStrategyResolver.get().afterPublish(versionable.getInode()); } else { final VersionInfo info = versionableFactory.getVersionInfo( versionable.getVersionId() ); @@ -534,8 +536,6 @@ public void setLive ( final Versionable versionable ) throws DotDataException, D info.setLiveInode( versionable.getInode() ); this.versionableFactory.saveVersionInfo( info, true ); } - - uniqueFieldValidationStrategyResolver.get().afterPublish(versionable.getInode()); } /** diff --git a/dotcms-integration/src/test/java/com/dotmarketing/portlets/templates/business/TemplateAPITest.java b/dotcms-integration/src/test/java/com/dotmarketing/portlets/templates/business/TemplateAPITest.java index 1c87d8c96076..09bdaf5689e0 100644 --- a/dotcms-integration/src/test/java/com/dotmarketing/portlets/templates/business/TemplateAPITest.java +++ b/dotcms-integration/src/test/java/com/dotmarketing/portlets/templates/business/TemplateAPITest.java @@ -12,6 +12,7 @@ import com.dotcms.IntegrationTestBase; import com.dotcms.api.web.HttpServletRequestThreadLocal; import com.dotcms.content.elasticsearch.ESQueryCache; +import com.dotcms.content.elasticsearch.business.ESContentletAPIImpl; import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.datagen.*; import com.dotcms.rendering.velocity.viewtools.DotTemplateTool; @@ -63,6 +64,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.quartz.JobExecutionException; import javax.servlet.http.HttpServletRequest; @@ -317,6 +319,39 @@ public void publishTemplate_expects_live_true() throws Exception { assertTrue(templateSaved.isLive()); } + + /** + * Method to test: {@link TemplateAPIImpl#publishTemplate(Template, User, boolean)} + * When: Publish a Template with the UniqueField Database Validation set to true + * should: Template should be live true + */ + @Test + public void publishTemplateWithUniqueFieldDatbaseValidationEnabled() throws Exception { + final boolean oldEnabledDataBaseValidation = ESContentletAPIImpl.getFeatureFlagDbUniqueFieldValidation(); + + try { + ESContentletAPIImpl.setFeatureFlagDbUniqueFieldValidation(true); + final Host host = hostAPI.findDefaultHost(user, false); + final String body = " I'm mostly empty "; + final String title = "empty test template " + UUIDGenerator.generateUuid(); + final Template template = new Template(); + template.setTitle(title); + template.setBody(body); + final Template templateSaved = templateAPI.saveTemplate(template, host, user, false); + assertTrue(UtilMethods.isSet(templateSaved.getInode())); + assertTrue(UtilMethods.isSet(templateSaved.getIdentifier())); + assertEquals(templateSaved.getBody(), body); + assertEquals(templateSaved.getTitle(), title); + assertFalse(templateSaved.isLive()); + + templateAPI.publishTemplate(templateSaved, user, false); + assertTrue(templateSaved.isLive()); + } finally { + + ESContentletAPIImpl.setFeatureFlagDbUniqueFieldValidation(oldEnabledDataBaseValidation); + } + } + /** * Method to test: unpublishTemplate * Given Scenario: Create a template, publish and unpublish it