private function doGetDocumentIndexes($documentName, array &$visited)
{
if (isset($visited[$documentName])) {
return array();
}
$visited[$documentName] = true;
$class = $this->dm->getClassMetadata($documentName);
$indexes = $this->prepareIndexes($class);
$embeddedDocumentIndexes = array();
// Add indexes from embedded & referenced documents
foreach ($class->fieldMappings as $fieldMapping) {
if (isset($fieldMapping['embedded'])) {
if (isset($fieldMapping['targetDocument'])) {
$possibleEmbeds = array($fieldMapping['targetDocument']);
} elseif (isset($fieldMapping['discriminatorMap'])) {
$possibleEmbeds = array_unique($fieldMapping['discriminatorMap']);
} else {
continue;
}
foreach ($possibleEmbeds as $embed) {
if (isset($embeddedDocumentIndexes[$embed])) {
$embeddedIndexes = $embeddedDocumentIndexes[$embed];
} else {
$embeddedIndexes = $this->doGetDocumentIndexes($embed, $visited);
$embeddedDocumentIndexes[$embed] = $embeddedIndexes;
}
foreach ($embeddedIndexes as $embeddedIndex) {
foreach ($embeddedIndex['keys'] as $key => $value) {
$embeddedIndex['keys'][$fieldMapping['name'] . '.' . $key] = $value;
unset($embeddedIndex['keys'][$key]);
}
$indexes[] = $embeddedIndex;
}
}
} elseif (isset($fieldMapping['reference']) && isset($fieldMapping['targetDocument'])) {
foreach ($indexes as $idx => $index) {
$newKeys = array();
foreach ($index['keys'] as $key => $v) {
if ($key == $fieldMapping['name']) {
$key = $fieldMapping['storeAs'] === ClassMetadataInfo::REFERENCE_STORE_AS_ID ? $key : $key . '.$id';
}
$newKeys[$key] = $v;
}
$indexes[$idx]['keys'] = $newKeys;
}
}
}
return $indexes;
}