Install: add missing changes for course dependent tables

pull/4855/head
Angel Fernando Quiroz Campos 1 year ago
parent 281b384a14
commit 3f023110ea
  1. 8
      src/CoreBundle/Entity/AccessUrlRelCourse.php
  2. 3
      src/CoreBundle/Entity/Course.php
  3. 2
      src/CoreBundle/Entity/CourseRelUser.php
  4. 50
      src/CoreBundle/Migrations/Schema/V200/Version20230824115700.php
  5. 2
      src/CourseBundle/Entity/CTool.php

@ -25,11 +25,11 @@ class AccessUrlRelCourse implements EntityAccessUrlInterface, Stringable
protected ?int $id = null;
#[ORM\ManyToOne(targetEntity: Course::class, cascade: ['persist'], inversedBy: 'urls')]
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id')]
protected Course $course;
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', nullable: false, onDelete: "CASCADE")]
protected ?Course $course;
#[ORM\ManyToOne(targetEntity: AccessUrl::class, cascade: ['persist'], inversedBy: 'courses')]
#[ORM\JoinColumn(name: 'access_url_id', referencedColumnName: 'id')]
#[ORM\JoinColumn(name: 'access_url_id', referencedColumnName: 'id', nullable: false, onDelete: "CASCADE")]
protected ?AccessUrl $url;
public function __toString(): string
@ -54,7 +54,7 @@ class AccessUrlRelCourse implements EntityAccessUrlInterface, Stringable
return $this;
}
public function getCourse(): Course
public function getCourse(): ?Course
{
return $this->course;
}

@ -164,7 +164,8 @@ class Course extends AbstractResource implements
cascade: [
'persist',
'remove',
]
],
orphanRemoval: true
)]
protected Collection $tools;

@ -68,7 +68,7 @@ class CourseRelUser implements Stringable
#[Groups(['course_rel_user:read'])]
#[ORM\ManyToOne(targetEntity: Course::class, inversedBy: 'users', cascade: ['persist'])]
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id')]
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', onDelete: "CASCADE")]
protected Course $course;
#[Groups(['course:read', 'user:read'])]

@ -0,0 +1,50 @@
<?php
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
class Version20230824115700 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Changes in Course dependent tables';
}
/**
* @inheritDoc
*/
public function up(Schema $schema): void
{
$accessUrlRelCourse = $schema->getTable('access_url_rel_course');
if ($accessUrlRelCourse->hasForeignKey('FK_8E97FC0891D79BD3')) {
$this->addSql('ALTER TABLE access_url_rel_course DROP FOREIGN KEY FK_8E97FC0891D79BD3');
}
if ($accessUrlRelCourse->hasForeignKey('FK_8E97FC0873444FD5')) {
$this->addSql('ALTER TABLE access_url_rel_course DROP FOREIGN KEY FK_8E97FC0873444FD5');
}
$this->addSql('ALTER TABLE access_url_rel_course CHANGE c_id c_id INT NOT NULL, CHANGE access_url_id access_url_id INT NOT NULL');
$this->addSql('ALTER TABLE access_url_rel_course ADD CONSTRAINT FK_8E97FC0891D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE access_url_rel_course ADD CONSTRAINT FK_8E97FC0873444FD5 FOREIGN KEY (access_url_id) REFERENCES access_url (id) ON DELETE CASCADE');
$courseRelUser = $schema->getTable('course_rel_user');
if ($courseRelUser->hasForeignKey('FK_92CFD9FE91D79BD3')) {
$this->addSql('ALTER TABLE course_rel_user DROP FOREIGN KEY FK_92CFD9FE91D79BD3');
}
$this->addSql('ALTER TABLE course_rel_user ADD CONSTRAINT FK_92CFD9FE91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE');
$cTool = $schema->getTable('c_tool');
if ($cTool->hasForeignKey('FK_8456658091D79BD3')) {
$this->addSql('ALTER TABLE c_tool DROP FOREIGN KEY FK_8456658091D79BD3');
}
$this->addSql('ALTER TABLE c_tool ADD CONSTRAINT FK_8456658091D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE');
}
}

@ -50,7 +50,7 @@ class CTool extends AbstractResource implements
protected ?bool $visibility = null;
#[ORM\ManyToOne(targetEntity: Course::class, inversedBy: 'tools')]
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', nullable: false)]
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', nullable: false, onDelete: "CASCADE")]
#[Gedmo\SortableGroup]
protected Course $course;

Loading…
Cancel
Save