Skip to content

Commit 7b56a61

Browse files
committed
Merge branch 'master' of github.com:chamilo/chamilo-lms
2 parents 41d03dd + cd7187e commit 7b56a61

File tree

4 files changed

+148
-47
lines changed

4 files changed

+148
-47
lines changed

src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,78 @@
1313

1414
class SettingsCurrentFixtures extends Fixture implements FixtureGroupInterface
1515
{
16+
/**
17+
* Settings candidates that must be locked at URL-level (access_url_locked = 1),
18+
* based on the task list.
19+
*/
20+
private const ACCESS_URL_LOCKED_YES = [
21+
'permissions_for_new_directories',
22+
'permissions_for_new_files',
23+
'course_creation_form_set_extra_fields_mandatory',
24+
'access_url_specific_files',
25+
'cron_remind_course_finished_activate',
26+
'cron_remind_course_expiration_frequency',
27+
'cron_remind_course_expiration_activate',
28+
'donotlistcampus',
29+
'server_type',
30+
'chamilo_database_version',
31+
'unoconv_binaries',
32+
'session_admin_access_to_all_users_on_all_urls',
33+
'split_users_upload_directory',
34+
'multiple_url_hide_disabled_settings',
35+
'login_is_email',
36+
'proxy_settings',
37+
'login_max_attempt_before_blocking_account',
38+
'permanently_remove_deleted_files',
39+
'allow_use_sub_language',
40+
];
41+
42+
/**
43+
* Settings candidates explicitly mentioned as "no" in the task list.
44+
* We set them to access_url_locked = 0, but only for this candidate list.
45+
*/
46+
private const ACCESS_URL_LOCKED_NO = [
47+
'drh_allow_access_to_all_students',
48+
'ticket_allow_category_edition',
49+
'max_anonymous_users',
50+
'enable_x_sendfile_headers',
51+
'mailer_dsn',
52+
'allow_send_message_to_all_platform_users',
53+
'message_max_upload_filesize',
54+
'use_custom_pages',
55+
'security_strict_transport',
56+
'security_content_policy',
57+
'security_content_policy_report_only',
58+
'security_public_key_pins',
59+
'security_public_key_pins_report_only',
60+
'security_x_frame_options',
61+
'security_xss_protection',
62+
'security_x_content_type_options',
63+
'security_referrer_policy',
64+
'security_session_cookie_samesite_none',
65+
'allow_session_admins_to_manage_all_sessions',
66+
'prevent_session_admins_to_manage_all_users',
67+
'session_admins_edit_courses_content',
68+
'assignment_base_course_teacher_access_to_all_session',
69+
];
70+
1671
public static function getGroups(): array
1772
{
1873
return ['settings-update'];
1974
}
2075

2176
public function load(ObjectManager $manager): void
2277
{
78+
$repo = $manager->getRepository(SettingsCurrent::class);
79+
2380
$existingSettings = $this->flattenConfigurationSettings(self::getExistingSettings());
2481
$newConfigurationSettings = $this->flattenConfigurationSettings(self::getNewConfigurationSettings());
2582

2683
$allConfigurations = array_merge($existingSettings, $newConfigurationSettings);
2784

85+
// Keep current behavior: update title/comment from configuration arrays.
2886
foreach ($allConfigurations as $settingData) {
29-
$setting = $manager->getRepository(SettingsCurrent::class)->findOneBy(['variable' => $settingData['name']]);
87+
$setting = $repo->findOneBy(['variable' => $settingData['name']]);
3088

3189
if (!$setting) {
3290
continue;
@@ -38,6 +96,34 @@ public function load(ObjectManager $manager): void
3896
$manager->persist($setting);
3997
}
4098

99+
// Reset all task candidates to access_url_locked = 0 (deterministic baseline).
100+
$candidates = array_values(array_unique(array_merge(
101+
self::ACCESS_URL_LOCKED_YES,
102+
self::ACCESS_URL_LOCKED_NO
103+
)));
104+
105+
/** @var SettingsCurrent[] $candidateSettings */
106+
$candidateSettings = $repo->findBy(['variable' => $candidates]);
107+
108+
// Index by variable to avoid extra queries.
109+
$byVariable = [];
110+
foreach ($candidateSettings as $setting) {
111+
$byVariable[$setting->getVariable()] = $setting;
112+
113+
$setting->setAccessUrlLocked(0);
114+
$manager->persist($setting);
115+
}
116+
117+
// Apply access_url_locked = 1 for the explicit YES list.
118+
foreach (self::ACCESS_URL_LOCKED_YES as $variable) {
119+
if (!isset($byVariable[$variable])) {
120+
continue;
121+
}
122+
123+
$byVariable[$variable]->setAccessUrlLocked(1);
124+
$manager->persist($byVariable[$variable]);
125+
}
126+
41127
$manager->flush();
42128
}
43129

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)