kuzzleio / sdk-php

Official php SDK for Kuzzle
http://docs.kuzzle.io/sdk-reference
Apache License 2.0
6 stars 1 forks source link

Problem with insert #8

Closed Astro-Otter-Space closed 7 years ago

Astro-Otter-Space commented 8 years ago

Hi,

I have a problem to create a document with PHP-SDK. The exception message is :

"ErrorException' with message '[mapper_parsing_exception] failed to parse".

I have compared data's type with the collection mapping : it's correct. I tried to create my document directly in BO : OK. I tried with a REST request (with POSTMAN) and the document have been created. It's the first time I can't create a document with PHP SDK. Our JSON

{       
       "id":45,
        "title":"Test daily tip",
        "status":1,"type_message":6,
        "challengeInstanceId":null,
        "theme":"Message de f\u00e9licitations et renforcement",
        "userId":410,
        "date":"2016-08-05 12:25:34",
        "programDate":null,
        "subTheme":"Bilan quotidien",
        "catchPhrase":"accroche test daily tip",
        "addText":"texte test daily tip",
        "body":"did you know test daily tip",
        "messageId":"daily_tip_in_progress",
        "icon":"",
        "fromUserId":null,
        "notifId":null,
        "notifText":null,
        "notifState":null,
        "notifParams":null
}

In PHP :

$this->kuzzle->save($message, $this->container->getParameter('kuzzle.index'));
    /**
     * @param AbstractKuzzleDocument $document
     * @param $index
     * @return AbstractKuzzleDocument
     */
    public function save(AbstractKuzzleDocument $document, $index)
    {
        $collection = $document::getKuzzleCollectionName();
        if (is_null($document->getKuzzleId())) {
            return $this->create($document, $index, $collection);
        }
        return $this->update($document, $index, $collection);
    }

And method create (in a class who override Kuzzle.php from Symfony-bridge) :

    /**
     * Create a document in Kuzzle from object implementing KuzzleDocumentInterface
     *
     * @param KuzzleDocumentInterface $document
     * @param string $index
     * @param string $collection
     * @return KuzzleDocumentInterface
     */
    public function create(KuzzleDocumentInterface $document, $index, $collection)
    {
        if (method_exists($document, 'setId')) {
            $document->setId($this->getUniqueId($index, $collection));
        }
        var_dump($document->toKuzzleDocument());
        return $document::fromKuzzleDocument(parent::createDocument($document->toKuzzleDocument(), $index, $collection)->serialize());
    }

And parent::createDocument() is the method in Symfony-Kuzzle-Bridge.

Thank you

Astro-Otter-Space commented 8 years ago

Update : I've seen some documents are created and some not. I've compared documents and noted documents with field "body" not empty are the error while documents with field "body" empty are created in Kuzzle.

Is word "body" reserved in Kuzzle ?

ballinette commented 8 years ago

Hi. Hmm, I wonder if it's not the same issue as #10 , that has just been fixed Can you try again with latest release ?

dbengsch commented 7 years ago

The bug comes from the way we use the payload of the request. If the request is sent with a field body it will in fact try to use the body as the content of the document. Other fields at the root of the payload would be completely ignore for the request. as a result, the document has not the same format as the one initially indexed (and mapped).

dbengsch commented 7 years ago

Solved with the recent Request refactor