Update migration

pull/3844/head
Julio Montoya 4 years ago
parent 6304f4c3e8
commit 6ad7d141b7
  1. 5
      src/CoreBundle/Migrations/Schema/V200/Version20.php
  2. 9
      src/CoreBundle/Migrations/Schema/V200/Version20170525122900.php
  3. 37
      src/CoreBundle/Migrations/Schema/V200/Version20170625123000.php
  4. 2
      src/CoreBundle/Migrations/Schema/V200/Version20180927172830.php
  5. 197
      src/CoreBundle/Migrations/Schema/V200/Version20181025064351.php
  6. 30
      src/CoreBundle/Migrations/Schema/V200/Version20190110182615.php
  7. 48
      src/CoreBundle/Migrations/Schema/V200/Version20191206150000.php
  8. 69
      src/CoreBundle/Migrations/Schema/V200/Version20191206150030.php
  9. 6
      src/CoreBundle/Migrations/Schema/V200/Version20200821224242.php
  10. 61
      src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php

@ -191,10 +191,7 @@ class Version20 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE usergroup ADD resource_node_id INT DEFAULT NULL');
}
if (false === $table->hasForeignKey('FK_4A6478171BAD783F')) {
$this->addSql('ALTER TABLE usergroup ADD CONSTRAINT FK_4A6478171BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
$this->addSql('CREATE UNIQUE INDEX UNIQ_4A6478171BAD783F ON usergroup (resource_node_id)');
}
// Update template.
$table = $schema->getTable('templates');

@ -170,6 +170,15 @@ class Version20170525122900 extends AbstractMigrationChamilo
'ALTER TABLE c_shortcut ADD CONSTRAINT FK_3F6BB9571BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'
);
}
$table = $schema->getTable('usergroup');
if (false === $table->hasForeignKey('FK_4A6478171BAD783F')) {
$this->addSql('ALTER TABLE usergroup ADD CONSTRAINT FK_4A6478171BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
}
if (false === $table->hasIndex('UNIQ_4A6478171BAD783F')) {
$this->addSql('CREATE UNIQUE INDEX UNIQ_4A6478171BAD783F ON usergroup (resource_node_id)');
}
}
public function down(Schema $schema): void

