Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
hasNextDefinition example
// increment last id with iterator offset
$offset
->
setLastId
(
$iterator
->
getOffset
(
)
)
;
$alias
=
$this
->helper->
getIndexName
(
$definition
->
getEntityDefinition
(
)
,
(string)
$offset
->
getLanguageId
(
)
)
;
$index
=
$alias
. '_' .
$offset
->
getTimestamp
(
)
;
// return indexing message for current offset
return
new
ElasticsearchIndexingMessage
(
new
IndexingDto
(
array_values
(
$ids
)
,
$index
,
$entity
)
,
$offset
,
$context
)
;
}
if
(
!
$offset
->
hasNextDefinition
(
)
)
{
return
null;
}
// increment definition offset
$offset
->
selectNextDefinition
(
)
;
// reset last id to start iterator at the beginning
$offset
->
setLastId
(
null
)
;
return
$this
->
createIndexingMessage
(
$offset
,
$context
)
;
}
public
function
testItConvertsDefinitionsToSerializableNamesAndCanDoAnDefinitionRoundTrip
(
)
: void
{
$timestamp
=
(
new
\
DateTime
(
)
)
->
getTimestamp
(
)
;
$offset
=
new
IndexerOffset
(
[
'foo', 'bar'
]
,
[
'product', 'product_manufacturer'
]
,
$timestamp
)
;
static
::
assertEquals
(
ProductDefinition::ENTITY_NAME,
$offset
->
getDefinition
(
)
)
;
static
::
assertTrue
(
$offset
->
hasNextDefinition
(
)
)
;
static
::
assertSame
(
$timestamp
,
$offset
->
getTimestamp
(
)
)
;
static
::
assertNull
(
$offset
->
getLastId
(
)
)
;
$offset
->
selectNextDefinition
(
)
;
static
::
assertEquals
(
ProductManufacturerDefinition::ENTITY_NAME,
$offset
->
getDefinition
(
)
)
;
static
::
assertEmpty
(
$offset
->
getDefinitions
(
)
)
;
static
::
assertFalse
(
$offset
->
hasNextDefinition
(
)
)
;
$offset
->
resetDefinitions
(
)
;
if
(
!
$definition
)
{
throw
ElasticsearchIndexingException::
definitionNotFound
(
(string)
$offset
->
getDefinition
(
)
)
;
}
$entity
=
$definition
->
getEntityDefinition
(
)
->
getEntityName
(
)
;
$iterator
=
$this
->iteratorFactory->
createIterator
(
$definition
->
getEntityDefinition
(
)
,
$offset
->
getLastId
(
)
,
$this
->indexingBatchSize
)
;
$ids
=
$iterator
->
fetch
(
)
;
if
(
empty
(
$ids
)
)
{
if
(
!
$offset
->
hasNextDefinition
(
)
)
{
return
null;
}
// increment definition offset
$offset
->
selectNextDefinition
(
)
;
// reset last id to start iterator at the beginning
$offset
->
setLastId
(
null
)
;
return
$this
->
createIndexingMessage
(
$offset
)
;
}