/**
* @param DataModel $model
* @param \stdClass $dataObject
*/
public function onBeforeUpdate(&$model, &$dataObject)
{
// Make sure we're not modifying a locked record
$userId = $model->getContainer()->platform->getUser()->id;
$isLocked = $model->isLocked($userId);
if ($isLocked) {
return;
}
// Handle the modified_on field
if ($model->hasField('modified_on')) {
$model->setFieldValue('modified_on', $model->getContainer()->platform->getDate()->toSql(false, $model->getDbo()));
$modifiedOnField = $model->getFieldAlias('modified_on');
$dataObject->{$modifiedOnField} = $model->getFieldValue('modified_on');
}
// Handle the modified_by field
if ($model->hasField('modified_by')) {
$model->setFieldValue('modified_by', $userId);
$modifiedByField = $model->getFieldAlias('modified_by');
$dataObject->{$modifiedByField} = $model->getFieldValue('modified_by');
}
}