Skip to content

Commit 5b2ddf6

Browse files
fix(core): Update modDate when unpublishing and archive (dotCMS#32227)
Add the `updateModDate` to the archive and unpublish functions, this way now when unpublishing or archiving a content the Last Edition Date will we updated ***Note**: As the modDate now will be updated each time we unpublish or archive, `Assertions.assertEquals(site2.modDate(), serverSite.entity().modDate());` was removed from `Test_Archive_Site()` --------- Co-authored-by: erickgonzalez <[email protected]>
1 parent 5eb1a74 commit 5b2ddf6

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,6 +3719,8 @@ private void internalArchive(final Contentlet contentlet, final User user,
37193719

37203720
CacheLocator.getHTMLPageCache().remove(contentlet.getInode());
37213721
}
3722+
final Set<String> inodes = Stream.of(contentlet).map(Contentlet::getInode).collect(Collectors.toSet());
3723+
updateModDate(inodes, user);
37223724
invalidateLanguageVariableCache(contentlet);
37233725
HibernateUtil.addCommitListener(
37243726
() -> this.contentletSystemEventUtil.pushArchiveEvent(workingContentlet), 1000);
@@ -4154,6 +4156,9 @@ private void internalUnpublish(final Contentlet contentlet, final User user, fin
41544156
this.cleanFileAssetCache(contentlet, user, false);
41554157
}
41564158

4159+
final Set<String> inodes = Stream.of(contentlet).map(Contentlet::getInode).collect(Collectors.toSet());
4160+
updateModDate(inodes, user);
4161+
41574162
invalidateLanguageVariableCache(contentlet);
41584163

41594164
new ContentletLoader().invalidate(contentlet, PageMode.LIVE);

dotcms-integration/src/test/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImplTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4814,4 +4814,79 @@ public void testValidationExceptionForMissingRequiredRelationship() throws Excep
48144814

48154815
}
48164816

4817+
/**
4818+
* Method to test: {@link ESContentletAPIImpl#unpublish(Contentlet, User, boolean)}
4819+
* Given Scenario: Unpublish a {@link Contentlet}
4820+
* Expected Result: The modDate field should be updated
4821+
*
4822+
* @throws DotDataException
4823+
*/
4824+
@Test
4825+
public void checkModDateAfterUnpublishContent() throws DotDataException, DotSecurityException {
4826+
final Host host = new SiteDataGen().nextPersisted();
4827+
final ContentType contentType = new ContentTypeDataGen()
4828+
.host(host)
4829+
.nextPersisted();
4830+
final Contentlet contentlet = new ContentletDataGen(contentType)
4831+
.host(host)
4832+
.nextPersistedAndPublish();
4833+
4834+
try {
4835+
assertNotNull(contentlet.getModDate());
4836+
Thread.sleep(500);
4837+
APILocator.getContentletAPI().unpublish(contentlet, APILocator.systemUser(), false);
4838+
4839+
final Contentlet contentletByIdentifier = APILocator.getContentletAPI()
4840+
.findContentletByIdentifier(contentlet.getIdentifier(),
4841+
false, contentlet.getLanguageId(), APILocator.systemUser(), false);
4842+
4843+
assertNotEquals(contentlet.getModDate(), contentletByIdentifier.getModDate());
4844+
} catch (InterruptedException e) {
4845+
throw new RuntimeException(e);
4846+
} finally {
4847+
ContentTypeDataGen.remove(contentType);
4848+
ContentletDataGen.remove(contentlet);
4849+
}
4850+
4851+
}
4852+
/**
4853+
* Method to test: {@link ESContentletAPIImpl#archive(Contentlet, User, boolean)}
4854+
* Given Scenario: Archive a {@link Contentlet}
4855+
* Expected Result: The modDate field should be updated
4856+
*
4857+
* @throws DotDataException
4858+
*/
4859+
@Test
4860+
public void checkModDateAfterArchiveContent() throws DotDataException, DotSecurityException {
4861+
final Host host = new SiteDataGen().nextPersisted();
4862+
final ContentType contentType = new ContentTypeDataGen()
4863+
.host(host)
4864+
.nextPersisted();
4865+
final Contentlet contentlet = new ContentletDataGen(contentType)
4866+
.host(host)
4867+
.nextPersistedAndPublish();
4868+
4869+
final Date initialModDate = contentlet.getModDate();
4870+
4871+
try {
4872+
assertNotNull(contentlet.getModDate());
4873+
Thread.sleep(500);
4874+
APILocator.getContentletAPI().archive(contentlet, APILocator.systemUser(), false);
4875+
4876+
final Contentlet contentletByIdentifier = APILocator.getContentletAPI()
4877+
.findContentletByIdentifier(contentlet.getIdentifier(),
4878+
false, contentlet.getLanguageId(), APILocator.systemUser(), false);
4879+
4880+
final Date finalModDate = contentletByIdentifier.getModDate();
4881+
4882+
assertNotEquals(initialModDate, finalModDate);
4883+
} catch (InterruptedException e) {
4884+
throw new RuntimeException(e);
4885+
} finally {
4886+
ContentTypeDataGen.remove(contentType);
4887+
ContentletDataGen.remove(contentlet);
4888+
}
4889+
4890+
}
4891+
48174892
}

tools/dotcms-cli/cli/src/test/java/com/dotcms/cli/command/site/SiteCommandIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,6 @@ void Test_Archive_Site() throws IOException {
11421142
Assertions.assertNotNull(serverSite.entity().identifier());
11431143
Assertions.assertEquals(site2.siteName(), serverSite.entity().siteName());
11441144
Assertions.assertEquals(site2.identifier(), serverSite.entity().identifier());
1145-
Assertions.assertEquals(site2.modDate(), serverSite.entity().modDate());
11461145
Assertions.assertEquals(site2.isArchived(), serverSite.entity().isArchived());
11471146
}
11481147
} finally {

0 commit comments

Comments
 (0)