This commit is contained in:
thinkphp
2017-03-10 11:27:54 +08:00
parent e40962c346
commit d086406a54

View File

@@ -779,22 +779,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
return false;
}
protected function autoWriteUpdateTime(&$data)
{
// 自动写入更新时间
if ($this->autoWriteTimestamp && $this->updateTime && (empty($this->change) || !in_array($this->updateTime, $this->change))) {
$data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);
}
}
protected function autoWriteCreateTime(&$data)
{
// 自动写入创建时间
if ($this->autoWriteTimestamp && $this->createTime && (empty($this->change) || !in_array($this->createTime, $this->change))) {
$data[$this->createTime] = $this->autoWriteTimestamp($this->createTime);
}
}
/**
* 保存当前数据对象
* @access public
@@ -886,9 +870,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
}
}
if (!empty($data)) {
if (!empty($data) && $this->autoWriteTimestamp && $this->updateTime && !isset($data[$this->updateTime])) {
// 自动写入更新时间
$this->autoWriteUpdateTime($data);
$data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);
} else {
return 0;
}
@@ -939,10 +923,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
} else {
// 自动写入
$this->autoCompleteData($this->insert);
// 自动写入创建时间
$this->autoWriteCreateTime($this->data);
// 自动写入更新时间
$this->autoWriteUpdateTime($this->data);
// 自动写入创建时间和更新时间
if ($this->autoWriteTimestamp) {
if ($this->createTime && !isset($this->data[$this->createTime])) {
$this->data[$this->createTime] = $this->autoWriteTimestamp($this->createTime);
}
if ($this->updateTime && !isset($this->data[$this->updateTime])) {
$this->data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);
}
}
if (false === $this->trigger('before_insert', $this)) {
return false;