So here is a shortened version of my code.
When a resource is edited, we copy the current content into tv3
When the resource is saved, we compare the content with tv3 to see if there has been a change
Except, tv3 disappears when I check it, after just having set it.
What am I doing wrong?
<?php
switch ($modx->event->name) {
case 'OnDocFormRender':
if ( $mode == modSystemEvent::MODE_UPD ) {
// before the form is edited, we get the current content and copy it to the old content, so we can compare later
$content = $resource->get('content');
$modx->log(modX::LOG_LEVEL_ERROR, ' [content]: '.$content);
$oldcontent = $resource->setTVValue(3, $content);
$modx->log(modX::LOG_LEVEL_ERROR, ' [tv3] now set:'.$resource->getTVValue(3));
}
break;
case 'OnBeforeDocFormSave':
if ( $mode == modSystemEvent::MODE_NEW ) {
} else if ( $mode == modSystemEvent::MODE_UPD ) {
}
break;
case 'OnDocFormSave':
if ( $mode == modSystemEvent::MODE_UPD ) {
$new_content = $resource->get('content');
$modx->log(modX::LOG_LEVEL_ERROR, ' [content] new:'.$new_content);
$old_content = $resource->getTVValue(3);
$modx->log(modX::LOG_LEVEL_ERROR, ' [tv3] old content:'.$old_content);
if ( $old_content !== $new_content) {
$modx->log(modX::LOG_LEVEL_ERROR, 'content of old and new DO NOT MATCH');
} else {
$modx->log(modX::LOG_LEVEL_ERROR, 'content of old and new ARE THE SAME');
}
}
break;
default:
}
return;