Skip to content

fix(schema): use FQCN for core model classes to resolve PSR-4 deprecation#16919

Open
Ibochkarev wants to merge 5 commits into
modxcms:3.xfrom
Ibochkarev:fix/schema-fqcn-psr4-deprecation
Open

fix(schema): use FQCN for core model classes to resolve PSR-4 deprecation#16919
Ibochkarev wants to merge 5 commits into
modxcms:3.xfrom
Ibochkarev:fix/schema-fqcn-psr4-deprecation

Conversation

@Ibochkarev

@Ibochkarev Ibochkarev commented Mar 8, 2026

Copy link
Copy Markdown
Collaborator

What does it do?

Use fully qualified class names (FQCN) for all core model classes in core/model/schema/modx.mysql.schema.xml. Replaces every short class name (e.g. class="modNamespace", class="modResource", class="modUser") with MODX\\Revolution\\* equivalents. Covers modNamespace, modPlugin, modPluginEvent, modSystemSetting, modMenu, modResource, modUser, modTemplate, modChunk, modSnippet, modCategory, modContext, modEvent, modFormCustomization*, modTemplateVar*, modUserGroup*, modAccess*, and all other mod* objects in the main schema.

Additionally, modX::loadClass() now normalizes short mod* names to FQCN at runtime. When legacy code or xPDO call paths pass short names (e.g. modResource, modAccessContext), they are converted to MODX\Revolution\* internally. A class_alias is created for backward compatibility. This avoids deprecation notices from getObject, getCollection, newQuery, and other paths that invoke loadClass before modAccessibleObject::load.

Why is it needed?

Short names in the schema cause the profiler and modX::loadClass() to trigger v3.0 deprecation warnings that tell users to replace references with MODX\\Revolution\\* for PSR-4 autoloading. Application code already uses modNamespace::class and equivalent; the warnings come from the schema-defined class attribute and the resulting xPDO map keys. Updating the schema to FQCN aligns metadata with PSR-4 and removes the deprecation notices. Runtime normalization in loadClass() handles remaining call paths that still pass short names.

How to test

Run the application with the profiler or deprecation log enabled; verify that deprecation warnings for mod* classes from this schema no longer appear. Optionally rebuild the model from the updated schema and confirm the map uses FQCN.

Related issue(s)/PR(s)

None.

Replace class="modNamespace" with class="MODX\Revolution\modNamespace"
in modx.mysql.schema.xml so the profiler and loadClass no longer trigger
the v3.0 deprecation warning for short class name.
Replace short class names with MODX\Revolution\ FQCN in modx.mysql.schema.xml
to resolve PSR-4 deprecation warnings in profiler (v3.0).
Replace short class names with MODX\Revolution\* for modAccess, modMenu,
modResource, modUser, modTemplate, modChunk, modSnippet, modCategory,
modContext, modEvent, modFormCustomization*, modTemplateVar*, modUserGroup*,
and all other core model classes in modx.mysql.schema.xml to resolve
PSR-4 deprecation warnings (v3.0).
…ility

Add isShortModClassName() helper and runtime normalization in loadClass().
Short names (modResource, modAccessContext, etc.) are converted to
MODX\Revolution\* FQCN to avoid deprecation from xPDO call paths.
Creates class_alias for backward compatibility.
@Ibochkarev Ibochkarev marked this pull request as ready for review March 8, 2026 17:24
@Mark-H

Mark-H commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator

I'm confused about the schema changes - all objects are already in the \MODX\Revolution package so this is already getting prepended as namespace when the model is built. It seems like this would cause that it to get doubled up.

Any deprecation warnings should come from specific usages using the short name, not the core schema. But as there's no issue linked or deprecation warning shown, it's unclear what specifically we're fixing.

The loadClass fix I could get behind but would want to test with third-party extras that have (perhaps unwisely so) used the mod prefix in their models.

@smg6511

smg6511 commented May 30, 2026

Copy link
Copy Markdown
Collaborator

On the loadClass change: Isn't the whole idea of having these deprecation warnings to remind (badger) us to adopt the appropriate replacement method? I don't think it's a fix to mute those.

@smg6511

smg6511 commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

@Ibochkarev - Hey, just wanted to get your response to Mark's and my comments above and whether you want to continue to pursue this change. Thx ;-)

Revert schema FQCN and loadClass normalization based on review feedback.
The schema package already prepends MODX\Revolution\, and silencing
deprecation in loadClass() undermines the v3.0 migration path.

Fix remaining core call sites that still passed short names to getObject()
and loadAttributes().
@Ibochkarev

Copy link
Copy Markdown
Collaborator Author

Thanks @Mark-H and @smg6511 — really helpful feedback, and sorry for the slow reply.

After re-reading your comments I agree the original approach was off:

Schema FQCN — you're right. Objects already live in the MODX\Revolution\ package, and xPDO prepends that namespace when the model is built. Putting FQCN in class="..." risks doubling the namespace. I've reverted all schema changes.

loadClass() normalization — also reverted. @smg6511 is right that those deprecation notices are intentional; muting them in loadClass() would work against the v3.0 migration path rather than help it.

What I kept instead — fixing actual short-name usages in core code. A repo-wide search turned up two remaining call sites that still passed bare mod* strings into xPDO:

  • modResource::isPreviewable()getObject('modResource', …)getObject(modResource::class, …)
  • modUser::getResourceGroups()loadAttributes(['modAccessResourceGroup'], …)loadAttributes([modAccessResourceGroup::class], …)

Pushed in 7c7b3df9e.

Happy to dig further if you know of other profiler warnings I missed — I didn't have a concrete stack trace in the original PR, which was part of the problem. If there are more, I'd rather fix them at the call site than in schema or loadClass().

@Mark-H — on third-party extras using the mod prefix: with the loadClass() shim gone, those should behave exactly as before. Worth a quick smoke test if anyone has a known extra that does this.

Let me know if this direction works or if you'd prefer closing the PR and opening a smaller one with just the two call-site fixes.

@smg6511 smg6511 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ibochkarev My first comment is optional (but maybe preferrable), but it'd be good to know more re the modUser->getResourceGroups method — unless it's used behind the scenes somehow, we may be able to just remove that (?).

Comment thread core/src/Revolution/modResource.php
Comment thread core/src/Revolution/modUser.php
@smg6511

smg6511 commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

more re the modUser->getResourceGroups method

Answering my own question, this is used in one place in modResourceGroup->hasAccess.

@smg6511 smg6511 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we're good here!

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.

3 participants