diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 630d40a53..f1169fb1d 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -818,21 +818,26 @@ class Controller extends Object { foreach ($data as $model => $fields) { foreach ($fields as $field => $value) { - $key = $model . '.' . $field; - if (is_string($op)) { - $cond[$key] = $this->__postConditionMatch($op, $value); + $key = $model.'.'.$field; + $fieldOp = $op; + if (is_array($op) && array_key_exists($key, $op)) { + $fieldOp = $op[$key]; + } elseif (is_array($op) && array_key_exists($field, $op)) { + $fieldOp = $op[$field]; } elseif (is_array($op)) { - $opFields = array_keys($op); - if (in_array($key, $opFields) || in_array($field, $opFields)) { - if (in_array($key, $opFields)) { - $cond[$key] = $this->__postConditionMatch($op[$key], $value); - } else { - $cond[$key] = $this->__postConditionMatch($op[$field], $value); - } - } elseif (!$exclusive) { - $cond[$key] = $this->__postConditionMatch(null, $value); - } + $fieldOp = false; } + if ($exclusive && $fieldOp === false) { + continue; + } + $fieldOp = strtoupper(trim($fieldOp)); + if ($fieldOp == 'LIKE') { + $key = $key.' LIKE'; + $value = '%'.$value.'%'; + } elseif ($fieldOp && $fieldOp != '=') { + $key = $key.' '.$fieldOp; + } + $cond[$key] = $value; } } if ($bool != null && strtoupper($bool) != 'AND') { @@ -840,32 +845,6 @@ class Controller extends Object { } return $cond; } -/** - * Builds a matching condition using the specified operator and value, used by postConditions - * - * @param mixed $op A string containing an SQL comparison operator, or an array matching operators to fields - * @param string $value Value to check against - * @access private - */ - function __postConditionMatch($op, $value) { - if (is_string($op)) { - $op = strtoupper(trim($op)); - } - - switch($op) { - case '': - case '=': - case null: - return $value; - break; - case 'LIKE': - return 'LIKE %' . $value . '%'; - break; - default: - return $op . ' ' . $value; - break; - } - } /** * Deprecated, see Model::deconstruct(); * diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 360aedc2d..bc913675d 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -446,52 +446,6 @@ class ControllerTest extends CakeTestCase { $this->assertTrue($Controller->_afterScaffoldSaveError('')); $this->assertFalse($Controller->_scaffoldError('')); } -/** - * test__postConditionMatch method - * - * @access public - * @return void - */ - function test__postConditionMatch() { - $Controller =& new Controller(); - $value = 'val'; - - $result = $Controller->__postConditionMatch('=', $value); - $expected = $value; - $this->assertIdentical($result, $expected); - - $result = $Controller->__postConditionMatch('', $value); - $expected = $value; - $this->assertIdentical($result, $expected); - - $result = $Controller->__postConditionMatch(null, $value); - $expected = $value; - $this->assertIdentical($result, $expected); - - $result = $Controller->__postConditionMatch('LIKE', $value); - $expected = 'LIKE %'.$value.'%'; - $this->assertIdentical($result, $expected); - - $result = $Controller->__postConditionMatch('>', $value); - $expected = '> '.$value; - $this->assertIdentical($result, $expected); - - $result = $Controller->__postConditionMatch('<', $value); - $expected = '< '.$value; - $this->assertIdentical($result, $expected); - - $result = $Controller->__postConditionMatch('>=', $value); - $expected = '>= '.$value; - $this->assertIdentical($result, $expected); - - $result = $Controller->__postConditionMatch('<=', $value); - $expected = '<= '.$value; - $this->assertIdentical($result, $expected); - - $result = $Controller->__postConditionMatch('<>', $value); - $expected = '<> '.$value; - $this->assertIdentical($result, $expected); - } /** * testCleanUpFields method * @@ -737,9 +691,9 @@ class ControllerTest extends CakeTestCase { 'Model3.field3' => '<=', ); $expected = array( - 'Model1.field1' => '> 23', - 'Model2.field2' => "LIKE %string%", - 'Model3.field3' => '<= 23', + 'Model1.field1 >' => '23', + 'Model2.field2 LIKE' => "%string%", + 'Model3.field3 <=' => '23', ); $result = $Controller->postConditions($data, $ops); $this->assertIdentical($result, $expected);