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):
use modmore\VersionX\Types\Resource;
use modmore\VersionX\Types\Template;
use modmore\VersionX\VersionX;
$eventName = $modx->event->name;
$path = $modx->getOption('versionx.core_path', null, MODX_CORE_PATH . 'components/versionx/');
require $path . 'vendor/autoload.php';
if (!$versionX = new VersionX($modx)) {
$modx->log(modX::LOG_LEVEL_ERROR, 'Could not load VersionX');
return;
}
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!
system
Closed
August 28, 2024, 3:49pm
5
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”.