@ -49,11 +49,7 @@ class Version20170625123000 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE c_attendance_calendar ADD CONSTRAINT FK_AA3A9AB8163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid);');
}
if ($table->hasIndex('attendance_id')) {
$this->addSql('DROP INDEX attendance_id ON c_attendance_calendar');
}
if (false === $table->hasIndex('attendance_id')) {
if (false === $table->hasIndex('IDX_AA3A9AB8163DDA15')) {
$this->addSql('CREATE INDEX IDX_AA3A9AB8163DDA15 ON c_attendance_calendar (attendance_id);');
}
@ -83,9 +79,6 @@ class Version20170625123000 extends AbstractMigrationChamilo
if (false === $table->hasIndex('IDX_AD1394FA19EA43C3')) {
$this->addSql('CREATE INDEX IDX_AD1394FA19EA43C3 ON c_attendance_sheet (attendance_calendar_id);');
}
if ($table->hasIndex('user')) {
$this->addSql('DROP INDEX user ON c_attendance_sheet;');
}
if (false === $table->hasIndex('IDX_AD1394FAA76ED395')) {
$this->addSql('CREATE INDEX IDX_AD1394FAA76ED395 ON c_attendance_sheet (user_id);');
@ -97,7 +90,17 @@ class Version20170625123000 extends AbstractMigrationChamilo
$this->addSql('DROP INDEX course ON c_attendance_result');
}
$this->addSql('UPDATE c_attendance_result SET attendance_id = NULL WHERE attendance_id = 0;');
if ($table->hasIndex('user_id')) {
$this->addSql('DROP INDEX user_id ON c_attendance_result');
}
if ($table->hasIndex('attendance_id')) {
$this->addSql('DROP INDEX attendance_id ON c_attendance_result;');
}
$this->addSql('UPDATE c_attendance_result SET attendance_id = NULL WHERE attendance_id = 0');
$this->addSql('UPDATE c_attendance_result SET user_id = NULL WHERE user_id = 0');
//ALTER TABLE c_attendance_result DROP c_id, ;
$this->addSql('ALTER TABLE c_attendance_result CHANGE user_id user_id INT DEFAULT NULL, CHANGE attendance_id attendance_id INT DEFAULT NULL ');
@ -109,16 +112,10 @@ class Version20170625123000 extends AbstractMigrationChamilo
if (false === $table->hasForeignKey('FK_2C7640163DDA15')) {
$this->addSql('ALTER TABLE c_attendance_result ADD CONSTRAINT FK_2C7640163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid);');
}
if ($table->hasIndex('user_id')) {
$this->addSql('DROP INDEX user_id ON c_attendance_result;');
}
if (false === $table->hasIndex('IDX_2C7640A76ED395')) {
$this->addSql('CREATE INDEX IDX_2C7640A76ED395 ON c_attendance_result (user_id);');
}
if ($table->hasIndex('attendance_id')) {
$this->addSql('DROP INDEX attendance_id ON c_attendance_result;');
}
if (false === $table->hasIndex('IDX_2C7640163DDA15')) {
$this->addSql('CREATE INDEX IDX_2C7640163DDA15 ON c_attendance_result (attendance_id);');
@ -135,11 +132,10 @@ class Version20170625123000 extends AbstractMigrationChamilo
$this->addSql('UPDATE c_attendance_calendar_rel_group SET calendar_id = NULL WHERE calendar_id = 0');
$this->addSql('ALTER TABLE c_attendance_calendar_rel_group CHANGE group_id group_id INT DEFAULT NULL, CHANGE calendar_id calendar_id INT DEFAULT NULL;');
if ($table->hasIndex('course')) {
$this->addSql('DROP INDEX course ON c_attendance_calendar_rel_group');
}
if (false === $table->hasForeignKey('FK_C2AB1FACFE54D947')) {
if ($table->hasIndex('group')) {
$this->addSql('DROP INDEX `group` ON c_attendance_calendar_rel_group');
}
$this->addSql('ALTER TABLE c_attendance_calendar_rel_group ADD CONSTRAINT FK_C2AB1FACFE54D947 FOREIGN KEY (group_id) REFERENCES c_group_info (iid);');
}
@ -151,9 +147,6 @@ class Version20170625123000 extends AbstractMigrationChamilo
$this->addSql('CREATE INDEX IDX_C2AB1FACA40A2C8 ON c_attendance_calendar_rel_group (calendar_id);');
}
if ($table->hasIndex('group')) {
$this->addSql('DROP INDEX `group` ON c_attendance_calendar_rel_group;');
}
if (false === $table->hasIndex('IDX_C2AB1FACFE54D947')) {
$this->addSql('CREATE INDEX IDX_C2AB1FACFE54D947 ON c_attendance_calendar_rel_group (group_id);');
}

@ -52,6 +52,8 @@ class Version20180927172830 extends AbstractMigrationChamilo
}
$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->hasForeignKey('FK_47A9C9968DFD1EF')) {
$this->addSql('ALTER TABLE c_forum_forum ADD CONSTRAINT FK_47A9C9968DFD1EF FOREIGN KEY (lp_id) REFERENCES c_lp (iid)');
}

