mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
fixed parsing of conditions with 'NOT' in TranslateBehavior
This commit is contained in:
parent
3440615323
commit
f0bbcb3ffc
3 changed files with 56 additions and 43 deletions
|
@ -245,11 +245,26 @@ class TranslateBehavior extends ModelBehavior {
|
|||
* @return array The list of translated fields that are in the conditions.
|
||||
*/
|
||||
protected function _checkConditions(Model $Model, $query) {
|
||||
$conditionFields = array();
|
||||
if (empty($query['conditions']) || (!empty($query['conditions']) && !is_array($query['conditions']))) {
|
||||
return $conditionFields;
|
||||
return array();
|
||||
}
|
||||
return $this->_getConditionFields($Model, $query['conditions']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts condition field names recursively.
|
||||
*
|
||||
* @param Model $Model The model being read.
|
||||
* @param array $conditions The conditions array.
|
||||
* @return array The list of condition fields.
|
||||
*/
|
||||
protected function _getConditionFields(Model $Model, $conditions) {
|
||||
$conditionFields = array();
|
||||
foreach ($conditions as $col => $val) {
|
||||
if (is_array($val)) {
|
||||
$subConditionFields = $this->_getConditionFields($Model, $val);
|
||||
$conditionFields = array_merge($conditionFields, $subConditionFields);
|
||||
}
|
||||
foreach ($query['conditions'] as $col => $val) {
|
||||
foreach ($this->settings[$Model->alias] as $field => $assoc) {
|
||||
if (is_numeric($field)) {
|
||||
$field = $assoc;
|
||||
|
|
|
@ -1460,7 +1460,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
'table' => (object)array(
|
||||
'tablePrefix' => '',
|
||||
'table' => 'article_i18n',
|
||||
'schemaName' => 'test',
|
||||
'schemaName' => 'cakephp_test',
|
||||
),
|
||||
'conditions' => array(
|
||||
'TranslatedArticle.id' => (object)array(
|
||||
|
@ -1478,7 +1478,7 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
'table' => (object)array(
|
||||
'tablePrefix' => '',
|
||||
'table' => 'article_i18n',
|
||||
'schemaName' => 'test',
|
||||
'schemaName' => 'cakephp_test',
|
||||
),
|
||||
'conditions' => array(
|
||||
'TranslatedArticle.id' => (object)array(
|
||||
|
@ -1535,13 +1535,30 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
),
|
||||
'fields' => 'COUNT(DISTINCT(`TranslatedArticle`.`id`)) AS count',
|
||||
'joins' => array(
|
||||
array(
|
||||
'type' => 'INNER',
|
||||
'alias' => 'TranslateArticleModel',
|
||||
'table' => (object)array(
|
||||
'tablePrefix' => '',
|
||||
'table' => 'article_i18n',
|
||||
'schemaName' => 'cakephp_test',
|
||||
),
|
||||
'conditions' => array(
|
||||
'`TranslatedArticle`.`id`' => (object)array(
|
||||
'type' => 'identifier',
|
||||
'value' => '`TranslateArticleModel`.`foreign_key`',
|
||||
),
|
||||
'`TranslateArticleModel`.`model`' => 'TranslatedArticle',
|
||||
'`TranslateArticleModel`.`locale`' => 'eng',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'INNER',
|
||||
'alias' => 'I18n__title',
|
||||
'table' => (object)array(
|
||||
'tablePrefix' => '',
|
||||
'table' => 'article_i18n',
|
||||
'schemaName' => 'test',
|
||||
'schemaName' => 'cakephp_test',
|
||||
),
|
||||
'conditions' => array(
|
||||
'TranslatedArticle.id' => (object)array(
|
||||
|
@ -1553,24 +1570,6 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
'I18n__title.locale' => 'eng',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'INNER',
|
||||
'alias' => 'I18n__body',
|
||||
'table' => (object)array(
|
||||
'tablePrefix' => '',
|
||||
'table' => 'article_i18n',
|
||||
'schemaName' => 'test',
|
||||
),
|
||||
'conditions' => array(
|
||||
'TranslatedArticle.id' => (object)array(
|
||||
'type' => 'identifier',
|
||||
'value' => 'I18n__body.foreign_key',
|
||||
),
|
||||
'I18n__body.model' => 'TranslatedArticle',
|
||||
'I18n__body.field' => 'body',
|
||||
'I18n__body.locale' => 'eng',
|
||||
),
|
||||
),
|
||||
),
|
||||
'limit' => 2,
|
||||
'offset' => null,
|
||||
|
|
|
@ -6505,6 +6505,23 @@ class ModelReadTest extends BaseModelTest {
|
|||
),
|
||||
'fields' => 'COUNT(DISTINCT(`TranslatedArticle`.`id`)) AS count',
|
||||
'joins' => array(
|
||||
array(
|
||||
'type' => 'INNER',
|
||||
'alias' => 'TranslateArticleModel',
|
||||
'table' => (object)array(
|
||||
'tablePrefix' => '',
|
||||
'table' => 'article_i18n',
|
||||
'schemaName' => 'cakephp_test',
|
||||
),
|
||||
'conditions' => array(
|
||||
'`TranslatedArticle`.`id`' => (object)array(
|
||||
'type' => 'identifier',
|
||||
'value' => '`TranslateArticleModel`.`foreign_key`',
|
||||
),
|
||||
'`TranslateArticleModel`.`model`' => 'TranslatedArticle',
|
||||
'`TranslateArticleModel`.`locale`' => 'eng',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'INNER',
|
||||
'alias' => 'I18n__title',
|
||||
|
@ -6523,24 +6540,6 @@ class ModelReadTest extends BaseModelTest {
|
|||
'I18n__title.locale' => 'eng',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'INNER',
|
||||
'alias' => 'I18n__body',
|
||||
'table' => (object)array(
|
||||
'tablePrefix' => '',
|
||||
'table' => 'article_i18n',
|
||||
'schemaName' => 'test',
|
||||
),
|
||||
'conditions' => array(
|
||||
'TranslatedArticle.id' => (object)array(
|
||||
'type' => 'identifier',
|
||||
'value' => 'I18n__body.foreign_key',
|
||||
),
|
||||
'I18n__body.model' => 'TranslatedArticle',
|
||||
'I18n__body.field' => 'body',
|
||||
'I18n__body.locale' => 'eng',
|
||||
),
|
||||
),
|
||||
),
|
||||
'limit' => 2,
|
||||
'offset' => null,
|
||||
|
@ -7325,7 +7324,7 @@ class ModelReadTest extends BaseModelTest {
|
|||
'limit' => 2,
|
||||
);
|
||||
$result = $TestModel->find('count', $options);
|
||||
$this->assertEquals(2, $result);
|
||||
$this->assertEquals(3, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue