Migration - Add MigrationFactory.php + fix queries

pull/3959/head
Julio 4 years ago
parent 5f975dca14
commit 198b2c2170
  1. 3
      config/packages/doctrine_migrations.yaml
  2. 27
      src/CoreBundle/Migrations/AbstractMigrationChamilo.php
  3. 32
      src/CoreBundle/Migrations/MigrationFactory.php
  4. 12
      src/CoreBundle/Migrations/Schema/V200/Version20180319145700.php
  5. 2
      src/CoreBundle/Migrations/Schema/V200/Version20191206150030.php
  6. 7
      src/CoreBundle/Migrations/Schema/V200/Version20201205102020.php
  7. 1
      src/CoreBundle/Migrations/Schema/V200/Version20201212195112.php
  8. 8
      src/CoreBundle/Migrations/Schema/V200/Version20201218132719.php
  9. 4
      src/CoreBundle/Migrations/Schema/V200/Version20210205082253.php
  10. 2
      src/CoreBundle/Migrations/Schema/V200/Version20210221082033.php
  11. 2
      src/CoreBundle/Migrations/Schema/V200/Version20210813150011.php
  12. 5
      src/CoreBundle/Resources/config/services.yml

@ -3,6 +3,9 @@ doctrine_migrations:
migrations_paths:
'Chamilo\CoreBundle\Migrations\Schema\V200': '%kernel.project_dir%/src/CoreBundle/Migrations/Schema/V200'
services:
'Doctrine\Migrations\Version\MigrationFactory': 'Chamilo\CoreBundle\Migrations\MigrationFactory'
connection: default
# Run all migrations in a transaction.

