Skip to content

Commit b98b747

Browse files
Merge pull request #8581 from christianbeeznest/ricky/23461-db-changes
Migration: Add legacy migration support structures
2 parents 5d97325 + 22d0bba commit b98b747

3 files changed

Lines changed: 127 additions & 0 deletions

File tree

public/plugin/GradingElectronic/src/GradingElectronicPlugin.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static function create()
4545
public function install()
4646
{
4747
$this->setUpExtraFields();
48+
$this->setUpDatabaseTables();
4849
}
4950

5051
/**
@@ -801,6 +802,79 @@ private function setDownExtraFields()
801802
}
802803

803804

805+
/**
806+
* Create plugin-specific migration support tables.
807+
*
808+
* These tables keep custom grading/tracking structures outside the core schema.
809+
* They intentionally use generic plugin table names instead of the legacy table names.
810+
*/
811+
private function setUpDatabaseTables(): void
812+
{
813+
Database::query(<<<'SQL'
814+
CREATE TABLE IF NOT EXISTS plugin_grading_electronic_lp_completion (
815+
id BIGINT AUTO_INCREMENT NOT NULL,
816+
course_id INT NOT NULL,
817+
user_id BIGINT NOT NULL,
818+
lp_id INT NOT NULL,
819+
completion_status VARCHAR(250) NOT NULL,
820+
INDEX idx_pge_lp_completion_course_user_lp (course_id, user_id, lp_id),
821+
INDEX idx_pge_lp_completion_lp (lp_id),
822+
PRIMARY KEY(id)
823+
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC
824+
SQL);
825+
826+
Database::query(<<<'SQL'
827+
CREATE TABLE IF NOT EXISTS plugin_grading_electronic_lp_schedule (
828+
id INT AUTO_INCREMENT NOT NULL,
829+
course_id BIGINT NOT NULL,
830+
lp_id BIGINT NOT NULL,
831+
title VARCHAR(100) DEFAULT NULL,
832+
week_day VARCHAR(100) DEFAULT NULL,
833+
INDEX idx_pge_lp_schedule_course_lp (course_id, lp_id),
834+
PRIMARY KEY(id)
835+
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC
836+
SQL);
837+
838+
Database::query(<<<'SQL'
839+
CREATE TABLE IF NOT EXISTS plugin_grading_electronic_forum_thread_comment (
840+
id BIGINT AUTO_INCREMENT NOT NULL,
841+
sender_user_id BIGINT NOT NULL,
842+
receiver_user_id BIGINT NOT NULL,
843+
forum_id BIGINT NOT NULL,
844+
thread_id BIGINT NOT NULL,
845+
comment BLOB NOT NULL,
846+
INDEX idx_pge_forum_thread_comment_forum_thread (forum_id, thread_id),
847+
INDEX idx_pge_forum_thread_comment_receiver (receiver_user_id),
848+
INDEX idx_pge_forum_thread_comment_sender (sender_user_id),
849+
PRIMARY KEY(id)
850+
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC
851+
SQL);
852+
853+
Database::query(<<<'SQL'
854+
CREATE TABLE IF NOT EXISTS plugin_grading_electronic_user_session_tracking (
855+
id BIGINT AUTO_INCREMENT NOT NULL,
856+
user_id BIGINT NOT NULL,
857+
session_time VARCHAR(200) NOT NULL,
858+
is_active INT NOT NULL DEFAULT 1,
859+
INDEX idx_pge_user_session_tracking_user_active (user_id, is_active),
860+
PRIMARY KEY(id)
861+
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC
862+
SQL);
863+
864+
Database::query(<<<'SQL'
865+
CREATE TABLE IF NOT EXISTS plugin_grading_electronic_unregistration_log (
866+
id BIGINT AUTO_INCREMENT NOT NULL,
867+
user_id INT NOT NULL,
868+
course_id INT NOT NULL,
869+
deleted_at_legacy VARCHAR(500) NOT NULL,
870+
last_access_legacy VARCHAR(500) NOT NULL,
871+
INDEX idx_pge_unregistration_user_course (user_id, course_id),
872+
PRIMARY KEY(id)
873+
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC
874+
SQL);
875+
}
876+
877+
804878
private function getCurrentPluginRegion(): string
805879
{
806880
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\CoreBundle\Migrations\Schema\V210;
8+
9+
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10+
use Doctrine\DBAL\Schema\Schema;
11+
12+
final class Version20260611183000 extends AbstractMigrationChamilo
13+
{
14+
public function getDescription(): string
15+
{
16+
return 'Add learning path completion date support.';
17+
}
18+
19+
public function up(Schema $schema): void
20+
{
21+
if (!$schema->hasTable('c_lp_view')) {
22+
return;
23+
}
24+
25+
$table = $schema->getTable('c_lp_view');
26+
27+
if (!$table->hasColumn('compdate')) {
28+
$this->addSql('ALTER TABLE c_lp_view ADD compdate DATE DEFAULT NULL');
29+
}
30+
}
31+
32+
public function down(Schema $schema): void
33+
{
34+
// Intentionally left empty.
35+
// The completion date can be part of migrated tracking/legal evidence.
36+
}
37+
}

src/CourseBundle/Entity/CLpView.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Chamilo\CoreBundle\Entity\Course;
1010
use Chamilo\CoreBundle\Entity\Session;
1111
use Chamilo\CoreBundle\Entity\User;
12+
use DateTimeInterface;
1213
use Doctrine\ORM\Mapping as ORM;
1314

1415
/**
@@ -51,6 +52,9 @@ class CLpView
5152
#[ORM\Column(name: 'progress', type: 'integer', nullable: true)]
5253
protected ?int $progress = null;
5354

55+
#[ORM\Column(name: 'compdate', type: 'date', nullable: true)]
56+
protected ?DateTimeInterface $completionDate = null;
57+
5458
public function getIid(): ?int
5559
{
5660
return $this->iid;
@@ -107,6 +111,18 @@ public function getProgress()
107111
return $this->progress;
108112
}
109113

114+
public function getCompletionDate(): ?DateTimeInterface
115+
{
116+
return $this->completionDate;
117+
}
118+
119+
public function setCompletionDate(?DateTimeInterface $completionDate): self
120+
{
121+
$this->completionDate = $completionDate;
122+
123+
return $this;
124+
}
125+
110126
public function getLp(): CLp
111127
{
112128
return $this->lp;

0 commit comments

Comments
 (0)