Skip to content

Commit

Permalink
Fixing error when try to publish a Template and the Unqiue feilds dat…
Browse files Browse the repository at this point in the history
…abase validation is enabled
  • Loading branch information
freddyDOTCMS committed Dec 17, 2024
1 parent b8de85e commit 7659e6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 = "<html><body> I'm mostly empty </body></html>";
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
Expand Down

0 comments on commit 7659e6c

Please sign in to comment.