Calendar: Fix migration about invitations/subscriptions

pull/5269/head
Angel Fernando Quiroz Campos 2 years ago
parent 7f23b2c1b9
commit 2580ebb364
  1. 137
      src/CoreBundle/Entity/AgendaEventInvitation.php
  2. 65
      src/CoreBundle/Entity/AgendaEventInvitee.php
  3. 12
      src/CoreBundle/Entity/AgendaEventSubscriber.php
  4. 32
      src/CoreBundle/Entity/AgendaEventSubscription.php
  5. 25
      src/CoreBundle/Migrations/Schema/V200/Version20230904173400.php
  6. 34
      src/CoreBundle/Migrations/Schema/V200/Version20230904173401.php
  7. 6
      src/CoreBundle/Migrations/Schema/V200/Version20240112131200.php

@ -1,137 +0,0 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'agenda_event_invitation')]
#[ORM\Entity()]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap([
'invitation' => 'Chamilo\CoreBundle\Entity\AgendaEventInvitation',
'subscription' => 'Chamilo\CoreBundle\Entity\AgendaEventSubscription',
])]
class AgendaEventInvitation
{
use TimestampableTypedEntity;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected ?int $id = null;
#[ORM\OneToMany(
mappedBy: 'invitation',
targetEntity: AgendaEventInvitee::class,
cascade: ['persist', 'remove'],
orphanRemoval: true
)]
protected Collection $invitees;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'resourceNodes')]
#[ORM\JoinColumn(name: 'creator_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
protected User $creator;
public function __construct()
{
$this->invitees = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getInvitees(): Collection
{
return $this->invitees;
}
public function setInvitees(Collection $invitees): self
{
$this->invitees = $invitees;
return $this;
}
public function addInvitee(AgendaEventInvitee $invitee): self
{
$invitee->setInvitation($this);
$this->invitees->add($invitee);
return $this;
}
public function removeInviteeUser(User $user): self
{
/** @var AgendaEventInvitee $invitee */
$invitee = $this
->invitees
->filter(function (AgendaEventInvitee $invitee) use ($user) {
return $invitee->getUser() === $user;
})
->first()
;
if ($invitee) {
$this->invitees->removeElement($invitee);
$invitee->setInvitation(null);
}
return $this;
}
public function removeInvitees(): self
{
$this->invitees = new ArrayCollection();
return $this;
}
public function getCreator(): User
{
return $this->creator;
}
public function setCreator(User $creator): self
{
$this->creator = $creator;
return $this;
}
public function hasUserAsInvitee(User $user): bool
{
return $this->invitees->exists(
function (int $key, AgendaEventInvitee $invitee) use ($user) {
return $invitee->getUser() === $user;
}
);
}
public function removeInviteesNotInIdList(array $idList): self
{
$toRemove = [];
/** @var AgendaEventInvitee $invitee */
foreach ($this->invitees as $key => $invitee) {
if (!\in_array($invitee->getUser()->getId(), $idList, true)) {
$toRemove[] = $key;
}
}
foreach ($toRemove as $key) {
$this->invitees->remove($key);
}
return $this;
}
}

