Internal: Migration: Fix migration for agenda reminders

pull/5339/head
Angel Fernando Quiroz Campos 1 year ago committed by GitHub
parent f77ed1a474
commit 539c443f88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 37
      src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php

@ -17,6 +17,7 @@ use Chamilo\CourseBundle\Repository\CCalendarEventRepository;
use Chamilo\Kernel;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\EntityManagerInterface;
final class Version20201215072918 extends AbstractMigrationChamilo
{
@ -27,22 +28,18 @@ final class Version20201215072918 extends AbstractMigrationChamilo
public function up(Schema $schema): void
{
$container = $this->getContainer();
$doctrine = $container->get('doctrine');
$em = $doctrine->getManager();
$em = $this->getEntityManager();
/** @var Connection $connection */
$connection = $em->getConnection();
$eventRepo = $container->get(CCalendarEventRepository::class);
$eventAttachmentRepo = $container->get(CCalendarEventAttachmentRepository::class);
$courseRepo = $container->get(CourseRepository::class);
$eventRepo = $this->container->get(CCalendarEventRepository::class);
$eventAttachmentRepo = $this->container->get(CCalendarEventAttachmentRepository::class);
$courseRepo = $this->container->get(CourseRepository::class);
/** @var Kernel $kernel */
$kernel = $container->get('kernel');
$kernel = $this->getContainer()->get('kernel');
$rootPath = $kernel->getProjectDir();
$admin = $this->getAdmin();
$oldNewEventIdMap = [];
$oldNewEventMap = [];
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
@ -104,8 +101,7 @@ final class Version20201215072918 extends AbstractMigrationChamilo
$em->persist($event);
$em->flush();
$newEventId = $event->getIid();
$oldNewEventIdMap[$oldEventId] = $newEventId;
$oldNewEventMap[$oldEventId] = $event;
}
$sql = "SELECT * FROM c_calendar_event_attachment WHERE c_id = {$courseId}
@ -144,17 +140,22 @@ final class Version20201215072918 extends AbstractMigrationChamilo
}
}
$this->updateAgendaReminders($oldNewEventIdMap, $em);
$this->updateAgendaReminders($oldNewEventMap, $em);
}
private function updateAgendaReminders($oldNewEventIdMap, $em): void
/**
* @param array<int, CCalendarEvent> $oldNewEventMap
*/
private function updateAgendaReminders(array $oldNewEventMap, EntityManagerInterface $em): void
{
$reminders = $em->getRepository(AgendaReminder::class)->findBy(['type' => 'course']);
/** @var AgendaReminder $reminder */
foreach ($reminders as $reminder) {
$oldEventId = $reminder->getEventId();
if (\array_key_exists($oldEventId, $oldNewEventIdMap)) {
$newEventId = $oldNewEventIdMap[$oldEventId];
$reminder->setEventId($newEventId);
$oldEventId = $reminder->getEvent()->getIid();
if (\array_key_exists($oldEventId, $oldNewEventMap)) {
$newEvent = $oldNewEventMap[$oldEventId];
$reminder->setEvent($newEvent);
$em->persist($reminder);
}
}

Loading…
Cancel
Save