Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Comment #34

Closed
ping86 opened this issue Aug 12, 2014 · 2 comments
Closed

Create Comment #34

ping86 opened this issue Aug 12, 2014 · 2 comments

Comments

@ping86
Copy link
Contributor

ping86 commented Aug 12, 2014

How I can create a comment?

       $postManager = $this->get('ekino.wordpress.manager.post');
       $userManager = $this->get('ekino.wordpress.manager.user');

       $post = $postManager->find(1);
       $user = $userManager->find(1);


        $commentManager = $this->get('ekino.wordpress.manager.comment');
        $comment = new Comment();
        $comment->setAuthor("username");
        $comment->setContent("My comment");
        $comment->setAuthorEmail("mail@example.com");
        $comment->setApproved("1");
        $comment->setAgent("");
        $comment->setAuthorUrl("");
        $comment->setAuthorIp("");
        $comment->setDate(new \Datetime());
        $comment->setDateGmt(new \Datetime());
        $comment->setKarma(1);
        $comment->setType("1");
        $comment->setUser($user);
        $comment->setPost($post);

If I use this code, doctrine return:

ContextErrorException: Catchable Fatal Error: Object of class Proxies\__CG__\Ekino\WordpressBundle\Entity\User could not be converted to string in /var/www/opos/current/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php line 120

I need create in the user entity (Ekino\WordpressBundle\Entity\User) the next method:

    public function __toString()
    {
        return $this->getUsername();
    }

Then I have this error.

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'comment_parent' cannot be null

In summary, when I want create a comment. Are all fields are required? In wordpress the parent field is not required. This also happens in the fields, agent, authorUrl, user....

@eko
Copy link
Collaborator

eko commented Aug 12, 2014

Hi @ping86,

Thank you for reporting this issue.

I think this is because the user field here should be mapped with a relation to the User entity: https://github.com/ekino/EkinoWordpressBundle/blob/master/Resources/config/doctrine/model/Comment.orm.xml#L51

About mandatory fields, I think all fields are not required indeed but the mapping looks wrong if so.

I will have a look at this as soon as possible.

Feel free to submit a PR if you have some time for fixing it.

@eko
Copy link
Collaborator

eko commented Sep 7, 2014

@ping86 Can we close this issue then? Thank you

@ping86 ping86 closed this as completed Sep 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants