Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
4e8e22da
Commit
4e8e22da
authored
Jul 04, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed issue with elasticsearch >=1.2.0
do not use scripting as it is disabled by default and will cause edge case queries to fail fixes #4187
parent
489a5e36
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
4 deletions
+52
-4
QueryBuilder.php
extensions/elasticsearch/QueryBuilder.php
+4
-4
ActiveRecordTest.php
tests/unit/extensions/elasticsearch/ActiveRecordTest.php
+30
-0
ActiveRecordTestTrait.php
tests/unit/framework/ar/ActiveRecordTestTrait.php
+18
-0
No files found.
extensions/elasticsearch/QueryBuilder.php
View file @
4e8e22da
...
...
@@ -205,8 +205,8 @@ class QueryBuilder extends \yii\base\Object
$parts
=
[];
foreach
(
$condition
as
$attribute
=>
$value
)
{
if
(
$attribute
==
'_id'
)
{
if
(
$value
==
null
)
{
// there is no null pk
$parts
[]
=
[
'
script'
=>
[
'script'
=>
'0==1'
]];
if
(
$value
==
=
null
)
{
// there is no null pk
$parts
[]
=
[
'
terms'
=>
[
'_uid'
=>
[]]];
// this condition is equal to WHERE false
}
else
{
$parts
[]
=
[
'ids'
=>
[
'values'
=>
is_array
(
$value
)
?
$value
:
[
$value
]]];
}
...
...
@@ -287,7 +287,7 @@ class QueryBuilder extends \yii\base\Object
$values
=
(
array
)
$values
;
if
(
empty
(
$values
)
||
$column
===
[])
{
return
$operator
===
'in'
?
[
'
script'
=>
[
'script'
=>
'0==1'
]]
:
[];
return
$operator
===
'in'
?
[
'
terms'
=>
[
'_uid'
=>
[]]]
:
[];
// this condition is equal to WHERE false
}
if
(
count
(
$column
)
>
1
)
{
...
...
@@ -307,7 +307,7 @@ class QueryBuilder extends \yii\base\Object
}
if
(
$column
==
'_id'
)
{
if
(
empty
(
$values
)
&&
$canBeNull
)
{
// there is no null pk
$filter
=
[
'
script'
=>
[
'script'
=>
'0==1'
]];
$filter
=
[
'
terms'
=>
[
'_uid'
=>
[]]];
// this condition is equal to WHERE false
}
else
{
$filter
=
[
'ids'
=>
[
'values'
=>
array_values
(
$values
)]];
if
(
$canBeNull
)
{
...
...
tests/unit/extensions/elasticsearch/ActiveRecordTest.php
View file @
4e8e22da
...
...
@@ -667,5 +667,35 @@ class ActiveRecordTest extends ElasticSearchTestCase
Event
::
off
(
BaseActiveRecord
::
className
(),
BaseActiveRecord
::
EVENT_AFTER_FIND
);
}
public
function
testFindEmptyPkCondition
()
{
/* @var $this TestCase|ActiveRecordTestTrait */
/* @var $orderItemClass \yii\db\ActiveRecordInterface */
$orderItemClass
=
$this
->
getOrderItemClass
();
$orderItem
=
new
$orderItemClass
();
$orderItem
->
setAttributes
([
'order_id'
=>
1
,
'item_id'
=>
1
,
'quantity'
=>
1
,
'subtotal'
=>
30.0
],
false
);
$orderItem
->
save
(
false
);
$this
->
afterSave
();
$orderItems
=
$orderItemClass
::
find
()
->
where
([
'_id'
=>
[
$orderItem
->
getPrimaryKey
()]])
->
all
();
$this
->
assertEquals
(
1
,
count
(
$orderItems
));
$orderItems
=
$orderItemClass
::
find
()
->
where
([
'_id'
=>
[]])
->
all
();
$this
->
assertEquals
(
0
,
count
(
$orderItems
));
$orderItems
=
$orderItemClass
::
find
()
->
where
([
'_id'
=>
null
])
->
all
();
$this
->
assertEquals
(
0
,
count
(
$orderItems
));
$orderItems
=
$orderItemClass
::
find
()
->
where
([
'IN'
,
'_id'
,
[
$orderItem
->
getPrimaryKey
()]])
->
all
();
$this
->
assertEquals
(
1
,
count
(
$orderItems
));
$orderItems
=
$orderItemClass
::
find
()
->
where
([
'IN'
,
'_id'
,
[]])
->
all
();
$this
->
assertEquals
(
0
,
count
(
$orderItems
));
$orderItems
=
$orderItemClass
::
find
()
->
where
([
'IN'
,
'_id'
,
[
null
]])
->
all
();
$this
->
assertEquals
(
0
,
count
(
$orderItems
));
}
// TODO test AR with not mapped PK
}
tests/unit/framework/ar/ActiveRecordTestTrait.php
View file @
4e8e22da
...
...
@@ -1046,4 +1046,22 @@ trait ActiveRecordTestTrait
Event
::
off
(
BaseActiveRecord
::
className
(),
BaseActiveRecord
::
EVENT_AFTER_FIND
);
}
public
function
testFindEmptyInCondition
()
{
/* @var $customerClass \yii\db\ActiveRecordInterface */
$customerClass
=
$this
->
getCustomerClass
();
/* @var $this TestCase|ActiveRecordTestTrait */
$customers
=
$customerClass
::
find
()
->
where
([
'id'
=>
[
1
]])
->
all
();
$this
->
assertEquals
(
1
,
count
(
$customers
));
$customers
=
$customerClass
::
find
()
->
where
([
'id'
=>
[]])
->
all
();
$this
->
assertEquals
(
0
,
count
(
$customers
));
$customers
=
$customerClass
::
find
()
->
where
([
'IN'
,
'id'
,
[
1
]])
->
all
();
$this
->
assertEquals
(
1
,
count
(
$customers
));
$customers
=
$customerClass
::
find
()
->
where
([
'IN'
,
'id'
,
[]])
->
all
();
$this
->
assertEquals
(
0
,
count
(
$customers
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment