private function doScheduleInsert($document, &$visited)
{
$oid = \spl_object_hash($document);
if (isset($visited[$oid])) {
return;
}
$visited[$oid] = true;
$class = $this->dm->getClassMetadata(get_class($document));
$state = $this->getDocumentState($document);
switch ($state) {
case self::STATE_NEW:
$this->persistNew($class, $document);
break;
case self::STATE_MANAGED:
// TODO: Change Tracking Deferred Explicit
break;
case self::STATE_REMOVED:
// document becomes managed again
unset($this->scheduledRemovals[$oid]);
$this->documentState[$oid] = self::STATE_MANAGED;
break;
case self::STATE_DETACHED:
throw new \InvalidArgumentException("Detached document passed to persist().");
break;
}
$this->cascadeScheduleInsert($class, $document, $visited);
}