In the case of a known visit, we have to do the following actions:

1) Insert the new action
2) Update the visit information

@param Visitor $visitor
@param Action $action
@param $visitIsConverted
@throws VisitorNotFoundInDb
772652
protected function handleExistingVisit($visitIsConverted)
    {
        Common::printDebug("Visit is known (IP = " . IPUtils::binaryToStringIP($this->getVisitorIp()) . ")");

        // TODO it should be its own dimension
        $this->visitProperties->setProperty('time_spent_ref_action', $this->getTimeSpentReferrerAction());

        $valuesToUpdate = $this->getExistingVisitFieldsToUpdate($visitIsConverted);

        // update visitorInfo
        foreach ($valuesToUpdate as $name => $value) {
            $this->visitProperties->setProperty($name, $value);
        }

        foreach ($this->requestProcessors as $processor) {
            $processor->onExistingVisit($valuesToUpdate, $this->visitProperties, $this->request);
        }

        $this->updateExistingVisit($valuesToUpdate);

        $this->visitProperties->setProperty('visit_last_action_time', $this->request->getCurrentTimestamp());
    }
422620
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $restContentType = $data->contentType;

        parent::visit($visitor, $generator, $restContentType);
        $visitor->setHeader(
            'Location',
            $this->router->generate(
                'ezpublish_rest_loadContentType' . $this->getUrlTypeSuffix($restContentType->contentType->status),
                array(
                    'contentTypeId' => $restContentType->contentType->id,
                )
            )
        );
        $visitor->setStatus(201);
    }
643197
public function onNewAction(Request $request, Visitor $visitor, Action $action)
    {
        return substr($request->getParam('pv_id'), 0, 6);
    }
385678
public void visitWith(ExecArg.Visitor visitor) {
        for (ExecArg arg : getList()) {
            arg.accept(visitor);
        }
    }
32353
public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
    {
        if ($this->extensionInitialized) {
            throw new LogicException('Unable to add a node visitor as extensions have already been initialized.');
        }

        $this->staging->addNodeVisitor($visitor);
    }
107876
public function visit(NodeVisitorInterface $visitor)
    {
        $visitor->enterListItem($this);

        parent::visit($visitor);

        $visitor->leaveListItem($this);
    }
1013647
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('View');
        $visitor->setHeader('Content-Type', $generator->getMediaType('View'));

        $generator->startAttribute(
            'href',
            $this->router->generate('ezpublish_rest_views_load', array('viewId' => $data->identifier))
        );
        $generator->endAttribute('href');

        $generator->startValueElement('identifier', $data->identifier);
        $generator->endValueElement('identifier');

        // BEGIN Query
        $generator->startObjectElement('Query');
        $generator->endObjectElement('Query');
        // END Query

        // BEGIN Result
        $generator->startObjectElement('Result', 'ViewResult');
        $generator->startAttribute(
            'href',
            $this->router->generate('ezpublish_rest_views_load_results', array('viewId' => $data->identifier))
        );
        $generator->endAttribute('href');

        // BEGIN Result metadata
        $generator->startValueElement('count', $data->searchResults->totalCount);
        $generator->endValueElement('count');

        $generator->startValueElement('time', $data->searchResults->time);
        $generator->endValueElement('time');

        $generator->startValueElement('timedOut', $generator->serializeBool($data->searchResults->timedOut));
        $generator->endValueElement('timedOut');

        $generator->startValueElement('maxScore', $data->searchResults->maxScore);
        $generator->endValueElement('maxScore');
        // END Result metadata

        // BEGIN searchHits
        $generator->startHashElement('searchHits');
        $generator->startList('searchHit');

        foreach ($data->searchResults->searchHits as $searchHit) {
            $generator->startObjectElement('searchHit');

            $generator->startAttribute('score', (float)$searchHit->score);
            $generator->endAttribute('score');

            $generator->startAttribute('index', (string)$searchHit->index);
            $generator->endAttribute('index');

            $generator->startObjectElement('value');

            // @todo Refactor
            if ($searchHit->valueObject instanceof ApiValues\Content) {
                /** @var \eZ\Publish\API\Repository\Values\Content\Content $searchHit->valueObject */
                $contentInfo = $searchHit->valueObject->contentInfo;
                $valueObject = new RestContentValue(
                    $contentInfo,
                    $this->locationService->loadLocation($contentInfo->mainLocationId),
                    $searchHit->valueObject,
                    $searchHit->valueObject->getContentType(),
                    $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo())
                );
            } elseif ($searchHit->valueObject instanceof ApiValues\Location) {
                $valueObject = $searchHit->valueObject;
            } elseif ($searchHit->valueObject instanceof ApiValues\ContentInfo) {
                $valueObject = new RestContentValue($searchHit->valueObject);
            } else {
                throw new Exceptions\InvalidArgumentException('Unhandled object type');
            }

            $visitor->visitValueObject($valueObject);
            $generator->endObjectElement('value');
            $generator->endObjectElement('searchHit');
        }

        $generator->endList('searchHit');

        $generator->endHashElement('searchHits');
        // END searchHits

        $generator->endObjectElement('Result');
        // END Result

        $generator->endObjectElement('View');
    }
