Skip to content

Commit

Permalink
Update - Enhanced UpdatedByAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
NGjata committed Jun 18, 2021
1 parent 2c8c3bf commit 8d06831
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Attributes/UpdatedByAttribute.php
Expand Up @@ -19,10 +19,12 @@ class UpdatedByAttribute extends ManyToOneRelation
{
public function __construct($name, $flags = 0)
{
$flags = $flags | self::AF_READONLY | self::AF_HIDE_ADD;
$flags = $flags | self::AF_READONLY | self::AF_HIDE_ADD | self::AF_LARGE; // self::AF_LARGE per migliorare performance
parent::__construct($name, $flags, Config::getGlobal('auth_usernode'));
$this->setForceInsert(true);
$this->setForceUpdate(true);

$this->setNoneLabel($this->text('system'));
}

public function addToQuery($query, $tablename = '', $fieldaliasprefix = '', &$record, $level = 0, $mode = '')
Expand Down Expand Up @@ -50,7 +52,9 @@ public function initialValue()

public function value2db(array $record)
{
$record[$this->fieldName()] = $this->initialValue();
if (!$record[$this->fieldName()]) { // only if it has no value
$record[$this->fieldName()] = $this->initialValue();
}

return parent::value2db($record);
}
Expand Down

0 comments on commit 8d06831

Please sign in to comment.