mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Check method existence before calling.
Datasource does not implemente calculate() or expression(). Only call them if they exist. Fixes #2535
This commit is contained in:
parent
f3b990bf0f
commit
4bb4040851
1 changed files with 4 additions and 1 deletions
|
@ -2589,6 +2589,10 @@ class Model extends Object {
|
||||||
protected function _findCount($state, $query, $results = array()) {
|
protected function _findCount($state, $query, $results = array()) {
|
||||||
if ($state === 'before') {
|
if ($state === 'before') {
|
||||||
$db = $this->getDataSource();
|
$db = $this->getDataSource();
|
||||||
|
$query['order'] = false;
|
||||||
|
if (!method_exists($db, 'calculate') || !method_exists($db, 'expression')) {
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
if (empty($query['fields'])) {
|
if (empty($query['fields'])) {
|
||||||
$query['fields'] = $db->calculate($this, 'count');
|
$query['fields'] = $db->calculate($this, 'count');
|
||||||
} elseif (is_string($query['fields']) && !preg_match('/count/i', $query['fields'])) {
|
} elseif (is_string($query['fields']) && !preg_match('/count/i', $query['fields'])) {
|
||||||
|
@ -2596,7 +2600,6 @@ class Model extends Object {
|
||||||
$db->expression($query['fields']), 'count'
|
$db->expression($query['fields']), 'count'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
$query['order'] = false;
|
|
||||||
return $query;
|
return $query;
|
||||||
} elseif ($state === 'after') {
|
} elseif ($state === 'after') {
|
||||||
foreach (array(0, $this->alias) as $key) {
|
foreach (array(0, $this->alias) as $key) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue