src/Persister/InPlacePagerPersister.php
private function insertPage($page, PagerInterface $pager, ObjectPersisterInterface $objectPersister, array $options = array())
    {
        $pager->setCurrentPage($page);

        $event = new PreFetchObjectsEvent($pager, $objectPersister, $options);
        $this->dispatcher->dispatch(Events::PRE_FETCH_OBJECTS, $event);
        $pager = $event->getPager();
        $options = $event->getOptions();

        $objects = $pager->getCurrentPageResults();

        if ($objects instanceof \Traversable) {
            $objects = iterator_to_array($objects);
        }

        $event = new PreInsertObjectsEvent($pager, $objectPersister, $objects, $options);
        $this->dispatcher->dispatch(Events::PRE_INSERT_OBJECTS, $event);
        $pager = $event->getPager();
        $options = $event->getOptions();
        $objects = $event->getObjects();

        try {
            if (!empty($objects)) {
                $objectPersister->insertMany($objects);
            }

            $event = new PostInsertObjectsEvent($pager, $objectPersister, $objects, $options);
            $this->dispatcher->dispatch(Events::POST_INSERT_OBJECTS, $event);
        } catch (\Exception $e) {
            $event = new OnExceptionEvent($pager, $objectPersister, $e, $objects, $options);
            $this->dispatcher->dispatch(Events::ON_EXCEPTION, $event);

            if ($event->isIgnored()) {
                $event = new PostInsertObjectsEvent($pager, $objectPersister, $objects, $options);
                $this->dispatcher->dispatch(Events::POST_INSERT_OBJECTS, $event);
            } else {
                $e = $event->getException();

                throw $e;
            }
        }
    }
private function insertPage($page, PagerInterface $pager, ObjectPersisterInterface $objectPersister, array $options = array())
    {
        $pager->setCurrentPage($page);

        $event = new PreFetchObjectsEvent($pager, $objectPersister, $options);
        $this->dispatcher->dispatch(Events::PRE_FETCH_OBJECTS, $event);
        $pager = $event->getPager();
        $options = $event->getOptions();

        $objects = $pager->getCurrentPageResults();

        if ($objects instanceof \Traversable) {
            $objects = iterator_to_array($objects);
        }

        $event = new PreInsertObjectsEvent($pager, $objectPersister, $objects, $options);
        $this->dispatcher->dispatch(Events::PRE_INSERT_OBJECTS, $event);
        $pager = $event->getPager();
        $options = $event->getOptions();
        $objects = $event->getObjects();

        try {
            if (!empty($objects)) {
                $objectPersister->insertMany($objects);
            }

            $event = new PostInsertObjectsEvent($pager, $objectPersister, $objects, $options);
            $this->dispatcher->dispatch(Events::POST_INSERT_OBJECTS, $event);
        } catch (\Exception $e) {
            $event = new OnExceptionEvent($pager, $objectPersister, $e, $objects, $options);
            $this->dispatcher->dispatch(Events::ON_EXCEPTION, $event);

            if ($event->isIgnored()) {
                $event = new PostInsertObjectsEvent($pager, $objectPersister, $objects, $options);
                $this->dispatcher->dispatch(Events::POST_INSERT_OBJECTS, $event);
            } else {
                $e = $event->getException();

                throw $e;
            }
        }
    }
@param int $page
@param PagerInterface $pager
@param ObjectPersisterInterface $objectPersister
@param array $options

@throws \Exception