XF 2.2 LogEntry double instead single


Well-known member
Hi everybody,

i have a public function with an API call. Everytime the api call is made, i want to set an log entry. This works fine, but i have no the issue that after every call the log entry is doubled in the database. I couldn't find out what's the problem. I do not have the call twice in the code.

Has someone a hint what is wrong or where i can take a look? Its my first XF2 add-on and in the learning phase.. ;)

This is the function i build:

public function fetchLocationData($location)
        $serviceID = 'geocode';
        $address = $location;
        $params = [
            'address' => $address,

        $apiUrl = $this->fetchService($serviceID, $params);

         * @var \GuzzleHttp\Client $client
        $client = \XF::app()->http()->client();
        $geocodeResponse = $client->get($apiUrl)->getBody();
        $geocodeData = \GuzzleHttp\json_decode($geocodeResponse);

        /** @var \XT\Membermap\XF\Entity\User $visitor */
        $visitorId = \XF::visitor()->user_id;
        $logData = [
            'user_id' => $visitorId,
            'request_url' => $apiUrl,
            'request_status' => $geocodeData->status,
            'request_data' => $geocodeData->results,

        $requestLog = $this->em()->create('XT\Membermap:Log');

        if (
            && $geocodeData->status == 'OK'
            && isset($geocodeData->results)
            && isset($geocodeData->results[0])
        ) {
            return [
                'latitude' => $geocodeData->results[0]->geometry->location->lat,
                'longitude' => $geocodeData->results[0]->geometry->location->lng


Well-known member
So, we are only talking about this part, right?

        $requestLog = $this->em()->create('XT\Membermap:Log');

This seems o.k. So, if you have the log entry twice, then the function was executed twice.

You could try to insert die() on various places in order to better isolate the problem.

Does this have anything to do with the XF API (never worked with it)?

P.S. Do you have in your \XT\Membermap\Entity\Log class or any other entity class any relevant _preSave? or _postSave actions?
Last edited: