Add createdon/editedon timestamps to element and category tables#16930
Open
pbowyer wants to merge 3 commits intomodxcms:3.xfrom
Open
Add createdon/editedon timestamps to element and category tables#16930pbowyer wants to merge 3 commits intomodxcms:3.xfrom
pbowyer wants to merge 3 commits intomodxcms:3.xfrom
Conversation
…hemas Add nullable datetime columns for createdon and editedon to the XML schema and PHP map files for: modCategory, modChunk, modPlugin, modPluginEvent, modSnippet, modTemplate, modTemplateVar, modTemplateVarResource, modTemplateVarResourceGroup, and modTemplateVarTemplate. editedon uses ON UPDATE CURRENT_TIMESTAMP so MySQL automatically tracks modifications. Both fields default to NULL for existing records.
Set createdon to the current datetime in modElement::save() and modCategory::save() when creating new objects, matching the convention used by modUser. Add upgrade script for 3.2.1 that adds the createdon and editedon columns to all 10 affected tables during setup.
Verify that createdon is set on new chunks and categories, that editedon remains null after creation, and that createdon is preserved after updates.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.x #16930 +/- ##
============================================
+ Coverage 21.64% 21.68% +0.04%
- Complexity 10764 10788 +24
============================================
Files 566 566
Lines 33005 33150 +145
============================================
+ Hits 7144 7189 +45
- Misses 25861 25961 +100 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does it do?
MODX tracks when resources, users, and settings were created and last modified, but not elements. There's no way to tell when a snippet was last changed or which templates haven't been touched in years.
As a developer, this information is useful. This PR adds
createdonandeditedoncolumns to chunks, snippets, plugins, templates, TVs, categories, and their association tables.How does it work?
createdonis set in PHP when an element or category is first saved, the same waymodUseralready handles it.editedonis handled by MySQL (ON UPDATE CURRENT_TIMESTAMP), so it requires no application code. Both use thedatetimetype rather thantimestampto avoid timezone conversion quirks and the 2038 year limit.Existing records get
NULLfor both columns.editedonstaysNULLuntil an actual edit is made, which matches how resources behave.For static elements,
editedonreflects when MODX last synced the file content to the database, which may differ from when the file was actually modified.editedonreflecting when the DB row was last updated is at least honest and consistent.How to test
I've extended the test suite to verify
createdonis set on creation,editedonisnullafter creation,createdonis preserved after update.Related issue(s)/PR(s)
#13857 was a previous PR to do this. It added
createdbyandeditedbyas well, and as it went the scope expanded. I have kept my PR focused because I am not using the other features. It ran into problems with static elements, and think I have taken a pragmatic approach to solving that.#13770 #13626 #13641 #2027