Forums › Forums › OroCRM › OroCRM – Programming Questions › Creating Custom Activity Entity
This topic contains 6 replies, has 2 voices, and was last updated by archy_bold 7 years, 11 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- April 22, 2016 at 7:09 am #25175
Hi there.
I’m trying to create a custom activity entity in code but I’m having some trouble. I’ve followed the instructions on this page and created my entity, which extends an ExtendEntity, which in turn implements the ActivityInterface. I’ve also set up a migration to create the table.
I then run the following commands to run the migrations and update the schema/cache:
Shell1234php app/console oro:entity-extend:update-configphp app/console oro:entity-extend:update-schemaphp app/console oro:entity-extend:cache:clearphp app/console oro:entity-config:updateBut looking in the oro_entity_config table, I can’t see my new entity. I’ve added several custom entities and it has always worked doing things this way.
I then tried to add the associations to my own custom entities with ActivityExtension migration tool regardless. Obviously it failed to run and had the following error:
PHP1$className must not be emptyWhich I guess is because the entity isn’t present in the database. Am I missing something here? I’m a little worried even if I get this working, that it might have trouble ensuring the migrations run at the correct time when deploying the bundle.
Thanks for your help.
Simon
- CreatorTopic
- AuthorReplies
- April 24, 2016 at 11:27 pm #25176
Hi @archy_bold,
please try to run
PHP12rm -rf app/cache/dev/*php app/console oro:platform:update --forcethis will run migrations and renew all caches.
April 26, 2016 at 2:00 am #25177Thanks, but I still get the same error. And the entity doesn’t show up in the database either.
May 3, 2016 at 3:00 am #25178Is the error because I’ve manually written my migrations? Should I be letting oro:platform:update handle the table creation?
May 4, 2016 at 2:45 am #25179Here’s the code, if that will help:
Entity/UserActivity.php
PHP123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331/*** UserActivity* @ORM\HasLifecycleCallbacks()* @ORM\Table(* name="trueconn_user_activity",* indexes={* @ORM\Index(name="user_owner_id_idx",columns={"user_owner_id"}),* @ORM\Index(name="organization_id_idx",columns={"organization_id"})* }* )* @Config(* defaultValues={* "grouping"={"groups"={"activity"}},* "ownership"={* "owner_type"="USER",* "owner_field_name"="owner",* "owner_column_name"="user_owner_id",* "organization_field_name"="organization",* "organization_column_name"="organization_id"* }* }* )*/class UserActivity extends ExtendUserActivity{/*** @var int** @ORM\Id* @ORM\Column(type="integer", name="id")* @ORM\GeneratedValue(strategy="AUTO")*/protected $id;/*** @var string** @ORM\Column(name="action", type="string", length=255, nullable=true)*/protected $action;/*** @var string** @ORM\Column(name="reference", type="string", length=100, nullable=true)*/protected $reference;/*** @var string** @ORM\Column(name="item", type="string", length=255, nullable=true)*/protected $item;/*** @var double** @ORM\Column(name="value", type="money", nullable=true)*/protected $value;/*** @var string** @ORM\Column(name="currency", type="string", length=10, nullable=true)*/protected $currency;/*** @var User* @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")* @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")*/protected $owner;/*** @var Organization** @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization")* @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")*/protected $organization;/*** @var \DateTime $createdAt** @ORM\Column(name="created_at", type="datetime")* @ConfigField(* defaultValues={* "entity"={* "label"="oro.ui.created_at"* }* }* )*/protected $createdAt;/*** @var \DateTime $updatedAt** @ORM\Column(name="updated_at", type="datetime")* @ConfigField(* defaultValues={* "entity"={* "label"="oro.ui.updated_at"* }* }* )*/protected $updatedAt;/*** @param int $id** @return $this*/public function setId($id){$this->id = $id;return $this;}/*** @return int*/public function getId(){return $this->id;}/*** @param string $action** @return $this*/public function setAction($action){$this->action = $action;return $this;}/*** @return string*/public function getAction(){return $this->action;}/*** @param string $reference** @return $this*/public function setReference($reference){$this->reference = $reference;return $this;}/*** @return string*/public function getReference(){return $this->reference;}/*** @param string $item** @return $this*/public function setItem($item){$this->item = $item;return $this;}/*** @return string*/public function getItem(){return $this->item;}/*** @param double $value** @return $this*/public function setValue($value){$this->value = $value;return $this;}/*** @return double*/public function getValue(){return $this->value;}/*** @param string $currency** @return $this*/public function setCurrency($currency){$this->currency = $currency;return $this;}/*** @return string*/public function getCurrency(){return $this->currency;}/*** @return User*/public function getOwner(){return $this->owner;}/*** @param User $user*/public function setOwner(User $user){$this->owner = $user;}/*** Set organization** @param Organization $organization* @return Customer*/public function setOrganization(Organization $organization = null){$this->organization = $organization;return $this;}/*** Get organization** @return Organization*/public function getOrganization(){return $this->organization;}/*** @param \DateTime $createdAt** @return $this*/public function setCreatedAt(\DateTime $createdAt){$this->createdAt = $createdAt;return $this;}/*** @return \DateTime*/public function getCreatedAt(){return $this->createdAt;}/*** @param \DateTime $updatedAt** @return $this*/public function setUpdatedAt(\DateTime $updatedAt){$this->updatedAt = $updatedAt;return $this;}/*** @return \DateTime*/public function getUpdatedAt(){return $this->updatedAt;}/*** @ORM\PrePersist*/public function prePersist(){if (!$this->createdAt) {$this->createdAt = new \DateTime('now', new \DateTimeZone('UTC'));}$this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));}/*** @ORM\PreUpdate*/public function preUpdate(){$this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));}}Model/ExtendUserActivity.php
PHP123456789101112131415class ExtendUserActivity implements ActivityInterface{use ExtendActivity;/*** Constructor** The real implementation of this method is auto generated.** IMPORTANT: If the derived class has own constructor it must call parent constructor.*/public function __construct(){}}Migration 1
PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344454647class UserActivityTable implements Migration{/*** {@inheritdoc}*/public function up(Schema $schema, QueryBag $queries){self::addTable($schema);}/*** {@inheritdoc}*/public static function addTable(Schema $schema){$table = $schema->createTable('trueconn_user_activity');$table->addColumn('id', 'integer', ['autoincrement' => true]);$table->addColumn('action', 'string', ['notnull' => false, 'length' => 255]);$table->addColumn('reference', 'string', ['notnull' => false, 'length' => 100]);$table->addColumn('item', 'string', ['notnull' => false, 'length' => 255]);$table->addColumn('value', 'float', ['notnull' => false]);$table->addColumn('currency', 'string', ['notnull' => false, 'length' => 10]);$table->addColumn('user_owner_id', 'integer', ['notnull' => false]);$table->addColumn('organization_id', 'integer', ['notnull' => false]);$table->addColumn('created_at', 'datetime', []);$table->addColumn('updated_at', 'datetime', []);$table->setPrimaryKey(['id']);$table->addIndex(['user_owner_id'], 'user_owner_id_idx', []);$table->addIndex(['organization_id'], 'organization_id_idx', []);$table->addForeignKeyConstraint($schema->getTable('oro_user'),['user_owner_id'],['id'],['onDelete' => 'SET NULL', 'onUpdate' => null]);$table->addForeignKeyConstraint($schema->getTable('oro_organization'),['organization_id'],['id'],['onDelete' => 'SET NULL', 'onUpdate' => null]);}}Migration 2
PHP123456789101112131415161718192021222324252627282930313233343536class UserActivityAssociations implements Migration, ActivityExtensionAwareInterface{/** @var ActivityExtension */protected $activityExtension;/*** {@inheritdoc}*/public function setActivityExtension(ActivityExtension $activityExtension){$this->activityExtension = $activityExtension;}/*** {@inheritdoc}*/public function up(Schema $schema, QueryBag $queries){self::addActivityAssociations($schema, $this->activityExtension);}/*** Enables Email activity for User entity** @param Schema $schema* @param ActivityExtension $activityExtension*/public static function addActivityAssociations(Schema $schema, ActivityExtension $activityExtension){// Customers$activityExtension->addActivityAssociation($schema, 'trueconn_user_activity', 'trueconn_customer');// Orders$activityExtension->addActivityAssociation($schema, 'trueconn_user_activity', 'trueconn_order');}}May 4, 2016 at 4:24 am #25180I’ve run the following command to see if my new entity is being recognised and I don’t see it in the list at all. Despite it containing all my other custom entities. There must be something wrong with the entity itself.
Shell1php app/console oro:entity-config:update --dry-runMay 4, 2016 at 8:42 am #25181Ok, I’m an idiot. My entity didn’t have the Entity annotation…
- AuthorReplies
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.