Skip to content

Commit 8c4573c

Browse files
Search: fix SearchEngineRef mapping and add resource_node FK migration
1 parent 777bb31 commit 8c4573c

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

src/CoreBundle/Entity/Course.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -241,28 +241,12 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
241241
#[ORM\OneToMany(mappedBy: 'course', targetEntity: TrackEHotspot::class, cascade: ['persist', 'remove'])]
242242
protected Collection $trackEHotspots;
243243

244-
/**
245-
* @var Collection<int, SearchEngineRef>
246-
*/
247-
#[ORM\OneToMany(mappedBy: 'course', targetEntity: SearchEngineRef::class, cascade: ['persist', 'remove'])]
248-
protected Collection $searchEngineRefs;
249-
250244
/**
251245
* @var Collection<int, Templates>
252246
*/
253247
#[ORM\OneToMany(mappedBy: 'course', targetEntity: Templates::class, cascade: ['persist', 'remove'])]
254248
protected Collection $templates;
255249

256-
/**
257-
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course").
258-
*/
259-
// protected $specificFieldValues;
260-
261-
/**
262-
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course").
263-
*/
264-
// protected $sharedSurveys;
265-
266250
#[ORM\Column(name: 'directory', type: 'string', length: 40, unique: false, nullable: true)]
267251
protected ?string $directory = null;
268252

@@ -410,7 +394,6 @@ public function __construct()
410394
$this->gradebookEvaluations = new ArrayCollection();
411395
$this->gradebookLinks = new ArrayCollection();
412396
$this->trackEHotspots = new ArrayCollection();
413-
$this->searchEngineRefs = new ArrayCollection();
414397
$this->templates = new ArrayCollection();
415398
$this->activateLegal = 0;
416399
$this->addTeachersToSessionsCourses = false;
@@ -420,8 +403,6 @@ public function __construct()
420403
$this->subscribe = true;
421404
$this->unsubscribe = false;
422405
$this->sticky = false;
423-
// $this->specificFieldValues = new ArrayCollection();
424-
// $this->sharedSurveys = new ArrayCollection();
425406
}
426407

427408
public function __toString(): string
@@ -1138,21 +1119,6 @@ public function setTrackEHotspots(Collection $trackEHotspots): self
11381119
return $this;
11391120
}
11401121

1141-
/**
1142-
* @return Collection<int, SearchEngineRef>
1143-
*/
1144-
public function getSearchEngineRefs(): Collection
1145-
{
1146-
return $this->searchEngineRefs;
1147-
}
1148-
1149-
public function setSearchEngineRefs(Collection $searchEngineRefs): self
1150-
{
1151-
$this->searchEngineRefs = $searchEngineRefs;
1152-
1153-
return $this;
1154-
}
1155-
11561122
public function getIntroduction(): ?string
11571123
{
11581124
return $this->introduction;

src/CoreBundle/Entity/SearchEngineRef.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,35 @@
88

99
use Doctrine\ORM\Mapping as ORM;
1010

11-
/**
12-
* SearchEngineRef.
13-
*/
1411
#[ORM\Table(name: 'search_engine_ref')]
1512
#[ORM\Entity]
1613
class SearchEngineRef
1714
{
18-
#[ORM\Column(name: 'resource_node_id', type: 'integer', nullable: true)]
19-
protected ?int $resourceNodeId = null;
15+
#[ORM\ManyToOne(targetEntity: ResourceNode::class)]
16+
#[ORM\JoinColumn(name: 'resource_node_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
17+
private ?ResourceNode $resourceNode = null;
2018

2119
#[ORM\Column(name: 'search_did', type: 'integer', nullable: false)]
22-
protected int $searchDid;
20+
private int $searchDid;
2321

24-
#[ORM\Column(name: 'id', type: 'integer')]
2522
#[ORM\Id]
23+
#[ORM\Column(name: 'id', type: 'integer')]
2624
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
27-
protected ?int $id = null;
25+
private ?int $id = null;
2826

2927
public function getId(): ?int
3028
{
3129
return $this->id;
3230
}
3331

34-
public function getResourceNodeId(): ?int
32+
public function getResourceNode(): ?ResourceNode
3533
{
36-
return $this->resourceNodeId;
34+
return $this->resourceNode;
3735
}
3836

39-
public function setResourceNodeId(?int $resourceNodeId): self
37+
public function setResourceNode(?ResourceNode $resourceNode): self
4038
{
41-
$this->resourceNodeId = $resourceNodeId;
39+
$this->resourceNode = $resourceNode;
4240

4341
return $this;
4442
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8+
9+
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10+
use Doctrine\DBAL\Schema\Schema;
11+
12+
final class Version20251216095100 extends AbstractMigrationChamilo
13+
{
14+
public function getDescription(): string
15+
{
16+
return 'Add FK + index for search_engine_ref.resource_node_id (resource_node.id).';
17+
}
18+
19+
public function up(Schema $schema): void
20+
{
21+
// Ensure the FK can be created (remove orphan references).
22+
$this->addSql("
23+
UPDATE search_engine_ref ser
24+
SET resource_node_id = NULL
25+
WHERE ser.resource_node_id IS NOT NULL
26+
AND NOT EXISTS (
27+
SELECT 1
28+
FROM resource_node rn
29+
WHERE rn.id = ser.resource_node_id
30+
)
31+
");
32+
33+
// Add index for faster joins and stable naming.
34+
$this->addSql('CREATE INDEX IDX_473F03781BAD783F ON search_engine_ref (resource_node_id)');
35+
36+
// Add FK constraint.
37+
$this->addSql("
38+
ALTER TABLE search_engine_ref
39+
ADD CONSTRAINT FK_473F03781BAD783F
40+
FOREIGN KEY (resource_node_id)
41+
REFERENCES resource_node (id)
42+
ON DELETE CASCADE
43+
");
44+
}
45+
46+
public function down(Schema $schema): void
47+
{
48+
$this->addSql('ALTER TABLE search_engine_ref DROP FOREIGN KEY FK_473F03781BAD783F');
49+
$this->addSql('DROP INDEX IDX_473F03781BAD783F ON search_engine_ref');
50+
}
51+
}

0 commit comments

Comments
 (0)