Skip to main content
Level 4
4月 16, 2024 2:51 午後 UTC
解決済み

Why I can't had the publish date of a page in stage (QA) environment?

Hello, what happens is that I have a component that has its own java sling model, what I need is to get the date of publication of the page (that is, the date on which you create the page and click the publish button).

I already have the code and the logic ready.

I have tested this code in localhost and in dev environment, and in both it works perfectly, but when I deploy it to stage (QA) it doesn't work, it doesn't bring me the value of the publish date.


This is the code I use:

@ScriptVariable private Page currentPage;
@Inject @Named("jcr:created") private Date original_created_page_date;
 
    public String getPublishDate() {
        String dates = "";

        try {
             //  Get the publish date of the page
            ValueMap pageProperties = currentPage.getProperties();
            Date lastReplicated = pageProperties.get(NameConstants.PN_PAGE_LAST_REPLICATED, Date.class);
            dates = new SimpleDateFormat("yyyy-MM-dd").format(lastReplicated);
        } catch (Exception e) {
             // If fails, return the created page date (the date of the page when was created even if is published or not)
            dates = new SimpleDateFormat("yyyy-MM-dd").format(original_created_page_date);
        }

        return dates;
    }
このトピックへの返信は締め切られました。
Raja_Reddy
Community Advisor
4月 16, 2024 3:46 午後 UTC

Hi @aaron_dempwolff 

It's possible that the issue is related to the replication process. In some environments, the replication process may take longer to complete, which could cause the lastReplicated value to be null.

You could try checking if the page is activated before getting the lastReplicated value. 

@ScriptVariable private Page currentPage; @Inject @Named("jcr:created") private Date original_created_page_date; public String getPublishDate() { String dates = ""; try { // Check if the page is activated if (currentPage != null && currentPage.isActivated()) { // Get the publish date of the page ValueMap pageProperties = currentPage.getProperties(); Date lastReplicated = pageProperties.get(NameConstants.PN_PAGE_LAST_REPLICATED, Date.class); dates = new SimpleDateFormat("yyyy-MM-dd").format(lastReplicated); } } catch (Exception e) { // If fails, return the created page date (the date of the page when was created even if is published or not) dates = new SimpleDateFormat("yyyy-MM-dd").format(original_created_page_date); } return dates; }

If this doesn't solve the issue, it's possible that there's a configuration difference between your environments that's causing the problem.

10 の返信

sravs
Community Advisor
Community Advisor
4月 16, 2024 2:55 午後 UTC

@aaron_dempwolff , please make sure that the page is published on Stage environment.

翻訳
Level 4
4月 16, 2024 4:28 午後 UTC

I tried but even if I republish the page it's still doesn't bringing the published date page

翻訳
joerghoh
Adobe Employee
Adobe Employee
4月 26, 2024 10:04 午後 UTC

the order of actions on author is like this:

* replicate the content

* Update the last_replicated* properties

 

That means, that this value will always be off.

翻訳
Raja_Reddy
Community Advisor
Community Advisor
4月 16, 2024 3:46 午後 UTC

Hi @aaron_dempwolff 

It's possible that the issue is related to the replication process. In some environments, the replication process may take longer to complete, which could cause the lastReplicated value to be null.

You could try checking if the page is activated before getting the lastReplicated value. 

@ScriptVariable private Page currentPage; @Inject @Named("jcr:created") private Date original_created_page_date; public String getPublishDate() { String dates = ""; try { // Check if the page is activated if (currentPage != null && currentPage.isActivated()) { // Get the publish date of the page ValueMap pageProperties = currentPage.getProperties(); Date lastReplicated = pageProperties.get(NameConstants.PN_PAGE_LAST_REPLICATED, Date.class); dates = new SimpleDateFormat("yyyy-MM-dd").format(lastReplicated); } } catch (Exception e) { // If fails, return the created page date (the date of the page when was created even if is published or not) dates = new SimpleDateFormat("yyyy-MM-dd").format(original_created_page_date); } return dates; }

If this doesn't solve the issue, it's possible that there's a configuration difference between your environments that's causing the problem.

翻訳
Level 4
4月 16, 2024 4:18 午後 UTC

Hello, I tried the code but when I build it I have the next error:

It says that currentPage doesn't have the method is Activated.

Is there's an alternative for that method or a package that have that method?

I'm using this one:

import com.day.cq.wcm.api.Page;
翻訳
sravs
Community Advisor
Community Advisor
4月 16, 2024 4:25 午後 UTC

hi @aaron_dempwolff , Try with below snippet

public String getPublishedDate() {
String dates = "";
ValueMap pageProperties = currentPage.getProperties();
if(null != pageProperties.get(NameConstants.PN_PAGE_LAST_REPLICATED)) {
Date lastReplicated = pageProperties.get(NameConstants.PN_PAGE_LAST_REPLICATED,
Date.class);
dates = new SimpleDateFormat("yyyy-MM-dd").format(lastReplicated);
}else {
dates = new SimpleDateFormat("yyyy-MM-dd").format(original_created_page_date);
}
}
return dates;
}
翻訳
Sady_Rifat
Community Advisor
Community Advisor
4月 17, 2024 11:17 午前 UTC

Hello @aaron_dempwolff ,

In your stage environment, I hope you checked the targeted page "jcr:content" node has property "cq:lastReplicated".?

翻訳
Level 4
4月 17, 2024 2:31 午後 UTC

Sadly I don't have permissions to enter in the crx of stage and prod, only I have permission to do it in localhost and dev env, however, now I check that even in dev is not working, because I make a republish (which make the publish date to update) and don't takes the new publish date, this is the structure of the data:

The page is name how to maximize, and have a jcr:content node, now inside that node is the value cq:lastReplicated that for what I investigate, is the value that have the last date when the page was published

 

翻訳
EstebanBustamante
Adobe Champion and Community Advisor
Adobe Champion and Community Advisor
4月 18, 2024 2:17 午後 UTC

@aaron_dempwolff Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

翻訳
Esteban Bustamante