686237
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('CountryList');
        $visitor->setHeader('Content-Type', $generator->getMediaType('CountryList'));
        $visitor->setHeader('Accept-Patch', false);

        $generator->startList('Country');

        foreach ($data->countries as $country) {
            $generator->startObjectElement('Country', 'Country');

            $generator->startAttribute('id', $country['Alpha2']);
            $generator->endAttribute('id');

            $generator->startValueElement('name', $country['Name']);
            $generator->endValueElement('name');

            $generator->startValueElement('Alpha2', $country['Alpha2']);
            $generator->endValueElement('Alpha2');

            $generator->startValueElement('Alpha3', $country['Alpha3']);
            $generator->endValueElement('Alpha3');

            $generator->startValueElement('IDC', $country['IDC']);
            $generator->endValueElement('IDC');

            $generator->endObjectElement('Country');
        }
        $generator->endList('Country');
        $generator->endObjectElement('CountryList');
    }
700489
public function addVisitor(VisitorInterface $visitor, $priority = 0)
    {
        $this->sortedVisitors = null;

        $this->visitors[spl_object_hash($visitor)] = array(
            'priority' => $priority,
            'visitor' => $visitor
        );

        return $this;
    }
861172
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('UserRefList');
        $visitor->setHeader('Content-Type', $generator->getMediaType('UserRefList'));
        //@todo Needs refactoring, disabling certain headers should not be done this way
        $visitor->setHeader('Accept-Patch', false);

        $generator->startAttribute('href', $data->path);
        $generator->endAttribute('href');

        $generator->startList('User');
        foreach ($data->users as $user) {
            $generator->startObjectElement('User');

            $generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadUser', array('userId' => $user->contentInfo->id)));
            $generator->endAttribute('href');

            $generator->endObjectElement('User');
        }
        $generator->endList('User');

        $generator->endObjectElement('UserRefList');
    }
