- Notifications
You must be signed in to change notification settings - Fork8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Added firstPublishedAt field which sets the datetime when a content is first published. (#22512)#23160
base:develop
Are you sure you want to change the base?
Conversation
…rticle was first published. (strapi#22512)This field can be updated by the user.
The latest updates on your projects. Learn more aboutVercel for Git ↗︎
|
Hi@ankit7201 in order to accept this contribution that looks great we will need the follow things:
|
Thank you for the review. Had a doubt regarding the first point that you mentioned and I was hoping to get some clarity on it. When you mentioned to make this opt-in, did you mean its visibility will be controlled by a flag in schema (similar to populateCreatorField) Meaning, it needs to be "private" unless it is enabled in the schema? |
We need to opt-in adding the field completely not just making it visible. It shouldn't be there by default or it would be a breaking change. It's about wrapping the code where you add the attribute with a condition checking the user has opted in adding it. |
@alexandrebodin Got it. What I mean is, since we are not recording the first published at datetime if it is not enabled by default, and some content is published and then we are enabling it, we don't have any value to populate this field. Or, is the expectation that if this is enabled after the content is published, a user would have to manually update this field to add a value to it. |
Good questions -> For new content-types created we would generate them with the option enabled so new users would have the field enabled. |
@alexandrebodin What will we set the value to when it is enabled for existing project? One idea would be to set it same as publishedAt date but that would be inaccurate since a content might be published several times and thereby changing the published date and time when it was first published? |
Yes it's the best we can do for existing data anyway |
@alexandrebodin |
I think we should just make it an option in the json as the goal isn't to easily switch back and forth it's just a way to introduce it in a backward compat way :) |
Got it. Thank you for all the help. Here is the final action plan:
For point 1, if possible, can you point me to some code sample where some schema options are being set when a new content type is created? |
If you look in packages/core/content-type-builder/server/src/services/schema-builder/content-type-builder.ts you will see where we set the options that will be saved to file :) |
@alexandrebodin Also, just realized one more thing while working on this. Wouldn't it be better if we create the firstPublishedAt field by default and keep it private/not private since by default we are enabling it anyway. This way, if someone switches off the feature and later switches it on again, it wouldn't cause problem with the firstPublishedAt value disappearing since while turning it off would not include it in the schema. What I mean is, if someone disables firstPublishedAt and reruns the app, strapi would remove this from the schema and subsequent enabling would not fetch any value since it was removed when it was disabled earlier. Wouldn't this cause confusion? Wouldn't it be better we keep it always as part of the schema and show is depending on if it is enabled or not? I am not sure if I am completely understood this or not. Please let me know if I am missing something here. |
This would be a breaking change. we need to make sure someone upgrading to the latest Strapi version doesn't get this field added at all. it is not in the reserved names so someone could already have a field call that way |
@alexandrebodin Edit: |
Just wanted to check back for the above query in case you missed my previous comment :-) Here is the scenario that I would need some more information on:
Is this scenario expected? |
Yes this looks good. Objectively someone wouldn't be playing around with the option in production with actual usefull data. once you decide to enable it (for old projects) or disable it for new projects it most likely will stay that way. One last thing I think you need to check with this though is that the condition to add it should be that In terms of the logic to set the value the default() { new Date() } won't be sufficient, it would add the date on the draft data. you will need more logic to be added in the document service. |
@alexandrebodin I tried playing around with existing data and when firstPublishedAt was present for publishedData and not for draft data, publishing some new content was making firstPublishedAt field null. (Not sure why?) Adding firstPublishedAt to draft data solved this problem. Will need to check why it was happening. Let me check in the code and try to understand what is going on. Thanks again. |
I have updated the code wherever applicable. I am yet to add the test cases but just wanted to get a quick review to make sure if this is what is expected. Would you mind taking a look at the changes? :) Changes:
Please note:
Thank you. |
Hey@ankit7201 Our team managing this scope will take over the review. Something I have been thinking about that could make more sense is set this as an option in the config folder so it's just a flag to trigger the new fields if D&P is enabled and it will apply everywhere. I'm a bit concerned about have an option per content type :) The team will be coming back to you soon with some product options :) |
What does it do?
Added firstPublishedAt field which sets the datetime when a content is first published.
Why is it needed?
See:#22512
How to test it?
Create a content-type and query it using the API. You should see the firstPublishedAt field.
Update the content and publishedAt field would change but firstPublishedAt field will not.
Related issue(s)/PR(s)
#22512