user and data for metadata + settings

user and date for metadata #1853 #1861
This commit is contained in:
Timo Litzbarski
2016-03-11 11:59:23 +00:00
committed by BlueTeck
parent 7d7b9f78b8
commit 194fbe263e
6 changed files with 64 additions and 12 deletions

View File

@@ -81,19 +81,19 @@ abstract class Metadata extends Base
public function save($entity_id, array $values)
{
$results = array();
$user_id = $this->userSession->getId();
$timestamp = time();
$this->db->startTransaction();
foreach ($values as $key => $value) {
if ($this->exists($entity_id, $key)) {
$results[] = $this->db->table(static::TABLE)->eq($this->getEntityKey(), $entity_id)->eq('name', $key)->update(array('value' => $value));
$results[] = $this->db->table(static::TABLE)->eq($this->getEntityKey(), $entity_id)->eq('name', $key)->update(array('value' => $value, 'changed_on' => $timestamp, 'changed_by' => $user_id));
} else {
$results[] = $this->db->table(static::TABLE)->insert(array('name' => $key, 'value' => $value, $this->getEntityKey() => $entity_id));
$results[] = $this->db->table(static::TABLE)->insert(array('name' => $key, 'value' => $value, $this->getEntityKey() => $entity_id, 'changed_on' => $timestamp, 'changed_by' => $user_id));
}
}
$this->db->closeTransaction();
return ! in_array(false, $results, true);
}

View File

@@ -81,14 +81,16 @@ abstract class Setting extends Base
{
$results = array();
$values = $this->prepare($values);
$user_id = $this->userSession->getId();
$timestamp = time();
$this->db->startTransaction();
foreach ($values as $option => $value) {
if ($this->exists($option)) {
$results[] = $this->db->table(self::TABLE)->eq('option', $option)->update(array('value' => $value));
$results[] = $this->db->table(self::TABLE)->eq('option', $option)->update(array('value' => $value, 'changed_on' => $timestamp, 'changed_by' => $user_id));
} else {
$results[] = $this->db->table(self::TABLE)->insert(array('option' => $option, 'value' => $value));
$results[] = $this->db->table(self::TABLE)->insert(array('option' => $option, 'value' => $value, 'changed_on' => $timestamp, 'changed_by' => $user_id));
}
}