5.0.0 - 严重 - 未处理
protected function updateData($where){
// 自动更新
$this->autoCompleteData($this->update);
// 事件回调
if (false === $this->trigger('before_update')) {
return false;
}
// 获取有更新的数据
$data = $this->getChangedData();
if (empty($data)) {
// 关联更新
if (!empty($this->relationWrite)) {
$this->autoRelationUpdate();
}
return true;
} elseif ($this->autoWriteTimestamp && $this->updateTime && !isset($data[$this->updateTime])) {
// 自动写入更新时间
$data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);
$this->data[$this->updateTime] = $data[$this->updateTime];
}
if (empty($where) && !empty($this->updateWhere)) {
$where = $this->updateWhere;
}
// 检查允许字段
$allowFields = $this->checkAllowFields(array_merge($this->auto, $this->update));
// 保留主键数据
foreach ($this->data as $key => $val) {
if ($this->isPk($key)) {
$data[$key] = $val;
}
}
$pk = $this->getPk();
$array = [];
foreach ((array) $pk as $key) {
if (isset($data[$key])) {
$array[] = [$key, '=', $data[$key]];
unset($data[$key]);
}
}
if (!empty($array)) {
$where = $array;
}
foreach ((array) $this->relationWrite as $name => $val) {
if (is_array($val)) {
foreach ($val as $key) {
if (isset($data[$key])) {
unset($data[$key]);
}
}
}
}
// 模型更新
$db = $this->db(false);
$db->startTrans();
try {
//没更新到不会反馈结果
$r = $db->where($where)
->strict(false)
->field($allowFields)
->update($data);
if (!$r) {
$db->rollback();
return false;
}
// 关联更新
if (!empty($this->relationWrite)) {
$this->autoRelationUpdate();
}
$db->commit();
// 更新回调
$this->trigger('after_update');
return true;
} catch (\Exception $e) {
$db->rollback();
throw $e;
}
}
