Skip to content

Add createdon/editedon timestamps to element and category tables#16930

Open
pbowyer wants to merge 3 commits intomodxcms:3.xfrom
pbowyer:peter/elements-createdon-editedon
Open

Add createdon/editedon timestamps to element and category tables#16930
pbowyer wants to merge 3 commits intomodxcms:3.xfrom
pbowyer:peter/elements-createdon-editedon

Conversation

@pbowyer
Copy link
Copy Markdown
Contributor

@pbowyer pbowyer commented Mar 21, 2026

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 createdon and editedon columns to chunks, snippets, plugins, templates, TVs, categories, and their association tables.

How does it work?

createdon is set in PHP when an element or category is first saved, the same way modUser already handles it. editedon is handled by MySQL (ON UPDATE CURRENT_TIMESTAMP), so it requires no application code. Both use the datetime type rather than timestamp to avoid timezone conversion quirks and the 2038 year limit.

Existing records get NULL for both columns. editedon stays NULL until an actual edit is made, which matches how resources behave.

For static elements, editedon reflects when MODX last synced the file content to the database, which may differ from when the file was actually modified. editedon reflecting when the DB row was last updated is at least honest and consistent.

How to test

  1. Run MODX setup upgrade to verify the upgrade script adds columns
  2. Create a new element in the manager and verify createdon appears
  3. Edit it and verify editedon is populated

I've extended the test suite to verify createdon is set on creation, editedon is null after creation, createdon is preserved after update.

Related issue(s)/PR(s)

#13857 was a previous PR to do this. It added createdby and editedby as 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

pbowyer added 3 commits March 21, 2026 08:16
…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.
@pbowyer pbowyer requested review from Mark-H and opengeek as code owners March 21, 2026 09:04
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 21.68%. Comparing base (af7a969) to head (5c4b80b).
⚠️ Report is 15 commits behind head on 3.x.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant