How to trigger VersionX in MODX API?

Is there a way to trigger VersionX to record a version of a resource after a resource is saved using the API ($thisres->save())?

I found this in a thread from 2020:

$resource = $modx->getObject(...);
$corePath = $modx->getOption('versionx.core_path',null,$modx->getOption('core_path').'components/versionx/');
require_once $corePath.'model/versionx.class.php';
$versionx = new VersionX($modx);
$versionx->newResourceVersion($resource);

but that’s not working for the newest version of VersionX.

MODX 2.8.7, VersionX 3.1.1.

Looking at the code of the plugin in VersionX, you probably have to load VersionX like this (without lines 24 and 27):

and then use this code (where $id is the resource-ID):

1 Like

Thanks, looks good. Will give that a try.

Just tried this. Works great!

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.