Migrations: Add course picture migration

pull/3989/head
Julio 4 years ago
parent 6cd33dd8ab
commit 652a981eb0
  1. 2
      src/CoreBundle/Entity/Course.php
  2. 55
      src/CoreBundle/Migrations/Schema/V200/Version20210923090920.php
  3. 18
      tests/CoreBundle/Migrations/MigrationTest.php

@ -626,7 +626,7 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
}
/**
* Get directory.
* Get directory, needed in migrations.
*
* @return string
*/

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
use Chamilo\Kernel;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\HttpFoundation\File\UploadedFile;
final class Version20210923090920 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Course pictures';
}
public function up(Schema $schema): void
{
$em = $this->getEntityManager();
$container = $this->getContainer();
/** @var Kernel $kernel */
$kernel = $container->get('kernel');
$rootPath = $kernel->getProjectDir();
$illustrationRepo = $container->get(IllustrationRepository::class);
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
/** @var Course $course */
foreach ($q->toIterable() as $course) {
$directory = $course->getDirectory();
$picturePath = $rootPath.'/app/courses/'.$directory.'/course-pic.png';
$admin = $this->getAdmin();
if ($illustrationRepo->hasIllustration($course)) {
continue;
}
if ($this->fileExists($picturePath)) {
$mimeType = mime_content_type($picturePath);
$uploadFile = new UploadedFile($picturePath, 'course-pic', $mimeType, null, true);
$illustrationRepo->addIllustration(
$course,
$admin,
$uploadFile
);
}
}
}
}

@ -15,7 +15,7 @@ class MigrationTest extends KernelTestCase
{
use ChamiloTestTrait;
public function testMigrations(): void
public function testMigrationsStatus(): void
{
$kernel = static::createKernel();
$application = new Application($kernel);
@ -30,4 +30,20 @@ class MigrationTest extends KernelTestCase
$output = $commandTester->getDisplay();
$this->assertStringContainsString('Chamilo\CoreBundle\Migrations\Schema\V200', $output);
}
public function testMigrationsList(): void
{
$kernel = static::createKernel();
$application = new Application($kernel);
$command = $application->find('doctrine:migrations:list');
$commandTester = new CommandTester($command);
$commandTester->execute([
// pass arguments to the helper
'--no-interaction',
]);
$output = $commandTester->getDisplay();
$this->assertStringContainsString('Chamilo\CoreBundle\Migrations\Schema\V200', $output);
}
}

Loading…
Cancel
Save