681300
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $restFieldDefinition = $data;
        $fieldDefinition = $restFieldDefinition->fieldDefinition;
        $contentType = $restFieldDefinition->contentType;

        $urlTypeSuffix = $this->getUrlTypeSuffix($contentType->status);

        $generator->startObjectElement('FieldDefinition');
        $visitor->setHeader('Content-Type', $generator->getMediaType('FieldDefinition'));

        if ($contentType->status === APIContentType::STATUS_DRAFT) {
            $visitor->setHeader('Accept-Patch', $generator->getMediaType('FieldDefinitionUpdate'));
        }

        $generator->startAttribute(
            'href',
            $this->router->generate(
                "ezpublish_rest_loadContentType{$urlTypeSuffix}FieldDefinition",
                array(
                    'contentTypeId' => $contentType->id,
                    'fieldDefinitionId' => $fieldDefinition->id,
                )
            )
        );
        $generator->endAttribute('href');

        $generator->startValueElement('id', $fieldDefinition->id);
        $generator->endValueElement('id');

        $generator->startValueElement('identifier', $fieldDefinition->identifier);
        $generator->endValueElement('identifier');

        $generator->startValueElement('fieldType', $fieldDefinition->fieldTypeIdentifier);
        $generator->endValueElement('fieldType');

        $generator->startValueElement('fieldGroup', $fieldDefinition->fieldGroup);
        $generator->endValueElement('fieldGroup');

        $generator->startValueElement('position', $fieldDefinition->position);
        $generator->endValueElement('position');

        $generator->startValueElement(
            'isTranslatable',
            $this->serializeBool($generator, $fieldDefinition->isTranslatable)
        );
        $generator->endValueElement('isTranslatable');

        $generator->startValueElement(
            'isRequired',
            $this->serializeBool($generator, $fieldDefinition->isRequired)
        );
        $generator->endValueElement('isRequired');

        $generator->startValueElement(
            'isInfoCollector',
            $this->serializeBool($generator, $fieldDefinition->isInfoCollector)
        );
        $generator->endValueElement('isInfoCollector');

        $this->fieldTypeSerializer->serializeFieldDefaultValue(
            $generator,
            $fieldDefinition->fieldTypeIdentifier,
            $fieldDefinition->defaultValue
        );

        $generator->startValueElement(
            'isSearchable',
            $this->serializeBool($generator, $fieldDefinition->isSearchable)
        );
        $generator->endValueElement('isSearchable');

        $this->visitNamesList($generator, $fieldDefinition->getNames());

        $descriptions = $fieldDefinition->getDescriptions();
        if (is_array($descriptions)) {
            $this->visitDescriptionsList($generator, $descriptions);
        }

        $this->fieldTypeSerializer->serializeFieldSettings(
            $generator,
            $fieldDefinition->fieldTypeIdentifier,
            $fieldDefinition->getFieldSettings()
        );

        $this->fieldTypeSerializer->serializeValidatorConfiguration(
            $generator,
            $fieldDefinition->fieldTypeIdentifier,
            $fieldDefinition->getValidatorConfiguration()
        );

        $generator->endObjectElement('FieldDefinition');
    }
584635
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('Location');
        $visitor->setHeader('Content-Type', $generator->getMediaType('Location'));
        $visitor->setHeader('Accept-Patch', $generator->getMediaType('LocationUpdate'));

        $location = $data->location;
        $contentInfo = $location->getContentInfo();

        $generator->startAttribute(
            'href',
            $this->router->generate(
                'ezpublish_rest_loadLocation',
                array('locationPath' => trim($location->pathString, '/'))
            )
        );
        $generator->endAttribute('href');

        $generator->startValueElement('id', $location->id);
        $generator->endValueElement('id');

        $generator->startValueElement('priority', $location->priority);
        $generator->endValueElement('priority');

        $generator->startValueElement(
            'hidden',
            $this->serializeBool($generator, $location->hidden)
        );
        $generator->endValueElement('hidden');

        $generator->startValueElement(
            'invisible',
            $this->serializeBool($generator, $location->invisible)
        );
        $generator->endValueElement('invisible');

        $generator->startObjectElement('ParentLocation', 'Location');
        if (trim($location->pathString, '/') !== '1') {
            $generator->startAttribute(
                'href',
                $this->router->generate(
                    'ezpublish_rest_loadLocation',
                    array(
                        'locationPath' => implode('/', array_slice($location->path, 0, count($location->path) - 1)),
                    )
                )
            );
            $generator->endAttribute('href');
        }
        $generator->endObjectElement('ParentLocation');

        $generator->startValueElement('pathString', $location->pathString);
        $generator->endValueElement('pathString');

        $generator->startValueElement('depth', $location->depth);
        $generator->endValueElement('depth');

        $generator->startValueElement('childCount', $data->childCount);
        $generator->endValueElement('childCount');

        $generator->startValueElement('remoteId', $location->remoteId);
        $generator->endValueElement('remoteId');

        $generator->startObjectElement('Children', 'LocationList');
        $generator->startAttribute(
            'href',
            $this->router->generate(
                'ezpublish_rest_loadLocationChildren',
                array(
                    'locationPath' => trim($location->pathString, '/'),
                )
            )
        );
        $generator->endAttribute('href');
        $generator->endObjectElement('Children');

        $generator->startObjectElement('Content');
        $generator->startAttribute(
            'href',
            $this->router->generate('ezpublish_rest_loadContent', array('contentId' => $contentInfo->id))
        );
        $generator->endAttribute('href');
        $generator->endObjectElement('Content');

        $generator->startValueElement('sortField', $this->serializeSortField($location->sortField));
        $generator->endValueElement('sortField');

        $generator->startValueElement('sortOrder', $this->serializeSortOrder($location->sortOrder));
        $generator->endValueElement('sortOrder');

        $generator->startObjectElement('UrlAliases', 'UrlAliasRefList');
        $generator->startAttribute(
            'href',
            $this->router->generate(
                'ezpublish_rest_listLocationURLAliases',
                array('locationPath' => trim($location->pathString, '/'))
            )
        );
        $generator->endAttribute('href');
        $generator->endObjectElement('UrlAliases');

        $generator->startObjectElement('ContentInfo', 'ContentInfo');
        $generator->startAttribute(
            'href',
            $this->router->generate(
                'ezpublish_rest_loadContent',
                array('contentId' => $contentInfo->id)
            )
        );
        $generator->endAttribute('href');
        $visitor->visitValueObject(new RestContentValue($contentInfo));
        $generator->endObjectElement('ContentInfo');

        $generator->endObjectElement('Location');
    }