@ -1,65 +0,0 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'agenda_event_invitee')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap([
'invitee' => AgendaEventInvitee::class,
'subscriber' => AgendaEventSubscriber::class,
])]
class AgendaEventInvitee
{
use TimestampableTypedEntity;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private int $id;
#[ORM\ManyToOne(targetEntity: AgendaEventInvitation::class, inversedBy: 'invitees')]
#[ORM\JoinColumn(name: 'invitation_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
private ?AgendaEventInvitation $invitation;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?User $user;
public function getId(): int
{
return $this->id;
}
public function getInvitation(): ?AgendaEventInvitation
{
return $this->invitation;
}
public function setInvitation(?AgendaEventInvitation $invitation): self
{
$this->invitation = $invitation;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}

@ -1,12 +0,0 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class AgendaEventSubscriber extends AgendaEventInvitee {}

@ -1,32 +0,0 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class AgendaEventSubscription extends AgendaEventInvitation
{
public const SUBSCRIPTION_NO = 0;
public const SUBSCRIPTION_ALL = 1;
public const SUBSCRIPTION_CLASS = 2;
#[ORM\Column(name: 'max_attendees', type: 'integer', nullable: false, options: ['default' => 0])]
protected int $maxAttendees = 0;
public function getMaxAttendees(): int
{
return $this->maxAttendees;
}
public function setMaxAttendees(int $maxAttendees): self
{
$this->maxAttendees = $maxAttendees;
return $this;
}
}

@ -72,31 +72,36 @@ class Version20230904173400 extends AbstractMigrationChamilo
$em->persist($calendarEvent);
if ($collectiveInvitationsEnabled) {
$calendarEvent->setCollective((bool) $personalAgenda['collective']);
$hasSubscriptions = false;
$invitationsOrSubscriptionsInfo = [];
if ($subscriptionsEnabled) {
$subscriptionsInfo = $this->getSubscriptions((int) $personalAgenda['id']);
if (\count($subscriptionsInfo) > 0) {
$hasSubscriptions = true;
if (\count($subscriptionsInfo) > 0
&& $personalAgenda['subscription_visibility'] !== 0
) {
$invitationsOrSubscriptionsInfo = $subscriptionsInfo;
}
}
if ($hasSubscriptions) {
if ($invitationsOrSubscriptionsInfo) {
$calendarEvent
->setInvitationType(CCalendarEvent::TYPE_SUBSCRIPTION)
->setSubscriptionVisibility($personalAgenda['subscription_visibility'])
->setSubscriptionItemId($personalAgenda['subscription_item_id'])
->setMaxAttendees($invitationsOrSubscriptionsInfo[0]['max_attendees'])
;
} else {
$calendarEvent->setInvitationType(CCalendarEvent::TYPE_INVITATION);
$invitationsInfo = $this->getInvitations($subscriptionsEnabled, (int) $personalAgenda['id']);
if (\count($invitationsInfo) > 0) {
$calendarEvent
->setCollective((bool) $personalAgenda['collective'])
->setInvitationType(CCalendarEvent::TYPE_INVITATION)
;
$invitationsOrSubscriptionsInfo = $this->getInvitations($subscriptionsEnabled, (int) $personalAgenda['id']);
$invitationsOrSubscriptionsInfo = $invitationsInfo;
}
}
foreach ($invitationsOrSubscriptionsInfo as $invitationOrSubscriptionInfo) {
@ -197,7 +202,7 @@ class Version20230904173400 extends AbstractMigrationChamilo
private function getSubscriptions(int $personalAgendaId): array
{
$sql = "SELECT i.id, i.creator_id, i.created_at, i.updated_at
$sql = "SELECT i.id, i.creator_id, i.created_at, i.updated_at, i.max_attendees
FROM agenda_event_invitation i
INNER JOIN personal_agenda pa ON i.id = pa.agenda_event_invitation_id
WHERE pa.id = $personalAgendaId

@ -0,0 +1,34 @@
<?php
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
class Version20230904173401 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Calendar: Cleanup about invitations/subscriptions';
}
/**
* @inheritDoc
*/
public function up(Schema $schema): void
{
if ($schema->hasTable('agenda_event_invitation')) {
$this->addSql('ALTER TABLE personal_agenda DROP FOREIGN KEY FK_D8612460AF68C6B');
$this->addSql("DROP INDEX UNIQ_D8612460AF68C6B ON personal_agenda");
$this->addSql("ALTER TABLE personal_agenda DROP agenda_event_invitation_id, DROP collective, DROP subscription_visibility, DROP subscription_item_id");
$this->addSql("ALTER TABLE agenda_event_invitation DROP FOREIGN KEY FK_52A2D5E161220EA6");
$this->addSql("DROP TABLE agenda_event_invitation");
$this->addSql("ALTER TABLE agenda_event_invitee DROP FOREIGN KEY FK_4F5757FEA76ED395");
$this->addSql("DROP TABLE agenda_event_invitee");
}
}
}

@ -75,12 +75,6 @@ final class Version20240112131200 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE resource_tag CHANGE id id INT AUTO_INCREMENT NOT NULL;');
}
if ($schema->hasTable('agenda_event_invitation')) {
error_log('Perform the changes in the agenda_event_invitation table');
$this->addSql('ALTER TABLE personal_agenda DROP FOREIGN KEY FK_D8612460AF68C6B');
$this->addSql('ALTER TABLE agenda_event_invitation CHANGE id id INT AUTO_INCREMENT NOT NULL;');
}
if ($schema->hasTable('gradebook_comment')) {
error_log('Perform the changes in the gradebook_comment table');
$this->addSql('ALTER TABLE gradebook_comment CHANGE id id INT AUTO_INCREMENT NOT NULL;');

Loading…
Cancel
Save