Shortcut: fix delete shortcut

pull/4037/head
Julio 3 years ago
parent f7f47fa4f2
commit 3a1927cf8e
  1. 2
      src/CoreBundle/Migrations/Schema/V200/Version20170525122900.php
  2. 17
      src/CourseBundle/Entity/CShortcut.php
  3. 8
      tests/CourseBundle/Repository/CShortcutRepositoryTest.php

@ -168,7 +168,7 @@ class Version20170525122900 extends AbstractMigrationChamilo
'CREATE TABLE IF NOT EXISTS c_shortcut (id INT AUTO_INCREMENT NOT NULL, shortcut_node_id BIGINT DEFAULT NULL, resource_node_id BIGINT DEFAULT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_3F6BB957937100BE (shortcut_node_id), UNIQUE INDEX UNIQ_3F6BB9571BAD783F (resource_node_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;'
);
$this->addSql(
'ALTER TABLE c_shortcut ADD CONSTRAINT FK_3F6BB957937100BE FOREIGN KEY (shortcut_node_id) REFERENCES resource_node (id);'
'ALTER TABLE c_shortcut ADD CONSTRAINT FK_3F6BB957937100BE FOREIGN KEY (shortcut_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'
);
$this->addSql(
'ALTER TABLE c_shortcut ADD CONSTRAINT FK_3F6BB9571BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'

@ -27,32 +27,25 @@ class CShortcut extends AbstractResource implements ResourceInterface
protected int $id;
/**
* @Groups({"cshortcut:read"})
*
* @ORM\Column(name="name", type="string", length=255, nullable=false)
*/
#[Assert\NotBlank]
#[Groups(['cshortcut:read'])]
protected string $name;
/**
* @ORM\OneToOne(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", inversedBy="shortCut")
* @ORM\JoinColumn(name="shortcut_node_id", referencedColumnName="id" )
* @ORM\JoinColumn(name="shortcut_node_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected ResourceNode $shortCutNode;
/**
* @Groups({"cshortcut:read"})
*/
#[Groups(['cshortcut:read'])]
protected string $url;
/**
* @Groups({"cshortcut:read"})
*/
#[Groups(['cshortcut:read'])]
protected string $tool;
/**
* @Groups({"cshortcut:read"})
*/
#[Groups(['cshortcut:read'])]
protected string $type;
public function __toString(): string

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\Tests\CourseBundle\Repository;
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
use Chamilo\CourseBundle\Entity\CForum;
use Chamilo\CourseBundle\Entity\CShortcut;
use Chamilo\CourseBundle\Repository\CForumRepository;
@ -22,6 +23,7 @@ class CShortcutRepositoryTest extends AbstractApiTest
$em = $this->getEntityManager();
$shortcutRepo = self::getContainer()->get(CShortcutRepository::class);
$forumRepo = self::getContainer()->get(CForumRepository::class);
$courseRepo = self::getContainer()->get(CourseRepository::class);
$course = $this->createCourse('new');
$teacher = $this->createUser('teacher');
@ -62,5 +64,11 @@ class CShortcutRepositoryTest extends AbstractApiTest
$shortcutRepo->addShortCut($resource, $teacher, $course);
$this->assertSame(1, $shortcutRepo->count([]));
$course = $this->getCourse($course->getId());
$courseRepo->delete($course);
$this->assertSame(0, $shortcutRepo->count([]));
$this->assertSame(0, $courseRepo->count([]));
}
}

Loading…
Cancel
Save