ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

This topic contains 2 replies, has 1 voice, and was last updated by  jakabadambalazs 2 years, 4 months ago.

  • Creator
    Topic
  • #7376

    jakabadambalazs
    Participant

    I have two bundles: Account and Contact and I am playing around with e-mails. Since I wanted to create an entity which would hold e-mails for both Accounts and Contacts, in AccountBundle I have created this entity:<?php
    namespace Mekit\Bundle\AccountBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;
    use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
    use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
    use Oro\Bundle\AddressBundle\Entity\AbstractEmail;
    use Oro\Bundle\EmailBundle\Entity\EmailInterface;

    use Mekit\Bundle\ContactBundle\Entity\Contact;

    /**
    * @ORM\Entity
    * @ORM\Table("mekit_account_email", indexes={
    * @ORM\Index(name="primary_email_idx", columns={"email", "is_primary"})
    * })
    * @Config(
    * defaultValues={
    * "entity"={
    * "icon"="icon-envelope"
    * },
    * "note"={
    * "immutable"=true
    * },
    * "activity"={
    * "immutable"=true
    * },
    * "attachment"={
    * "immutable"=true
    * }
    * }
    * )
    */
    class AccountEmail extends AbstractEmail implements EmailInterface {
    /**
    * @ORM\ManyToOne(targetEntity="Mekit\Bundle\AccountBundle\Entity\Account", inversedBy="emails")
    * @ORM\JoinColumn(name="account_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
    */
    protected $ownerAccount;

    /**
    * @ORM\ManyToOne(targetEntity="Mekit\Bundle\ContactBundle\Entity\Contact", inversedBy="emails")
    * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
    */
    protected $ownerContact;

    /**
    * @return Account
    */
    public function getOwnerAccount() {
    return $this->ownerAccount;
    }

    /**
    * @param Account $ownerAccount
    * @return $this
    */
    public function setOwnerAccount(Account $ownerAccount = null) {
    $this->ownerAccount = $ownerAccount;
    return $this;
    }

    /**
    * @return bool
    */
    public function isAccountEMail() {
    return (!is_null($this->ownerAccount));
    }

    /**
    * @return Contact
    */
    public function getOwnerContact() {
    return $this->ownerContact;
    }

    /**
    * @param Contact $ownerContact
    * @return $this
    */
    public function setOwnerContact(Contact $ownerContact = null) {
    $this->ownerContact = $ownerContact;
    return $this;
    }

    /**
    * @return bool
    */
    public function isContactEmail() {
    return (!is_null($this->ownerContact));
    }

    /**
    * Returns entity which owns this Email
    * @return Account|Contact|null
    */
    public function getEmailOwner() {
    if($this->isAccountEMail()) {
    return $this->getOwnerAccount();
    } else if ($this->isContactEmail()) {
    return $this->getOwnerContact();
    }
    return null;
    }

    /**
    * {@inheritdoc}
    */
    public function getEmailField() {
    return 'email';
    }
    }

    … and in both Mekit\Bundle\AccountBundle\Entity\Account and Mekit\Bundle\ContactBundle\Entity\Contact I have created the “emails” property creating the necessary relationships.

    It seemed like a good idea because now I have emails stored in the same table.

    Everything works apart from when I try to delete a Contact through the rest api controller which says:<b>Notice</b>: Undefined index: owner in <b>/home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php</b> on line <b>1753</b><br />
    <br />
    <b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/master.mekitcrm.bradipo/oro/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php</b> on line <b>1758</b><br />
    {"status":"error","status_code":500,"status_text":"Internal Server Error","current_content":"","message":"Unrecognized field: primary"}

    and it is right becuase i renamed the owner fieled to $ownerAccount and $ownerContact.

    Actually removing Accounts (event with e-mails) works correctly.

    Do you recon I can fix this somehow?
    I think the answer should be somehere in the ‘EmailOwnerProviderStorage::getEmailOwnerFieldName’ / ‘EmailOwnerProviderStorage::getEmailOwnerColumnName’ but I cannot figure out how to do this.

    hmmm, or maybe it has not to do with Emails???


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #7379

    jakabadambalazs
    Participant

    … after editing the above code got split into bits – here it is again:


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #7380

    jakabadambalazs
    Participant

    Sorry about this – this problem had nothing to do with emails. I removed every connection to emails and the problem was still there – so reading the error message better I noticed the “Unrecognized field: primary” – and I realized that it had to do with Addresses. In particular my Contact entity extends the ExtendContact which in turn extends the BasePerson did NOT implement addresses and in fact (later I noticed that) Sf was complaining about my entity as being invalid saying:

    So I made it happy and now my problem is gone
    a\


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.