@ -22,12 +22,52 @@ class Version20181025064351 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE gradebook_result_log CHANGE id_result result_id INT NOT NULL');
}
$this->addSql('UPDATE gradebook_result_log SET user_id = NULL WHERE user_id = 0');
$this->addSql('ALTER TABLE gradebook_result_log CHANGE user_id user_id INT DEFAULT NULL');
if (false === $table->hasForeignKey('FK_C5C4CABBA76ED395')) {
$this->addSql(
'ALTER TABLE gradebook_result_log ADD CONSTRAINT FK_C5C4CABBA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
}
if (false === $table->hasIndex('IDX_C5C4CABBA76ED395')) {
$this->addSql('CREATE INDEX IDX_C5C4CABBA76ED395 ON gradebook_result_log (user_id)');
}
$table = $schema->getTable('gradebook_category');
$this->addSql('ALTER TABLE gradebook_category CHANGE user_id user_id INT DEFAULT NULL');
$this->addSql(
'DELETE FROM gradebook_category WHERE user_id IS NOT NULL AND user_id NOT IN (SELECT id FROM user)'
);
$table = $schema->getTable('gradebook_category');
if ($table->hasIndex('idx_gb_cat_parent')) {
$this->addSql(' DROP INDEX idx_gb_cat_parent ON gradebook_category;');
}
$this->addSql('UPDATE gradebook_category SET session_id = NULL WHERE session_id = 0');
$this->addSql('UPDATE gradebook_category SET parent_id = NULL WHERE parent_id = 0');
if (false === $table->hasForeignKey('FK_96A4C705727ACA70')) {
$this->addSql('ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C705727ACA70 FOREIGN KEY (parent_id) REFERENCES gradebook_category (id);');
}
if (false === $table->hasForeignKey('FK_96A4C705613FECDF')) {
$this->addSql('ALTER TABLE gradebook_category ADD CONSTRAINT FK_96A4C705613FECDF FOREIGN KEY (session_id) REFERENCES session (id);');
}
if (false === $table->hasIndex('IDX_96A4C705613FECDF')) {
$this->addSql('CREATE INDEX IDX_96A4C705613FECDF ON gradebook_category (session_id)');
}
if (false === $table->hasIndex('IDX_96A4C705727ACA70')) {
$this->addSql('CREATE INDEX IDX_96A4C705727ACA70 ON gradebook_category (parent_id);');
}
if (false === $table->hasColumn('c_id')) {
$this->addSql('ALTER TABLE gradebook_category ADD c_id INT DEFAULT NULL');
$this->addSql('UPDATE gradebook_category SET c_id = (SELECT id FROM course WHERE code = course_code)');
@ -47,9 +87,6 @@ class Version20181025064351 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE gradebook_category ADD gradebooks_to_validate_in_dependence INT DEFAULT NULL');
}
if (false === $table->hasIndex('idx_gb_cat_parent')) {
$this->addSql('CREATE INDEX idx_gb_cat_parent ON gradebook_category (parent_id)');
}
if (false === $table->hasForeignKey('FK_96A4C705A76ED395')) {
$this->addSql(
@ -76,6 +113,10 @@ class Version20181025064351 extends AbstractMigrationChamilo
$this->addSql('CREATE INDEX idx_ge_cat ON gradebook_evaluation (category_id)');
}
if (false === $table->hasForeignKey('FK_DDDED80412469DE2')) {
$this->addSql('ALTER TABLE gradebook_evaluation ADD CONSTRAINT FK_DDDED80412469DE2 FOREIGN KEY (category_id) REFERENCES gradebook_category (id);');
}
if (false === $table->hasColumn('best_score')) {
$this->addSql('ALTER TABLE gradebook_evaluation ADD best_score DOUBLE PRECISION DEFAULT NULL');
}
@ -112,16 +153,95 @@ class Version20181025064351 extends AbstractMigrationChamilo
);
$this->addSql('CREATE INDEX IDX_4F0F595F91D79BD3 ON gradebook_link (c_id);');
}
if (false === $table->hasColumn('best_score')) {
$this->addSql('ALTER TABLE gradebook_link ADD best_score DOUBLE PRECISION DEFAULT NULL');
}
if (false === $table->hasColumn('average_score')) {
$this->addSql(
'ALTER TABLE gradebook_link ADD average_score DOUBLE PRECISION DEFAULT NULL'
);
}
if (false === $table->hasColumn('score_weight')) {
$this->addSql('ALTER TABLE gradebook_link ADD score_weight DOUBLE PRECISION DEFAULT NULL');
}
if (false === $table->hasColumn('user_score_list')) {
$this->addSql(
'ALTER TABLE gradebook_link ADD user_score_list LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\''
);
}
if (false === $table->hasIndex('idx_gl_cat')) {
$this->addSql('CREATE INDEX idx_gl_cat ON gradebook_link (category_id)');
}
$this->addSql('ALTER TABLE gradebook_link CHANGE user_id user_id INT DEFAULT NULL');
if (false === $table->hasForeignKey('FK_4F0F595FA76ED395')) {
$this->addSql(
'ALTER TABLE gradebook_link ADD CONSTRAINT FK_4F0F595FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
}
if (false === $table->hasIndex('IDX_4F0F595FA76ED395')) {
$this->addSql('CREATE INDEX IDX_4F0F595FA76ED395 ON gradebook_link (user_id)');
}
$this->addSql('ALTER TABLE gradebook_link CHANGE category_id category_id INT DEFAULT NULL;');
$this->addSql('UPDATE gradebook_link SET category_id = NULL WHERE category_id = 0');
if (false === $table->hasForeignKey('FK_4F0F595F12469DE2')) {
$this->addSql('ALTER TABLE gradebook_link ADD CONSTRAINT FK_4F0F595F12469DE2 FOREIGN KEY (category_id) REFERENCES gradebook_category (id);');
}
$table = $schema->getTable('gradebook_result');
if (false === $table->hasIndex('idx_gb_uid_eid')) {
$this->addSql('CREATE INDEX idx_gb_uid_eid ON gradebook_result (user_id, evaluation_id)');
if ($table->hasIndex('idx_gb_uid_eid')) {
$this->addSql('');
}
if (false === $table->hasIndex('IDX_B88AEB67456C5646')) {
$this->addSql('CREATE INDEX IDX_B88AEB67456C5646 ON gradebook_result (evaluation_id);');
}
$this->addSql('ALTER TABLE gradebook_result CHANGE evaluation_id evaluation_id INT DEFAULT NULL;');
$this->addSql('UPDATE gradebook_result SET evaluation_id = NULL WHERE evaluation_id = 0');
if (false === $table->hasForeignKey('FK_B88AEB67456C5646')) {
$this->addSql('ALTER TABLE gradebook_result ADD CONSTRAINT FK_B88AEB67456C5646 FOREIGN KEY (evaluation_id) REFERENCES gradebook_evaluation (id);');
}
$this->addSql('ALTER TABLE gradebook_result CHANGE user_id user_id INT DEFAULT NULL');
$this->addSql('UPDATE gradebook_result SET user_id = NULL WHERE user_id = 0');
if (false === $table->hasForeignKey('FK_B88AEB67A76ED395')) {
$this->addSql(
'ALTER TABLE gradebook_result ADD CONSTRAINT FK_B88AEB67A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
}
if (false === $table->hasIndex('IDX_B88AEB67A76ED395')) {
$this->addSql('CREATE INDEX IDX_B88AEB67A76ED395 ON gradebook_result (user_id)');
}
$table = $schema->getTable('gradebook_certificate');
$this->addSql('ALTER TABLE gradebook_certificate CHANGE cat_id cat_id INT DEFAULT NULL;');
$this->addSql('UPDATE gradebook_certificate SET cat_id = NULL WHERE cat_id = 0');
if (false === $table->hasForeignKey('FK_650669DE6ADA943')) {
if ($table->hasIndex('idx_gradebook_certificate_category_id')) {
$this->addSql('DROP INDEX idx_gradebook_certificate_category_id ON gradebook_certificate;');
}
if ($table->hasIndex('idx_gradebook_certificate_category_id_user_id')) {
$this->addSql('DROP INDEX idx_gradebook_certificate_category_id_user_id ON gradebook_certificate;');
}
$this->addSql('ALTER TABLE gradebook_certificate ADD CONSTRAINT FK_650669DE6ADA943 FOREIGN KEY (cat_id) REFERENCES gradebook_category (id);');
}
if (false === $table->hasColumn('downloaded_at')) {
$this->addSql('ALTER TABLE gradebook_certificate ADD downloaded_at DATETIME DEFAULT NULL;');
$this->addSql(
@ -141,6 +261,10 @@ class Version20181025064351 extends AbstractMigrationChamilo
);
}
if (false === $table->hasIndex('IDX_650669DE6ADA943')) {
$this->addSql('CREATE INDEX IDX_650669DE6ADA943 ON gradebook_certificate (cat_id);');
}
$table = $schema->hasTable('gradebook_result_attempt');
if (false === $table) {
$this->addSql(
@ -148,32 +272,37 @@ class Version20181025064351 extends AbstractMigrationChamilo
);
}
$this->addSql(
'ALTER TABLE gradebook_link ADD best_score DOUBLE PRECISION DEFAULT NULL, ADD average_score DOUBLE PRECISION DEFAULT NULL, ADD score_weight DOUBLE PRECISION DEFAULT NULL, ADD user_score_list LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:array)\', CHANGE user_id user_id INT DEFAULT NULL'
);
$this->addSql(
'ALTER TABLE gradebook_link ADD CONSTRAINT FK_4F0F595FA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
$this->addSql('CREATE INDEX IDX_4F0F595FA76ED395 ON gradebook_link (user_id)');
$table = $schema->getTable('gradebook_linkeval_log');
$this->addSql('UPDATE gradebook_linkeval_log SET user_id_log = NULL WHERE user_id_log = 0');
$this->addSql('ALTER TABLE gradebook_linkeval_log CHANGE user_id_log user_id_log INT DEFAULT NULL');
$this->addSql(
'ALTER TABLE gradebook_linkeval_log ADD CONSTRAINT FK_1F554C7474C99BA2 FOREIGN KEY (user_id_log) REFERENCES user (id) ON DELETE CASCADE'
);
$this->addSql('CREATE INDEX IDX_1F554C7474C99BA2 ON gradebook_linkeval_log (user_id_log)');
$this->addSql('ALTER TABLE gradebook_result CHANGE user_id user_id INT DEFAULT NULL');
$this->addSql(
'ALTER TABLE gradebook_result ADD CONSTRAINT FK_B88AEB67A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
$this->addSql('CREATE INDEX IDX_B88AEB67A76ED395 ON gradebook_result (user_id)');
$this->addSql('ALTER TABLE gradebook_result_log CHANGE user_id user_id INT DEFAULT NULL');
$this->addSql(
'ALTER TABLE gradebook_result_log ADD CONSTRAINT FK_C5C4CABBA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
$this->addSql('CREATE INDEX IDX_C5C4CABBA76ED395 ON gradebook_result_log (user_id)');
if (false === $table->hasForeignKey('FK_1F554C7474C99BA2')) {
$this->addSql(
'ALTER TABLE gradebook_linkeval_log ADD CONSTRAINT FK_1F554C7474C99BA2 FOREIGN KEY (user_id_log) REFERENCES user (id) ON DELETE CASCADE'
);
}
if (false === $table->hasIndex('IDX_1F554C7474C99BA2')) {
$this->addSql('CREATE INDEX IDX_1F554C7474C99BA2 ON gradebook_linkeval_log (user_id_log)');
}
$table = $schema->getTable('gradebook_score_log');
$this->addSql('ALTER TABLE gradebook_score_log CHANGE user_id user_id INT DEFAULT NULL');
$this->addSql(
'ALTER TABLE gradebook_score_log ADD CONSTRAINT FK_640C6449A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
$this->addSql('ALTER TABLE gradebook_score_log CHANGE category_id category_id INT DEFAULT NULL;');
if (false === $table->hasForeignKey('FK_640C6449A76ED395')) {
$this->addSql(
'ALTER TABLE gradebook_score_log ADD CONSTRAINT FK_640C6449A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE'
);
}
if (false === $table->hasIndex('IDX_640C644912469DE2')) {
$this->addSql('CREATE INDEX IDX_640C644912469DE2 ON gradebook_score_log (category_id);');
}
$table = $schema->hasTable('gradebook_comment');
if (false === $table) {
@ -181,6 +310,14 @@ class Version20181025064351 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE gradebook_comment ADD CONSTRAINT FK_C3B70763A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;');
$this->addSql('ALTER TABLE gradebook_comment ADD CONSTRAINT FK_C3B70763AD3ED51C FOREIGN KEY (gradebook_id) REFERENCES gradebook_category (id) ON DELETE CASCADE;');
}
$table = $schema->getTable('gradebook_score_display');
$this->addSql('ALTER TABLE gradebook_score_display CHANGE category_id category_id INT DEFAULT NULL;');
$this->addSql('UPDATE gradebook_score_display SET category_id = NULL WHERE category_id = 0');
if (false === $table->hasForeignKey('FK_61F7DC8412469DE2')) {
$this->addSql('ALTER TABLE gradebook_score_display ADD CONSTRAINT FK_61F7DC8412469DE2 FOREIGN KEY (category_id) REFERENCES gradebook_category (id);');
}
}
public function down(Schema $schema): void

@ -69,36 +69,6 @@ class Version20190110182615 extends AbstractMigrationChamilo
);
}
$em = $doctrine->getManager();
/** @var Connection $connection */
$connection = $em->getConnection();
$lpRepo = $container->get(CLpRepository::class);
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
/** @var Course $course */
foreach ($q->toIterable() as $course) {
$courseId = $course->getId();
$sql = "SELECT * FROM c_lp WHERE c_id = $courseId
ORDER BY iid";
$result = $connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
foreach ($items as $itemData) {
$id = $itemData['iid'];
$lp = $lpRepo->find($id);
if ($lp && !empty($lp->getPreviewImage())) {
$path = $lp->getPreviewImage();
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/learning_path/images/'.$path;
if (file_exists($rootPath)) {
$this->addLegacyFileToResource($filePath, $lpRepo, $lp, $lp->getIid(), $path);
$em->persist($lp);
$em->flush();
}
}
}
$em->flush();
$em->clear();
}
$table = $schema->getTable('c_lp_category');
if (false === $table->hasColumn('session_id')) {

@ -31,53 +31,5 @@ class Version20191206150000 extends AbstractMigrationChamilo
if (!$table->hasIndex('idx_efv_item')) {
$this->addSql('CREATE INDEX idx_efv_item ON extra_field_values (item_id)');
}
// Migrate extra field fields
$container = $this->getContainer();
$doctrine = $container->get('doctrine');
$em = $doctrine->getManager();
/** @var Connection $connection */
$connection = $em->getConnection();
$kernel = $container->get('kernel');
$rootPath = $kernel->getProjectDir();
$batchSize = self::BATCH_SIZE;
$counter = 1;
$q = $em->createQuery('SELECT v FROM Chamilo\CoreBundle\Entity\ExtraFieldValues v');
$fieldWithFiles = \ExtraField::getExtraFieldTypesWithFiles();
/** @var ExtraFieldValues $item */
foreach ($q->toIterable() as $item) {
if (in_array($item->getField()->getFieldType(), $fieldWithFiles)) {
$path = $item->getValue();
if (empty($path)) {
continue;
}
$filePath = $rootPath.'/app/upload/'.$path;
if (file_exists($filePath) && !is_dir($filePath)) {
$fileName = basename($path);
$mimeType = mime_content_type($filePath);
$file = new UploadedFile($filePath, $fileName, $mimeType, null, true);
$asset = new Asset();
$asset
->setCategory(Asset::EXTRA_FIELD)
->setTitle($fileName)
->setFile($file)
;
$em->persist($asset);
$em->flush();
$item->setValue($asset->getId());
$em->persist($item);
}
}
if (0 === $counter % $batchSize) {
$em->flush();
$em->clear(); // Detaches all objects from Doctrine!
}
$counter++;
}
}
}

@ -0,0 +1,69 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\Asset;
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Extra fields.
*/
class Version20191206150030 extends AbstractMigrationChamilo
{
public function up(Schema $schema): void
{
// Migrate extra field fields
$container = $this->getContainer();
$doctrine = $container->get('doctrine');
$em = $doctrine->getManager();
/** @var Connection $connection */
$connection = $em->getConnection();
$kernel = $container->get('kernel');
$rootPath = $kernel->getProjectDir();
$batchSize = self::BATCH_SIZE;
$counter = 1;
$q = $em->createQuery('SELECT v FROM Chamilo\CoreBundle\Entity\ExtraFieldValues v');
$fieldWithFiles = \ExtraField::getExtraFieldTypesWithFiles();
/** @var ExtraFieldValues $item */
foreach ($q->toIterable() as $item) {
if (in_array($item->getField()->getFieldType(), $fieldWithFiles)) {
$path = $item->getValue();
if (empty($path)) {
continue;
}
$filePath = $rootPath.'/app/upload/'.$path;
if (file_exists($filePath) && !is_dir($filePath)) {
$fileName = basename($path);
$mimeType = mime_content_type($filePath);
$file = new UploadedFile($filePath, $fileName, $mimeType, null, true);
$asset = new Asset();
$asset
->setCategory(Asset::EXTRA_FIELD)
->setTitle($fileName)
->setFile($file)
;
$em->persist($asset);
$em->flush();
$item->setValue($asset->getId());
$em->persist($item);
}
}
if (0 === $counter % $batchSize) {
$em->flush();
$em->clear(); // Detaches all objects from Doctrine!
}
$counter++;
}
}
}

@ -19,12 +19,6 @@ final class Version20200821224242 extends AbstractMigrationChamilo
$table = $schema->getTable('message');
$this->addSql('ALTER TABLE message CHANGE parent_id parent_id BIGINT DEFAULT NULL');
if (false === $table->hasForeignKey('FK_B6BD307F727ACA70')) {
$this->addSql(
'ALTER TABLE message ADD CONSTRAINT FK_B6BD307F727ACA70 FOREIGN KEY (parent_id) REFERENCES message (id)'
);
}
if ($table->hasIndex('idx_message_parent')) {
$this->addSql('DROP INDEX idx_message_parent ON message');
}

@ -0,0 +1,61 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\Kernel;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
class Version20210221082033 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Migrate c_lp images';
}
public function up(Schema $schema): void
{
$container = $this->getContainer();
/** @var Kernel $kernel */
$kernel = $container->get('kernel');
$rootPath = $kernel->getProjectDir();
$doctrine = $container->get('doctrine');
$em = $doctrine->getManager();
/** @var Connection $connection */
$connection = $em->getConnection();
$lpRepo = $container->get(CLpRepository::class);
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
/** @var Course $course */
foreach ($q->toIterable() as $course) {
$courseId = $course->getId();
$sql = "SELECT * FROM c_lp WHERE c_id = $courseId
ORDER BY iid";
$result = $connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
foreach ($items as $itemData) {
$id = $itemData['iid'];
$lp = $lpRepo->find($id);
if ($lp && !empty($lp->getPreviewImage())) {
$path = $lp->getPreviewImage();
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/learning_path/images/'.$path;
if (file_exists($rootPath)) {
$this->addLegacyFileToResource($filePath, $lpRepo, $lp, $lp->getIid(), $path);
$em->persist($lp);
$em->flush();
}
}
}
$em->flush();
$em->clear();
}
}
}
Loading…
Cancel
Save