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
6e6353e2
Commit
6e6353e2
authored
Jan 07, 2015
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed indentation
parent
dc7aa25a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
32 deletions
+32
-32
ActiveFixture.php
extensions/elasticsearch/ActiveFixture.php
+32
-32
No files found.
extensions/elasticsearch/ActiveFixture.php
View file @
6e6353e2
...
@@ -29,13 +29,13 @@ use yii\test\BaseActiveFixture;
...
@@ -29,13 +29,13 @@ use yii\test\BaseActiveFixture;
*/
*/
class
ActiveFixture
extends
BaseActiveFixture
class
ActiveFixture
extends
BaseActiveFixture
{
{
/**
/**
* @var Connection|string the DB connection object or the application component ID of the DB connection.
* @var Connection|string the DB connection object or the application component ID of the DB connection.
* After the DbFixture object is created, if you want to change this property, you should only assign it
* After the DbFixture object is created, if you want to change this property, you should only assign it
* with a DB connection object.
* with a DB connection object.
*/
*/
public
$db
=
'elasticsearch'
;
public
$db
=
'elasticsearch'
;
/**
/**
* @var string the name of the index that this fixture is about. If this property is not set,
* @var string the name of the index that this fixture is about. If this property is not set,
* the name will be determined via [[modelClass]].
* the name will be determined via [[modelClass]].
* @see modelClass
* @see modelClass
...
@@ -66,14 +66,14 @@ class ActiveFixture extends BaseActiveFixture
...
@@ -66,14 +66,14 @@ class ActiveFixture extends BaseActiveFixture
if
(
!
isset
(
$this
->
modelClass
)
&&
(
!
isset
(
$this
->
index
)
||
!
isset
(
$this
->
type
)))
{
if
(
!
isset
(
$this
->
modelClass
)
&&
(
!
isset
(
$this
->
index
)
||
!
isset
(
$this
->
type
)))
{
throw
new
InvalidConfigException
(
'Either "modelClass" or "index" and "type" must be set.'
);
throw
new
InvalidConfigException
(
'Either "modelClass" or "index" and "type" must be set.'
);
}
}
/* @var $modelClass ActiveRecord */
/* @var $modelClass ActiveRecord */
$modelClass
=
$this
->
modelClass
;
$modelClass
=
$this
->
modelClass
;
if
(
$this
->
index
===
null
)
{
if
(
$this
->
index
===
null
)
{
$this
->
index
=
$modelClass
::
index
();
$this
->
index
=
$modelClass
::
index
();
}
}
if
(
$this
->
type
===
null
)
{
if
(
$this
->
type
===
null
)
{
$this
->
type
=
$modelClass
::
type
();
$this
->
type
=
$modelClass
::
type
();
}
}
}
}
/**
/**
...
@@ -90,21 +90,21 @@ class ActiveFixture extends BaseActiveFixture
...
@@ -90,21 +90,21 @@ class ActiveFixture extends BaseActiveFixture
$this
->
resetIndex
();
$this
->
resetIndex
();
$this
->
data
=
[];
$this
->
data
=
[];
$mapping
=
$this
->
db
->
createCommand
()
->
getMapping
(
$this
->
index
,
$this
->
type
);
$mapping
=
$this
->
db
->
createCommand
()
->
getMapping
(
$this
->
index
,
$this
->
type
);
if
(
isset
(
$mapping
[
$this
->
index
][
'mappings'
][
$this
->
type
][
'_id'
][
'path'
]))
{
if
(
isset
(
$mapping
[
$this
->
index
][
'mappings'
][
$this
->
type
][
'_id'
][
'path'
]))
{
$idField
=
$mapping
[
$this
->
index
][
'mappings'
][
$this
->
type
][
'_id'
][
'path'
];
$idField
=
$mapping
[
$this
->
index
][
'mappings'
][
$this
->
type
][
'_id'
][
'path'
];
}
else
{
}
else
{
$idField
=
'_id'
;
$idField
=
'_id'
;
}
}
foreach
(
$this
->
getData
()
as
$alias
=>
$row
)
{
foreach
(
$this
->
getData
()
as
$alias
=>
$row
)
{
$options
=
[];
$options
=
[];
$id
=
isset
(
$row
[
$idField
])
?
$row
[
$idField
]
:
null
;
$id
=
isset
(
$row
[
$idField
])
?
$row
[
$idField
]
:
null
;
$response
=
$this
->
db
->
createCommand
()
->
insert
(
$this
->
index
,
$this
->
type
,
$row
,
$id
,
$options
);
$response
=
$this
->
db
->
createCommand
()
->
insert
(
$this
->
index
,
$this
->
type
,
$row
,
$id
,
$options
);
if
(
$id
===
null
)
{
if
(
$id
===
null
)
{
$row
[
$idField
]
=
$response
[
'_id'
];
$row
[
$idField
]
=
$response
[
'_id'
];
}
}
$this
->
data
[
$alias
]
=
$row
;
$this
->
data
[
$alias
]
=
$row
;
}
}
}
}
...
@@ -136,10 +136,10 @@ class ActiveFixture extends BaseActiveFixture
...
@@ -136,10 +136,10 @@ class ActiveFixture extends BaseActiveFixture
*/
*/
protected
function
resetIndex
()
protected
function
resetIndex
()
{
{
$this
->
db
->
createCommand
([
$this
->
db
->
createCommand
([
'index'
=>
$this
->
index
,
'index'
=>
$this
->
index
,
'type'
=>
$this
->
type
,
'type'
=>
$this
->
type
,
'queryParts'
=>
[
'query'
=>
[
'match_all'
=>
new
\stdClass
()]],
'queryParts'
=>
[
'query'
=>
[
'match_all'
=>
new
\stdClass
()]],
])
->
deleteByQuery
();
])
->
deleteByQuery
();
}
}
}
}
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