src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php
<?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\CourseRepository;
use Chamilo\CourseBundle\Entity\CWiki;
use Chamilo\CourseBundle\Repository\CWikiRepository;
use Doctrine\DBAL\Schema\Schema;
final class Version20201219115244 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Migrate c_wiki';
}
public function up(Schema $schema): void
{
$wikiRepo = $this->container->get(CWikiRepository::class);
$courseRepo = $this->container->get(CourseRepository::class);
$admin = $this->getAdmin();
$q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
/** @var Course $course */
foreach ($q->toIterable() as $course) {
$courseId = $course->getId();
$course = $courseRepo->find($courseId);
$sql = "SELECT * FROM c_wiki WHERE c_id = {$courseId} ORDER BY iid";
$result = $this->connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
foreach ($items as $itemData) {
$id = $itemData['iid'];
/** @var CWiki $resource */
$resource = $wikiRepo->find($id);
if ($resource->hasResourceNode()) {
continue;
}
$result = $this->fixItemProperty(
'wiki',
$wikiRepo,
$course,
$admin,
$resource,
$course
);
if (false === $result) {
continue;
}
$this->entityManager->persist($resource);
$this->entityManager->flush();
}
$this->entityManager->flush();
$this->entityManager->clear();
}
}
}