Fixes #16192: yii\db\Command::logQuery() is now protected, extracted getCacheKey() from queryInternal()

This commit is contained in:
drlibra
2018-07-27 21:39:16 +05:00
committed by Alexander Makarov
parent b32ba1132e
commit 32c7c4161b
2 changed files with 25 additions and 9 deletions

View File

@ -37,7 +37,7 @@ Yii Framework 2 Change Log
- Bug #16292: Fixed misconfigured CORS filter exception throwing. Now it throws `InvalidConfigException` in Debug mode (khvalov)
- Bug #16301: Fixed `yii\web\User::setIdentity()` to clear access check cache while setting identity object to `null` (Izumi-kun)
- Bug #16322: Fixed strings were not were not compared using timing attack resistant approach while CSRF token validation (samdark, Felix Wiedemann)
- Chg #16192: `yii\db\Command::logQuery()` is now protected (drlibra)
- Chg #16192: `yii\db\Command::logQuery()` is now protected, extracted `getCacheKey()` from `queryInternal()` (drlibra)
- Bug #16377: Fixed `yii\base\Event:off()` undefined index error when event handler does not match (razvanphp)
2.0.15.1 March 21, 2018

View File

@ -1140,14 +1140,8 @@ class Command extends Component
if (is_array($info)) {
/* @var $cache \yii\caching\CacheInterface */
$cache = $info[0];
$cacheKey = [
__CLASS__,
$method,
$fetchMode,
$this->db->dsn,
$this->db->username,
$rawSql ?: $rawSql = $this->getRawSql(),
];
$rawSql = $rawSql ?: $this->getRawSql();
$cacheKey = $this->getCacheKey($method, $fetchMode, $rawSql);
$result = $cache->get($cacheKey);
if (is_array($result) && isset($result[0])) {
Yii::debug('Query result served from cache', 'yii\db\Command::query');
@ -1187,6 +1181,28 @@ class Command extends Component
return $result;
}
/**
* Returns the cache key for the query.
*
* @param string $method method of PDOStatement to be called
* @param int $fetchMode the result fetch mode. Please refer to [PHP manual](http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php)
* for valid fetch modes.
* @param string $rawSql the raw SQL with parameter values inserted into the corresponding placeholders
* @return array the cache key
* @since 2.0.16
*/
protected function getCacheKey($method, $fetchMode, $rawSql)
{
return [
__CLASS__,
$method,
$fetchMode,
$this->db->dsn,
$this->db->username,
$rawSql,
];
}
/**
* Marks a specified table schema to be refreshed after command execution.
* @param string $name name of the table, which schema should be refreshed.