diff --git a/public/main/inc/lib/message.lib.php b/public/main/inc/lib/message.lib.php index 887e44a22f..c5a953c866 100644 --- a/public/main/inc/lib/message.lib.php +++ b/public/main/inc/lib/message.lib.php @@ -282,12 +282,14 @@ class MessageManager } $messageId = $editMessageId; } else { + $group = Container::getUsergroupRepository()->find($group_id); + $message = (new Message()) ->setSender($userSender) ->addReceiver($userRecipient) ->setTitle($subject) ->setContent($content) - ->setGroup(api_get_group_entity($group_id)) + ->setGroup($group) ->setParent($parent) ; $em->persist($message); diff --git a/src/CoreBundle/Entity/Message.php b/src/CoreBundle/Entity/Message.php index 47d333a7d2..2a5ffd84b1 100644 --- a/src/CoreBundle/Entity/Message.php +++ b/src/CoreBundle/Entity/Message.php @@ -12,7 +12,6 @@ use ApiPlatform\Core\Annotation\ApiResource; use ApiPlatform\Core\Annotation\ApiSubresource; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; -use Chamilo\CourseBundle\Entity\CGroup; use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; @@ -202,10 +201,10 @@ class Message protected ?MessageRelUser $firstReceiver; /** - * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CGroup") - * @ORM\JoinColumn(name="group_id", referencedColumnName="iid", nullable=true, onDelete="CASCADE") + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Usergroup") + * @ORM\JoinColumn(name="group_id", referencedColumnName="id", onDelete="CASCADE") */ - protected ?CGroup $group = null; + protected ?Usergroup $group = null; /** * @var Collection|Message[] @@ -518,20 +517,12 @@ class Message return $this; } - /** - * @return MessageFeedback[]|Collection - */ - public function getLikes() - { - return $this->likes; - } - - public function getGroup(): ?CGroup + public function getGroup(): ?Usergroup { return $this->group; } - public function setGroup(?CGroup $group): self + public function setGroup(?Usergroup $group): self { // $this->msgType = self::MESSAGE_TYPE_GROUP; $this->group = $group; diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php b/src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php index bfd90b31c0..364c7ff064 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php @@ -70,7 +70,7 @@ final class Version20200821224242 extends AbstractMigrationChamilo $this->addSql('DELETE FROM message WHERE user_receiver_id IS NOT NULL AND user_receiver_id NOT IN (SELECT id FROM user)'); if (!$table->hasForeignKey('FK_B6BD307FFE54D947')) { - $this->addSql('ALTER TABLE message ADD CONSTRAINT FK_B6BD307FFE54D947 FOREIGN KEY (group_id) REFERENCES c_group_info (iid) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE message ADD CONSTRAINT FK_B6BD307FFE54D947 FOREIGN KEY (group_id) REFERENCES usergroup (id) ON DELETE CASCADE;'); } if (!$table->hasForeignKey('FK_B6BD307F727ACA70')) {