183181
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('ErrorMessage');

        $statusCode = $this->getStatus();
        $visitor->setStatus($statusCode);
        $visitor->setHeader('Content-Type', $generator->getMediaType('ErrorMessage'));

        $generator->startValueElement('errorCode', $statusCode);
        $generator->endValueElement('errorCode');

        $generator->startValueElement('errorMessage', $this->httpStatusCodes[$statusCode]);
        $generator->endValueElement('errorMessage');

        if ($data instanceof Translatable && $this->translator) {
            /** @Ignore */
            $errorDescription = $this->translator->trans($data->getMessageTemplate(), $data->getParameters(), 'repository_exceptions');
        } else {
            $errorDescription = $data->getMessage();
        }
        $generator->startValueElement('errorDescription', $errorDescription);
        $generator->endValueElement('errorDescription');

        if ($this->debug) {
            $generator->startValueElement('trace', $data->getTraceAsString());
            $generator->endValueElement('trace');

            $generator->startValueElement('file', $data->getFile());
            $generator->endValueElement('file');

            $generator->startValueElement('line', $data->getLine());
            $generator->endValueElement('line');
        }

        if ($previous = $data->getPrevious()) {
            $generator->startObjectElement('Previous', 'ErrorMessage');
            $visitor->visitValueObject($previous);
            $generator->endObjectElement('Previous');
        }

        $generator->endObjectElement('ErrorMessage');
    }
1188502
public function accept(VisitorInterface $visitor): void
    {
        $visitor->visitBefore($this);

        foreach ($this->getChildren() as $node) {
            $node->accept($visitor);
        }

        $visitor->visitAfter($this);
    }
825406
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $generator->startObjectElement('limitation');

        $generator->startAttribute('identifier', $data->getIdentifier());
        $generator->endAttribute('identifier');

        $generator->startObjectElement('values');
        $generator->startList('values');

        foreach ($data->limitationValues as $limitationValue) {
            $generator->startObjectElement('ref');
            $generator->startAttribute('href', $limitationValue);
            $generator->endAttribute('href');
            $generator->endObjectElement('ref');
        }

        $generator->endList('values');
        $generator->endObjectElement('values');

        $generator->endObjectElement('limitation');
    }
96459
public function visit(Visitor $visitor, Generator $generator, $data)
    {
        $status = $data->created ? 201 : 200;
        $visitor->setStatus($status);

        $visitor->setHeader('Content-Type', $generator->getMediaType('Session'));
        //@todo Needs refactoring, disabling certain headers should not be done this way
        $visitor->setHeader('Accept-Patch', false);

        $generator->startObjectElement('Session');
        $this->visitUserSessionAttributes($visitor, $generator, $data);
        $generator->endObjectElement('Session');
    }
551370
public function addVisitor($location, ResponseVisitorInterface $visitor)
    {
        $this->factory->addResponseVisitor($location, $visitor);

        return $this;
    }