@ -84,27 +84,7 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con
*/
public function getEntityManager()
{
if (empty($this->manager)) {
//$params = $this->connection->getParams();
/*
$dbParams = [
'driver' => 'pdo_mysql',
'host' => $this->connection->getHost(),
'user' => $this->connection->getUsername(),
'password' => $this->connection->getPassword(),
'dbname' => $this->connection->getDatabase(),
'port' => $this->connection->getPort(),
];*/
/*$database = new \Database();
$database->connect(
$params,
__DIR__.'/../../',
__DIR__.'/../../'
);
$this->manager = $database->getManager();*/
}
return $this->manager;
return $this->getContainer()->get('doctrine')->getManager();
}
/**
@ -340,4 +320,9 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con
return true;
}
public function fileExists($filePath): bool
{
return file_exists($filePath) && !is_dir($filePath) && is_readable($filePath);
}
}

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Chamilo\CoreBundle\Migrations;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MigrationFactory implements \Doctrine\Migrations\Version\MigrationFactory
{
private \Doctrine\Migrations\Version\MigrationFactory $migrationFactory;
private ContainerInterface $container;
public function __construct(\Doctrine\Migrations\Version\MigrationFactory $migrationFactory, ContainerInterface $container)
{
$this->migrationFactory = $migrationFactory;
$this->container = $container;
}
public function createVersion(string $migrationClassName): AbstractMigration
{
$instance = $this->migrationFactory->createVersion($migrationClassName);
if ($instance instanceof ContainerAwareInterface) {
$instance->setContainer($this->container);
}
return $instance;
}
}

@ -102,17 +102,19 @@ class Version20180319145700 extends AbstractMigrationChamilo
$this->addSql('CREATE INDEX idx_survey_code ON c_survey (code)');
}*/
$table = $schema->getTable('c_survey_invitation');
$this->addSql('ALTER TABLE c_survey_invitation CHANGE reminder_date reminder_date DATETIME DEFAULT NULL');
$this->addSql(
'UPDATE c_survey_invitation SET reminder_date = NULL WHERE CAST(reminder_date AS CHAR(20)) = "0000-00-00 00:00:00"'
);
$table = $schema->getTable('c_survey_invitation');
// c_survey_invitation.user_id
/*if (!$table->hasColumn('user_id')) {
if (!$table->hasColumn('user_id')) {
$this->addSql('ALTER TABLE c_survey_invitation ADD user_id INT DEFAULT NULL');
$this->addSql('DELETE FROM c_survey_invitation WHERE user NOT IN (SELECT id FROM user) ');
$this->addSql('ALTER TABLE c_survey_invitation CHANGE user user VARCHAR(255) DEFAULT NULL');
$this->addSql('UPDATE c_survey_invitation SET user = NULL WHERE user NOT IN (SELECT id FROM user)');
$this->addSql('UPDATE c_survey_invitation SET user_id = user');
}
@ -124,7 +126,7 @@ class Version20180319145700 extends AbstractMigrationChamilo
if (!$table->hasIndex('IDX_D0BC7C2A76ED395')) {
$this->addSql('CREATE INDEX IDX_D0BC7C2A76ED395 ON c_survey_invitation (user_id)');
}*/
}
if (!$table->hasColumn('answered_at')) {
$this->addSql('ALTER TABLE c_survey_invitation ADD answered_at DATETIME DEFAULT NULL;');

@ -43,7 +43,7 @@ class Version20191206150030 extends AbstractMigrationChamilo
continue;
}
$filePath = $rootPath.'/app/upload/'.$path;
if (file_exists($filePath) && !is_dir($filePath)) {
if ($this->fileExists($filePath)) {
$fileName = basename($path);
$mimeType = mime_content_type($filePath);
$file = new UploadedFile($filePath, $fileName, $mimeType, null, true);

@ -20,12 +20,17 @@ final class Version20201205102020 extends AbstractMigrationChamilo
{
$table = $schema->getTable('skill');
$this->addSql('UPDATE skill SET updated_at = NOW() WHERE CAST(updated_at AS CHAR(20)) = "0000-00-00 00:00:00"');
if (!$table->hasColumn('asset_id')) {
$this->addSql('ALTER TABLE skill ADD asset_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE skill ADD CONSTRAINT FK_5E3DE4775DA1941 FOREIGN KEY (asset_id) REFERENCES asset (id)');
$this->addSql('CREATE INDEX IDX_5E3DE4775DA1941 ON skill (asset_id)');
}
if (!$table->hasForeignKey('FK_5E3DE4775DA1941')) {
$this->addSql('ALTER TABLE skill ADD CONSTRAINT FK_5E3DE4775DA1941 FOREIGN KEY (asset_id) REFERENCES asset (id)');
}
if (!$schema->hasTable('skill_rel_item_rel_user')) {
$this->addSql(
'CREATE TABLE skill_rel_item_rel_user (id INT AUTO_INCREMENT NOT NULL, skill_rel_item_id INT NOT NULL, user_id INT NOT NULL, result_id INT DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by INT NOT NULL, updated_by INT NOT NULL, INDEX IDX_D1133E0DFD4B12DC (skill_rel_item_id), INDEX IDX_D1133E0DA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;'

@ -38,7 +38,6 @@ final class Version20201212195112 extends AbstractMigrationChamilo
$groupCategoryRepo = $container->get(CGroupCategoryRepository::class);
$batchSize = self::BATCH_SIZE;
$admin = $this->getAdmin();
// Migrating c_tool.
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');

@ -14,7 +14,6 @@ use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\CourseBundle\Entity\CSurvey;
use Chamilo\CourseBundle\Repository\CGroupRepository;
use Chamilo\CourseBundle\Repository\CSurveyRepository;
use Chamilo\Kernel;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
@ -38,11 +37,6 @@ final class Version20201218132719 extends AbstractMigrationChamilo
$sessionRepo = $container->get(SessionRepository::class);
$groupRepo = $container->get(CGroupRepository::class);
$userRepo = $container->get(UserRepository::class);
/** @var Kernel $kernel */
$kernel = $container->get('kernel');
$rootPath = $kernel->getProjectDir();
$admin = $this->getAdmin();
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
/** @var Course $course */
@ -61,6 +55,8 @@ final class Version20201218132719 extends AbstractMigrationChamilo
continue;
}
$admin = $this->getAdmin();
$result = $this->fixItemProperty(
'survey',
$surveyRepo,

@ -58,7 +58,7 @@ final class Version20210205082253 extends AbstractMigrationChamilo
$path = 'users/'.substr((string) $id, 0, 1).'/'.$id.'/';
}
$picturePath = $rootPath.'/app/upload/'.$path.'/'.$picture;
if (file_exists($picturePath) && !is_dir($picturePath)) {
if ($this->fileExists($picturePath)) {
$mimeType = mime_content_type($picturePath);
$file = new UploadedFile($picturePath, $picture, $mimeType, null, true);
$illustrationRepo->addIllustration($userEntity, $userEntity, $file);
@ -94,7 +94,7 @@ final class Version20210205082253 extends AbstractMigrationChamilo
$path = 'groups/'.substr((string) $id, 0, 1).'/'.$id.'/';
}
$picturePath = $rootPath.'/app/upload/'.$path.'/'.$picture;
if (file_exists($picturePath) && !is_dir($picturePath)) {
if ($this->fileExists($picturePath)) {
$mimeType = mime_content_type($picturePath);
$file = new UploadedFile($picturePath, $picture, $mimeType, null, true);
$illustrationRepo->addIllustration($userGroup, $admin, $file);

@ -47,7 +47,7 @@ class Version20210221082033 extends AbstractMigrationChamilo
$lp = $lpRepo->find($id);
if ($lp && !empty($path)) {
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/learning_path/images/'.$path;
if (file_exists($rootPath) && !is_dir($filePath)) {
if ($this->fileExists($filePath)) {
$this->addLegacyFileToResource($filePath, $lpRepo, $lp, $lp->getIid(), $path);
$em->persist($lp);
$em->flush();

@ -47,7 +47,7 @@ class Version20210813150011 extends AbstractMigrationChamilo
}
$filePath = $rootPath.'/app/upload/badges/'.$icon;
if (file_exists($rootPath) && !is_dir($filePath)) {
if ($this->fileExists($filePath)) {
$mimeType = mime_content_type($filePath);
$fileName = basename($filePath);
$file = new UploadedFile($filePath, $fileName, $mimeType, null, true);

@ -15,6 +15,11 @@ services:
exclude: '../../{Repository,Component,DependencyInjection,EventListener,Form,Framework,Migrations,Settings,ChamiloCoreBundle.php,Entity}'
public: true
Doctrine\Migrations\Version\DbalMigrationFactory: ~
Chamilo\CoreBundle\Migrations\MigrationFactory:
decorates: Doctrine\Migrations\Version\DbalMigrationFactory
arguments: ['@Chamilo\CoreBundle\Migrations\MigrationFactory.inner', '@service_container']
Chamilo\CoreBundle\Controller\:
resource: '../../Controller'
tags: ['controller.service_arguments']

Loading…
Cancel
Save