Add session unique keys

pull/3924/head
Julio Montoya 3 years ago
parent 24d79e70a2
commit 5e107954f7
  1. 21
      src/CoreBundle/Entity/SessionRelCourse.php
  2. 12
      src/CoreBundle/Entity/SessionRelCourseRelUser.php
  3. 10
      src/CoreBundle/Entity/SessionRelUser.php
  4. 15
      src/CoreBundle/Migrations/Schema/V200/Version20190210182615.php
  5. 7
      src/CoreBundle/Repository/SessionRepository.php

@ -9,19 +9,23 @@ namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Course subscriptions to a session.
*
* @ORM\Table(name="session_rel_course", indexes={
* @ORM\Table(name="session_rel_course",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="course_session_unique",
* columns={"session_id", "c_id"})
* },
* indexes={
* @ORM\Index(name="idx_session_rel_course_course_id", columns={"c_id"})
* })
* }
* )
* @ORM\Entity
*/
#[ApiResource(
attributes: [
'security' => "is_granted('ROLE_ADMIN')",
],
collectionOperations: [
'get' => [
'security' => "is_granted('ROLE_ADMIN')",
@ -38,12 +42,15 @@ use Symfony\Component\Serializer\Annotation\Groups;
'security' => "is_granted('ROLE_ADMIN')",
],
],
normalizationContext: [
'groups' => ['session_rel_course:read'],
attributes: [
'security' => "is_granted('ROLE_ADMIN')",
],
denormalizationContext: [
'groups' => ['session_rel_course:write'],
],
normalizationContext: [
'groups' => ['session_rel_course:read'],
],
)]
class SessionRelCourse
{

@ -22,6 +22,10 @@ use Symfony\Component\Validator\Constraints as Assert;
* )
* @ORM\Table(
* name="session_rel_course_rel_user",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="course_session_unique",
* columns={"session_id", "c_id", "user_id", "status"})
* },
* indexes={
* @ORM\Index(name="idx_session_rel_course_rel_user_id_user", columns={"user_id"}),
* @ORM\Index(name="idx_session_rel_course_rel_user_course_id", columns={"c_id"})
@ -73,14 +77,14 @@ class SessionRelCourseRelUser
protected Course $course;
/**
* @ORM\Column(name="visibility", type="integer")
* @ORM\Column(name="status", type="integer")
*/
protected int $visibility;
protected int $status;
/**
* @ORM\Column(name="status", type="integer")
* @ORM\Column(name="visibility", type="integer")
*/
protected int $status;
protected int $visibility;
/**
* @ORM\Column(name="legal_agreement", type="integer", nullable=false, unique=false)

@ -21,6 +21,10 @@ use Symfony\Component\Serializer\Annotation\Groups;
*
* @ORM\Table(
* name="session_rel_user",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="session_user_unique",
* columns={"session_id", "user_id", "relation_type"})
* },
* indexes={
* @ORM\Index(name="idx_session_rel_user_id_user_moved", columns={"user_id", "moved_to"})
* }
@ -28,9 +32,6 @@ use Symfony\Component\Serializer\Annotation\Groups;
* @ORM\Entity
*/
#[ApiResource(
attributes: [
'security' => "is_granted('ROLE_USER')",
],
collectionOperations: [
'get' => [
'security' => "is_granted('ROLE_ADMIN')",
@ -44,6 +45,9 @@ use Symfony\Component\Serializer\Annotation\Groups;
'security' => "is_granted('ROLE_ADMIN') or object.user == user",
],
],
attributes: [
'security' => "is_granted('ROLE_USER')",
],
normalizationContext: [
'groups' => ['session_rel_user:read', 'user:read'],
],

@ -54,6 +54,21 @@ class Version20190210182615 extends AbstractMigrationChamilo
} else {
$this->addSql('ALTER TABLE session_rel_course_rel_user ADD CONSTRAINT FK_720167E91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE');
}
if (!$table->hasIndex('course_session_unique')) {
$this->addSql(' CREATE UNIQUE INDEX course_session_unique ON session_rel_course_rel_user (session_id, c_id, user_id, status);');
}
$table = $schema->getTable('session_rel_course');
if (!$table->hasIndex('UNIQ_12D110D391D79BD3')) {
$this->addSql('CREATE UNIQUE INDEX course_session_unique ON session_rel_course (session_id, c_id)');
}
$table = $schema->getTable('session_rel_user');
if (!$table->hasIndex('session_user_unique')) {
$this->addSql('CREATE UNIQUE INDEX session_user_unique ON session_rel_user (session_id, user_id, relation_type);');
}
}
public function down(Schema $schema): void

@ -29,7 +29,12 @@ class SessionRepository extends ServiceEntityRepository
parent::__construct($registry, Session::class);
}
public function create(Session $session): void
public function create(): ?Session
{
return new Session();
}
public function update(Session $session): void
{
$this->getEntityManager()->persist($session);
$this->getEntityManager()->flush();

Loading…
Cancel
Save