mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
Merge branch 'master' of https://git.topthink.com/topteam/framework
This commit is contained in:
@@ -995,7 +995,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 模型更新
|
// 模型更新
|
||||||
$result = $this->db()->where($where)->update($data);
|
$result = $this->getQuery()->where($where)->update($data);
|
||||||
|
|
||||||
// 关联更新
|
// 关联更新
|
||||||
if (isset($relation)) {
|
if (isset($relation)) {
|
||||||
@@ -1022,11 +1022,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->db()->insert($this->data);
|
$result = $this->getQuery()->insert($this->data);
|
||||||
|
|
||||||
// 获取自动增长主键
|
// 获取自动增长主键
|
||||||
if ($result && is_string($pk) && (!isset($this->data[$pk]) || '' == $this->data[$pk])) {
|
if ($result && is_string($pk) && (!isset($this->data[$pk]) || '' == $this->data[$pk])) {
|
||||||
$insertId = $this->db()->getLastInsID($sequence);
|
$insertId = $this->getQuery()->getLastInsID($sequence);
|
||||||
if ($insertId) {
|
if ($insertId) {
|
||||||
$this->data[$pk] = $insertId;
|
$this->data[$pk] = $insertId;
|
||||||
}
|
}
|
||||||
@@ -1114,7 +1114,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
$db = $this->db();
|
$db = $this->getQuery();
|
||||||
$db->startTrans();
|
$db->startTrans();
|
||||||
try {
|
try {
|
||||||
$pk = $this->getPk();
|
$pk = $this->getPk();
|
||||||
@@ -1228,7 +1228,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 删除当前模型数据
|
// 删除当前模型数据
|
||||||
$result = $this->db()->where($where)->delete();
|
$result = $this->getQuery()->where($where)->delete();
|
||||||
|
|
||||||
// 关联删除
|
// 关联删除
|
||||||
if (!empty($this->relationWrite)) {
|
if (!empty($this->relationWrite)) {
|
||||||
|
|||||||
@@ -273,6 +273,23 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
|
|||||||
return $this->items->isEmpty();
|
return $this->items->isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 给每个元素执行个回调
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function each(callable $callback)
|
||||||
|
{
|
||||||
|
foreach ($this->items as $key => $item) {
|
||||||
|
if ($callback($item, $key) === false) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve an external iterator
|
* Retrieve an external iterator
|
||||||
* @return Traversable An instance of an object implementing <b>Iterator</b> or
|
* @return Traversable An instance of an object implementing <b>Iterator</b> or
|
||||||
|
|||||||
@@ -1034,7 +1034,7 @@ class Request
|
|||||||
$filter = [];
|
$filter = [];
|
||||||
} else {
|
} else {
|
||||||
$filter = $filter ?: $this->filter;
|
$filter = $filter ?: $this->filter;
|
||||||
if (is_string($filter)) {
|
if (is_string($filter) && false === strpos($filter, '/')) {
|
||||||
$filter = explode(',', $filter);
|
$filter = explode(',', $filter);
|
||||||
} else {
|
} else {
|
||||||
$filter = (array) $filter;
|
$filter = (array) $filter;
|
||||||
@@ -1060,7 +1060,7 @@ class Request
|
|||||||
// 调用函数或者方法过滤
|
// 调用函数或者方法过滤
|
||||||
$value = call_user_func($filter, $value);
|
$value = call_user_func($filter, $value);
|
||||||
} elseif (is_scalar($value)) {
|
} elseif (is_scalar($value)) {
|
||||||
if (strpos($filter, '/')) {
|
if (false !== strpos($filter, '/')) {
|
||||||
// 正则过滤
|
// 正则过滤
|
||||||
if (!preg_match($filter, $value)) {
|
if (!preg_match($filter, $value)) {
|
||||||
// 匹配不成功返回默认值
|
// 匹配不成功返回默认值
|
||||||
|
|||||||
@@ -924,7 +924,7 @@ class Route
|
|||||||
} else {
|
} else {
|
||||||
$str = $key;
|
$str = $key;
|
||||||
}
|
}
|
||||||
if (is_string($str) && $str && 0 !== strpos(str_replace('|', '/', $url), $str)) {
|
if (is_string($str) && $str && 0 !== stripos(str_replace('|', '/', $url), $str)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
self::setOption($option);
|
self::setOption($option);
|
||||||
|
|||||||
@@ -780,11 +780,31 @@ abstract class Connection
|
|||||||
/**
|
/**
|
||||||
* 是否断线
|
* 是否断线
|
||||||
* @access protected
|
* @access protected
|
||||||
* @param \PDOException $e 异常
|
* @param \PDOException $e 异常对象
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isBreak($e)
|
protected function isBreak($e)
|
||||||
{
|
{
|
||||||
|
$info = [
|
||||||
|
'server has gone away',
|
||||||
|
'no connection to the server',
|
||||||
|
'Lost connection',
|
||||||
|
'is dead or not enabled',
|
||||||
|
'Error while sending',
|
||||||
|
'decryption failed or bad record mac',
|
||||||
|
'server closed the connection unexpectedly',
|
||||||
|
'SSL connection has been closed unexpectedly',
|
||||||
|
'Error writing data to the connection',
|
||||||
|
'Resource deadlock avoided',
|
||||||
|
];
|
||||||
|
|
||||||
|
$error = $e->getMessage();
|
||||||
|
|
||||||
|
foreach ($info as $msg) {
|
||||||
|
if (false !== stripos($error, $msg)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ class Query
|
|||||||
if (empty($this->options['table'])) {
|
if (empty($this->options['table'])) {
|
||||||
$this->options['table'] = $this->getTable();
|
$this->options['table'] = $this->getTable();
|
||||||
}
|
}
|
||||||
$key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
|
$key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options) . serialize($this->bind));
|
||||||
$result = Cache::get($key);
|
$result = Cache::get($key);
|
||||||
}
|
}
|
||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
@@ -444,7 +444,7 @@ class Query
|
|||||||
if (empty($this->options['table'])) {
|
if (empty($this->options['table'])) {
|
||||||
$this->options['table'] = $this->getTable();
|
$this->options['table'] = $this->getTable();
|
||||||
}
|
}
|
||||||
$guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
|
$guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options) . serialize($this->bind));
|
||||||
$result = Cache::get($guid);
|
$result = Cache::get($guid);
|
||||||
}
|
}
|
||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
@@ -596,7 +596,7 @@ class Query
|
|||||||
}
|
}
|
||||||
if ($lazyTime > 0) {
|
if ($lazyTime > 0) {
|
||||||
// 延迟写入
|
// 延迟写入
|
||||||
$guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition));
|
$guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition) . serialize($this->bind));
|
||||||
$step = $this->lazyWrite('inc', $guid, $step, $lazyTime);
|
$step = $this->lazyWrite('inc', $guid, $step, $lazyTime);
|
||||||
if (false === $step) {
|
if (false === $step) {
|
||||||
// 清空查询条件
|
// 清空查询条件
|
||||||
@@ -625,7 +625,7 @@ class Query
|
|||||||
}
|
}
|
||||||
if ($lazyTime > 0) {
|
if ($lazyTime > 0) {
|
||||||
// 延迟写入
|
// 延迟写入
|
||||||
$guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition));
|
$guid = md5($this->getTable() . '_' . $field . '_' . serialize($condition) . serialize($this->bind));
|
||||||
$step = $this->lazyWrite('dec', $guid, $step, $lazyTime);
|
$step = $this->lazyWrite('dec', $guid, $step, $lazyTime);
|
||||||
if (false === $step) {
|
if (false === $step) {
|
||||||
// 清空查询条件
|
// 清空查询条件
|
||||||
@@ -1902,6 +1902,9 @@ class Query
|
|||||||
$closure = $relation;
|
$closure = $relation;
|
||||||
$relation = $key;
|
$relation = $key;
|
||||||
$with[$key] = $key;
|
$with[$key] = $key;
|
||||||
|
} elseif (is_array($relation)) {
|
||||||
|
$subRelation = $relation;
|
||||||
|
$relation = $key;
|
||||||
} elseif (is_string($relation) && strpos($relation, '.')) {
|
} elseif (is_string($relation) && strpos($relation, '.')) {
|
||||||
$with[$key] = $relation;
|
$with[$key] = $relation;
|
||||||
list($relation, $subRelation) = explode('.', $relation, 2);
|
list($relation, $subRelation) = explode('.', $relation, 2);
|
||||||
@@ -2205,7 +2208,7 @@ class Query
|
|||||||
$options['where']['AND'] = $where;
|
$options['where']['AND'] = $where;
|
||||||
}
|
}
|
||||||
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
$key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成UPDATE SQL语句
|
// 生成UPDATE SQL语句
|
||||||
@@ -2293,7 +2296,7 @@ class Query
|
|||||||
// 判断查询缓存
|
// 判断查询缓存
|
||||||
$cache = $options['cache'];
|
$cache = $options['cache'];
|
||||||
unset($options['cache']);
|
unset($options['cache']);
|
||||||
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options) . serialize($this->bind));
|
||||||
$resultSet = Cache::get($key);
|
$resultSet = Cache::get($key);
|
||||||
}
|
}
|
||||||
if (!$resultSet) {
|
if (!$resultSet) {
|
||||||
@@ -2385,8 +2388,9 @@ class Query
|
|||||||
* @access public
|
* @access public
|
||||||
* @param mixed $value 缓存数据
|
* @param mixed $value 缓存数据
|
||||||
* @param array $options 缓存参数
|
* @param array $options 缓存参数
|
||||||
|
* @param array $bind 绑定参数
|
||||||
*/
|
*/
|
||||||
protected function getCacheKey($value, $options)
|
protected function getCacheKey($value, $options, $bind = [])
|
||||||
{
|
{
|
||||||
if (is_scalar($value)) {
|
if (is_scalar($value)) {
|
||||||
$data = $value;
|
$data = $value;
|
||||||
@@ -2394,9 +2398,9 @@ class Query
|
|||||||
$data = $value[1];
|
$data = $value[1];
|
||||||
}
|
}
|
||||||
if (isset($data)) {
|
if (isset($data)) {
|
||||||
return 'think:' . $options['table'] . '|' . $data;
|
return 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data;
|
||||||
} else {
|
} else {
|
||||||
return md5(serialize($options));
|
return md5(serialize($options) . serialize($bind));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2424,7 +2428,7 @@ class Query
|
|||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
} elseif (!empty($options['cache']) && true === $options['cache']['key'] && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
} elseif (!empty($options['cache']) && true === $options['cache']['key'] && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
$key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options['limit'] = 1;
|
$options['limit'] = 1;
|
||||||
@@ -2437,7 +2441,7 @@ class Query
|
|||||||
} elseif (is_string($cache['key'])) {
|
} elseif (is_string($cache['key'])) {
|
||||||
$key = $cache['key'];
|
$key = $cache['key'];
|
||||||
} elseif (!isset($key)) {
|
} elseif (!isset($key)) {
|
||||||
$key = md5(serialize($options));
|
$key = md5(serialize($options) . serialize($this->bind));
|
||||||
}
|
}
|
||||||
$result = Cache::get($key);
|
$result = Cache::get($key);
|
||||||
}
|
}
|
||||||
@@ -2648,7 +2652,7 @@ class Query
|
|||||||
// AR模式分析主键条件
|
// AR模式分析主键条件
|
||||||
$this->parsePkWhere($data, $options);
|
$this->parsePkWhere($data, $options);
|
||||||
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
} elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
|
||||||
$key = $this->getCacheKey($options['where']['AND'][$pk], $options);
|
$key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true !== $data && empty($options['where'])) {
|
if (true !== $data && empty($options['where'])) {
|
||||||
|
|||||||
@@ -130,17 +130,4 @@ class Mysql extends Connection
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否断线
|
|
||||||
* @access protected
|
|
||||||
* @param \PDOException $e 异常对象
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isBreak($e)
|
|
||||||
{
|
|
||||||
if (false !== stripos($e->getMessage(), 'server has gone away')) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title><?php echo lang('System Error'); ?></title>
|
<title><?php echo \think\Lang::get('System Error'); ?></title>
|
||||||
<meta name="robots" content="noindex,nofollow" />
|
<meta name="robots" content="noindex,nofollow" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user