VersionX and MODX 3.0.1-pl - chunks and snippets versions not saved

Hi all … sorry, me again :person_facepalming:

I’ve checked against four different MODX 3.0.1-pl sites and all of them fail to save new versions [via VersionX] when Chunks or Snippets are saved.

Resource versions are saved OK.

When saving a Chunk or Snippet - one or more of the following errors are logged:

[2022-07-01 20:15:05] (ERROR @ /home/xxyyzz/core/components/versionx/model/versionx.class.php : 318) PHP warning: Object of class MODX\Revolution\mysql\modSnippet could not be converted to int
[2022-07-01 20:15:21] (ERROR @ /home/xxyyzz/core/components/versionx/model/versionx.class.php : 279) PHP warning: Object of class MODX\Revolution\mysql\modChunk could not be converted to int
[2022-07-01 20:15:21] (ERROR @ /home/xxyyzz/core/components/versionx/elements/plugins/versionx.plugin.php : 117) undefined error

Can anyone reproduce this?

VersionX is up to date. All sites on PHP 8.1.

Could you log an issue at Issues · modmore/VersionX · GitHub please? There is some type checking going on that needs to be updated I guess.

Of course @markh — will do.

You probably just have to add the namespace to the classes modChunk and modSnippet.

if ($chunk instanceof \MODX\Revolution\modChunk) { instead of if ($chunk instanceof modChunk) {

Hey @halftrainedharry

That looks like a fix to me.

Line 275 as you suggested:

if ($chunk instanceof \MODX\Revolution\modChunk) {

Line 314:

if ($snippet instanceof \MODX\Revolution\modSnippet) {

Both chunks and snippets saving versions as they should now :+1:

Issue raised here.

By the way, thanks for testing all these extras in MODX 3.

1 Like

All good @halftrainedharry :+1: … I’d have liked to have been able to test more pre MODX 3 launch but it just wasn’t possible for me back then.

I’m always hugely grateful for the community’s help :slightly_smiling_face:

Yeah, that’s the fix that’s needed across all element types, though as for now the modmore policy is to keep extras both 2.x and 3.x compatible from the same codebase (if at all possible, MoreGallery has been… interesting), we usually it like this:

if ($chunk instanceof \MODX\Revolution\modChunk || $chunk instance of modChunk) {
1 Like

Aye … the modmore policy is good!

Line 275:

if ($chunk instanceof \MODX\Revolution\modChunk || $chunk instanceof modChunk) {

Line 314:

if ($snippet instanceof \MODX\Revolution\modSnippet || $snippet instanceof modSnippet) {    

Tested :white_check_mark:

1 Like

I wish I’d thought of that. I’ve been removing instanceof calls from my extras, on the assumption that MODX will return null if it can’t get the requested object.

That also works. :wink: Technically the odds of any getObject returning an object that is not the type you ask for is pretty much impossible, so they’d be equivalent in any but super weird edge cases that don’t happen unless you specifically make them happen to prove the point.