diff --git a/src/CoreBundle/Entity/AccessUrlRelUser.php b/src/CoreBundle/Entity/AccessUrlRelUser.php index 61bd0ae006..fbb77da84f 100644 --- a/src/CoreBundle/Entity/AccessUrlRelUser.php +++ b/src/CoreBundle/Entity/AccessUrlRelUser.php @@ -37,13 +37,13 @@ class AccessUrlRelUser * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="portals") * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE") */ - protected $user; + protected User $user; /** * @ORM\ManyToOne(targetEntity="AccessUrl", inversedBy="user", cascade={"persist"}) * @ORM\JoinColumn(name="access_url_id", referencedColumnName="id") */ - protected $url; + protected AccessUrl $url; /** * @return string diff --git a/src/CoreBundle/Entity/GradebookCategory.php b/src/CoreBundle/Entity/GradebookCategory.php index 2185b92f95..0fecafd608 100644 --- a/src/CoreBundle/Entity/GradebookCategory.php +++ b/src/CoreBundle/Entity/GradebookCategory.php @@ -468,11 +468,6 @@ class GradebookCategory return $this->parent; } - /** - * @param GradebookCategory|null $parent - * - * @return GradebookCategory - */ public function setParent(?GradebookCategory $parent): self { $this->parent = $parent; diff --git a/src/CoreBundle/Entity/GradebookResult.php b/src/CoreBundle/Entity/GradebookResult.php index e76ebafc39..eb1f00ac35 100644 --- a/src/CoreBundle/Entity/GradebookResult.php +++ b/src/CoreBundle/Entity/GradebookResult.php @@ -37,6 +37,12 @@ class GradebookResult */ protected GradebookEvaluation $evaluation; + /** + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="gradeBookResults") + * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE") + */ + protected User $user; + /** * @var float * @@ -52,12 +58,6 @@ class GradebookResult */ protected $createdAt; - /** - * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="gradeBookResults") - * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE") - */ - protected User $user; - /** * Set evaluationId. * diff --git a/src/CoreBundle/Migrations/AbstractMigrationChamilo.php b/src/CoreBundle/Migrations/AbstractMigrationChamilo.php index 65f9afefd4..8f880712da 100644 --- a/src/CoreBundle/Migrations/AbstractMigrationChamilo.php +++ b/src/CoreBundle/Migrations/AbstractMigrationChamilo.php @@ -215,8 +215,15 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con } } - public function fixItemProperty($tool, $repo, $course, $admin, ResourceInterface $resource, $parent) - { + public function fixItemProperty( + $tool, + $repo, + $course, + $admin, + ResourceInterface $resource, + $parent, + array $items = [] + ) { $container = $this->getContainer(); $doctrine = $container->get('doctrine'); $em = $doctrine->getManager(); @@ -226,12 +233,14 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con $courseId = $course->getId(); $id = $resource->getResourceIdentifier(); - $sql = "SELECT * FROM c_item_property - WHERE tool = '$tool' AND c_id = $courseId AND ref = $id"; - $result = $connection->executeQuery($sql); - $items = $result->fetchAllAssociative(); + if (empty($items)) { + $sql = "SELECT * FROM c_item_property + WHERE tool = '$tool' AND c_id = $courseId AND ref = $id"; + $result = $connection->executeQuery($sql); + $items = $result->fetchAllAssociative(); + } - // For some reason this document doesnt have a c_item_property value. + // For some reason the resource doesnt have a c_item_property value. if (empty($items)) { return false; } @@ -250,9 +259,9 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con $sessionList = []; foreach ($items as $item) { $visibility = $item['visibility']; - $sessionId = $item['session_id']; $userId = $item['insert_user_id']; - $groupId = $item['to_group_id']; + $sessionId = $item['session_id'] ?? 0; + $groupId = $item['to_group_id'] ?? 0; $newVisibility = ResourceLink::VISIBILITY_PENDING; switch ($visibility) { diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20.php b/src/CoreBundle/Migrations/Schema/V200/Version20.php index 7f49b5b6b8..ec73df88e9 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20.php @@ -112,6 +112,11 @@ class Version20 extends AbstractMigrationChamilo if ($table->hasColumn('course')) { $this->addSql('ALTER TABLE personal_agenda DROP course'); } + + if ($table->hasIndex('category_code')) { + $this->addSql('DROP INDEX category_code ON course'); + } + if (false === $table->hasForeignKey('FK_D86124608D93D649')) { $this->addSql('ALTER TABLE personal_agenda ADD CONSTRAINT FK_D86124608D93D649 FOREIGN KEY (user) REFERENCES user (id) ON DELETE CASCADE'); } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20170625122900.php b/src/CoreBundle/Migrations/Schema/V200/Version20170625122900.php index 97804f5fdc..cc588d0e2b 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20170625122900.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20170625122900.php @@ -43,6 +43,10 @@ class Version20170625122900 extends AbstractMigrationChamilo $this->addSql('CREATE INDEX idx_cdoc_type ON c_document (filetype)'); } + if (false === $table->hasIndex('course')) { + $this->addSql('DROP INDEX course ON c_document'); + } + //$this->addSql('ALTER TABLE c_document CHANGE path path VARCHAR(255) DEFAULT NULL;'); $table = $schema->getTable('c_announcement'); if (false === $table->hasColumn('resource_node_id')) { diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20170625143000.php b/src/CoreBundle/Migrations/Schema/V200/Version20170625143000.php index 6a7553a1e8..6a7e4fe626 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20170625143000.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20170625143000.php @@ -88,9 +88,10 @@ class Version20170625143000 extends AbstractMigrationChamilo $table = $schema->getTable('c_thematic_plan'); $this->addSql('ALTER TABLE c_thematic_plan CHANGE thematic_id thematic_id INT DEFAULT NULL'); - if (false === $table->hasIndex('course')) { + if ($table->hasIndex('course')) { $this->addSql('DROP INDEX course ON c_thematic_plan'); } + if ($table->hasColumn('c_id')) { //$this->addSql('ALTER TABLE c_thematic_plan DROP c_id;'); } @@ -153,6 +154,15 @@ class Version20170625143000 extends AbstractMigrationChamilo } $table = $schema->getTable('c_glossary'); + + if ($table->hasIndex('course')) { + $this->addSql('DROP INDEX course ON c_glossary'); + } + + if ($table->hasIndex('session_id')) { + $this->addSql('DROP INDEX session_id ON c_glossary'); + } + if (false === $table->hasColumn('resource_node_id')) { $this->addSql('ALTER TABLE c_glossary ADD resource_node_id INT DEFAULT NULL'); $this->addSql( @@ -224,7 +234,21 @@ class Version20170625143000 extends AbstractMigrationChamilo $this->addSql('CREATE UNIQUE INDEX UNIQ_A06225811BAD783F ON c_calendar_event (resource_node_id)'); } + if ($table->hasIndex('course')) { + $this->addSql('DROP INDEX course ON c_calendar_event'); + } + + if ($table->hasIndex('session_id')) { + $this->addSql('DROP INDEX session_id ON c_calendar_event'); + } + + $table = $schema->getTable('c_calendar_event_attachment'); + + if ($table->hasIndex('course')) { + $this->addSql('DROP INDEX course ON c_calendar_event_attachment'); + } + if (false === $table->hasColumn('resource_node_id')) { $this->addSql('ALTER TABLE c_calendar_event_attachment ADD resource_node_id INT DEFAULT NULL'); $this->addSql( @@ -250,12 +274,20 @@ class Version20170625143000 extends AbstractMigrationChamilo $this->addSql('CREATE INDEX IDX_86FD1CA87300D633 ON c_calendar_event_repeat (cal_id)'); } - $this->addSql('ALTER TABLE c_calendar_event_repeat_not CHANGE cal_id cal_id INT DEFAULT NULL'); + $table = $schema->getTable('c_calendar_event_repeat_not'); + + if ($table->hasIndex('course')) { + $this->addSql('DROP INDEX course ON c_calendar_event_repeat_not;'); + } + if (false === $table->hasForeignKey('FK_7D4436947300D633')) { $this->addSql( 'ALTER TABLE c_calendar_event_repeat_not ADD CONSTRAINT FK_7D4436947300D633 FOREIGN KEY (cal_id) REFERENCES c_calendar_event (iid)' ); } + + $this->addSql('ALTER TABLE c_calendar_event_repeat_not CHANGE cal_id cal_id INT DEFAULT NULL'); + if (false === $table->hasIndex('IDX_7D4436947300D633')) { $this->addSql('CREATE INDEX IDX_7D4436947300D633 ON c_calendar_event_repeat_not (cal_id)'); } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20170625153000.php b/src/CoreBundle/Migrations/Schema/V200/Version20170625153000.php index ea3c9564c7..92967b56a9 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20170625153000.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20170625153000.php @@ -51,7 +51,20 @@ class Version20170625153000 extends AbstractMigrationChamilo $this->addSql('CREATE UNIQUE INDEX UNIQ_47A9C991BAD783F ON c_forum_forum (resource_node_id)'); } - $this->addSql('ALTER TABLE c_forum_forum DROP FOREIGN KEY FK_47A9C9921BF9426'); + if ($table->hasIndex('FK_47A9C9968DFD1EF')) { + $this->addSql('ALTER TABLE c_forum_forum DROP INDEX FK_47A9C9968DFD1EF'); + } + + $this->addSql('ALTER TABLE c_forum_forum CHANGE lp_id lp_id INT DEFAULT NULL'); + $this->addSql('UPDATE c_forum_forum SET lp_id = NULL WHERE lp_id = 0'); + if (false === $table->hasIndex('UNIQ_47A9C9968DFD1EF')) { + $this->addSql('ALTER TABLE c_forum_forum ADD UNIQUE INDEX UNIQ_47A9C9968DFD1EF (lp_id)'); + } + + if ($table->hasForeignKey('FK_47A9C9921BF9426')) { + $this->addSql('ALTER TABLE c_forum_forum DROP FOREIGN KEY FK_47A9C9921BF9426'); + } + $table = $schema->getTable('c_forum_thread'); if ($table->hasForeignKey('FK_5DA7884C29CCBAD0')) { @@ -97,6 +110,10 @@ class Version20170625153000 extends AbstractMigrationChamilo $this->addSql('CREATE UNIQUE INDEX UNIQ_EC3CD8091BAD783F ON c_course_description (resource_node_id)'); } + if ($table->hasIndex('session_id')) { + $this->addSql('DROP INDEX session_id ON c_course_description'); + } + $table = $schema->getTable('c_notebook'); if ($table->hasIndex('course')) { diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20170628122900.php b/src/CoreBundle/Migrations/Schema/V200/Version20170628122900.php index f0191e493f..fa2d33e6bd 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20170628122900.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20170628122900.php @@ -19,10 +19,16 @@ class Version20170628122900 extends AbstractMigrationChamilo if (false === $table->hasColumn('id')) { $this->addSql('ALTER TABLE access_url_rel_user MODIFY COLUMN access_url_id INT NOT NULL'); $this->addSql('ALTER TABLE access_url_rel_user MODIFY COLUMN user_id INT NOT NULL'); - $this->addSql('ALTER TABLE access_url_rel_user DROP PRIMARY KEY'); + if ($table->hasPrimaryKey()) { + $this->addSql('ALTER TABLE access_url_rel_user DROP PRIMARY KEY'); + } + $this->addSql( - 'ALTER TABLE access_url_rel_user ADD id INT AUTO_INCREMENT NOT NULL, CHANGE access_url_id access_url_id INT DEFAULT NULL, CHANGE user_id user_id INT DEFAULT NULL, ADD PRIMARY KEY (id);' + 'ALTER TABLE access_url_rel_user ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)' ); + + $this->addSql('ALTER TABLE access_url_rel_user CHANGE access_url_id access_url_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE access_url_rel_user CHANGE user_id user_id INT DEFAULT NULL'); } if (false === $table->hasForeignKey('FK_85574263A76ED395')) { diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20180319145700.php b/src/CoreBundle/Migrations/Schema/V200/Version20180319145700.php index d0c511e671..282e684ca8 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20180319145700.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20180319145700.php @@ -53,8 +53,12 @@ class Version20180319145700 extends AbstractMigrationChamilo ->addColumn('is_required', Types::BOOLEAN) ->setDefault(false); } - if (false === $table->hasIndex('idx_survey_q_qid')) { + /*if (false === $table->hasIndex('idx_survey_q_qid')) { $this->addSql('CREATE INDEX idx_survey_q_qid ON c_survey_question (question_id)'); + }*/ + + if ($table->hasIndex('idx_survey_q_qid')) { + $this->addSql('DROP INDEX idx_survey_q_qid ON c_survey_question;'); } if (false === $table->hasColumn('parent_id')) { diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20181025064351.php b/src/CoreBundle/Migrations/Schema/V200/Version20181025064351.php index f75918da56..f500c7edf6 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20181025064351.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20181025064351.php @@ -193,8 +193,9 @@ class Version20181025064351 extends AbstractMigrationChamilo } $table = $schema->getTable('gradebook_result'); - if ($table->hasIndex('idx_gb_uid_eid')) { - $this->addSql(''); + + if (false === $table->hasIndex('idx_gb_uid_eid')) { + $this->addSql('CREATE INDEX idx_gb_uid_eid ON gradebook_result (user_id, evaluation_id);'); } if (false === $table->hasIndex('IDX_B88AEB67456C5646')) { @@ -292,6 +293,13 @@ class Version20181025064351 extends AbstractMigrationChamilo ); } + if (false === $table->hasForeignKey('FK_640C644912469DE2')) { + $this->addSql( + 'ALTER TABLE gradebook_score_log ADD CONSTRAINT FK_640C644912469DE2 FOREIGN KEY (category_id) REFERENCES gradebook_category (id)' + ); + } + + if (false === $table->hasIndex('IDX_640C644912469DE2')) { $this->addSql('CREATE INDEX IDX_640C644912469DE2 ON gradebook_score_log (category_id);'); } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20190110182615.php b/src/CoreBundle/Migrations/Schema/V200/Version20190110182615.php index 18ebe5926a..98a4a9405f 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20190110182615.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20190110182615.php @@ -42,6 +42,14 @@ class Version20190110182615 extends AbstractMigrationChamilo $this->addSql('CREATE INDEX IDX_F67ABBEB5DA1941 ON c_lp (asset_id);'); } + if ($table->hasIndex('session')) { + $this->addSql('DROP INDEX session ON c_lp'); + } + + if ($table->hasIndex('course')) { + $this->addSql('DROP INDEX course ON c_lp'); + } + if (false === $table->hasColumn('accumulate_work_time')) { $this->addSql('ALTER TABLE c_lp ADD accumulate_work_time INT DEFAULT 0 NOT NULL'); } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php b/src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php index 8af96468b1..bb9c60fbc4 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php @@ -48,7 +48,6 @@ final class Version20201215072918 extends AbstractMigrationChamilo $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); /** @var Course $course */ foreach ($q->toIterable() as $course) { - $counter = 1; $courseId = $course->getId(); $course = $courseRepo->find($courseId); @@ -83,6 +82,7 @@ final class Version20201215072918 extends AbstractMigrationChamilo $em->flush(); continue; } + // Assign parent. $parent = null; if (!empty($eventData['parent_event_id'])) { @@ -95,6 +95,9 @@ final class Version20201215072918 extends AbstractMigrationChamilo if (false === $result) { continue; } + + $this->fixItemProperty('calendar_event', $eventRepo, $course, $admin, $event, $parent); + $em->persist($event); $em->flush(); } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201216124011.php b/src/CoreBundle/Migrations/Schema/V200/Version20201216124011.php index d591744339..3f679eecbd 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201216124011.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201216124011.php @@ -93,7 +93,7 @@ final class Version20201216124011 extends AbstractMigrationChamilo $sql = "SELECT * FROM c_student_publication WHERE contains_file = 1 AND - c_id = $courseId AND + c_id = $courseId ORDER BY iid"; $result = $connection->executeQuery($sql); $items = $result->fetchAllAssociative(); diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php b/src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php index 2e97488157..9b7359532c 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php @@ -41,11 +41,11 @@ class Version20210221082033 extends AbstractMigrationChamilo $items = $result->fetchAllAssociative(); foreach ($items as $itemData) { $id = $itemData['iid']; + $path = $itemData['preview_image']; $lp = $lpRepo->find($id); - if ($lp && !empty($lp->getPreviewImage())) { - $path = $lp->getPreviewImage(); + if ($lp && !empty($path)) { $filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/learning_path/images/'.$path; - if (file_exists($rootPath)) { + if (file_exists($rootPath) && !is_dir($filePath)) { $this->addLegacyFileToResource($filePath, $lpRepo, $lp, $lp->getIid(), $path); $em->persist($lp); $em->flush(); diff --git a/src/CourseBundle/Entity/CCalendarEventRepeat.php b/src/CourseBundle/Entity/CCalendarEventRepeat.php index 270e5cc1f0..4977a3a6af 100644 --- a/src/CourseBundle/Entity/CCalendarEventRepeat.php +++ b/src/CourseBundle/Entity/CCalendarEventRepeat.php @@ -28,12 +28,10 @@ class CCalendarEventRepeat protected $iid; /** - * @var CCalendarEvent - * * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CCalendarEvent", inversedBy="repeatEvents") * @ORM\JoinColumn(name="cal_id", referencedColumnName="iid") */ - protected $event; + protected CCalendarEvent $event; /** * @var string @@ -67,10 +65,8 @@ class CCalendarEventRepeat * Set calType. * * @param string $calType - * - * @return CCalendarEventRepeat */ - public function setCalType($calType) + public function setCalType($calType): self { $this->calType = $calType; @@ -91,10 +87,8 @@ class CCalendarEventRepeat * Set calEnd. * * @param int $calEnd - * - * @return CCalendarEventRepeat */ - public function setCalEnd($calEnd) + public function setCalEnd($calEnd): self { $this->calEnd = $calEnd; @@ -115,10 +109,8 @@ class CCalendarEventRepeat * Set calFrequency. * * @param int $calFrequency - * - * @return CCalendarEventRepeat */ - public function setCalFrequency($calFrequency) + public function setCalFrequency($calFrequency): self { $this->calFrequency = $calFrequency; @@ -139,10 +131,8 @@ class CCalendarEventRepeat * Set calDays. * * @param string $calDays - * - * @return CCalendarEventRepeat */ - public function setCalDays($calDays) + public function setCalDays($calDays): self { $this->calDays = $calDays; diff --git a/src/CourseBundle/Entity/CForumForum.php b/src/CourseBundle/Entity/CForumForum.php index ca2203c579..44e6d3ff87 100644 --- a/src/CourseBundle/Entity/CForumForum.php +++ b/src/CourseBundle/Entity/CForumForum.php @@ -77,12 +77,10 @@ class CForumForum extends AbstractResource implements ResourceInterface /** * @Gedmo\SortableGroup * - * @var CForumCategory|null - * * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumCategory", inversedBy="forums") * @ORM\JoinColumn(name="forum_category", referencedColumnName="iid", nullable=true, onDelete="SET NULL") */ - protected $forumCategory; + protected ?CForumCategory $forumCategory; /** * @var int @@ -187,7 +185,7 @@ class CForumForum extends AbstractResource implements ResourceInterface * @ORM\OneToOne(targetEntity="Chamilo\CourseBundle\Entity\CLp", inversedBy="forum") * @ORM\JoinColumn(name="lp_id", referencedColumnName="iid", nullable=true) */ - protected $lp; + protected ?CLp $lp; /** * @var bool @@ -210,9 +208,6 @@ class CForumForum extends AbstractResource implements ResourceInterface */ protected $posts; - /** - * CForumForum constructor. - */ public function __construct() { $this->threads = new ArrayCollection();