parent
da7d374383
commit
1fc421a4b4
@ -0,0 +1,85 @@ |
||||
<?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\CoreBundle\Repository\Node\CourseRepository; |
||||
use Chamilo\CoreBundle\Repository\Node\UserRepository; |
||||
use Chamilo\CoreBundle\Repository\SessionRepository; |
||||
use Chamilo\CourseBundle\Entity\CBlog; |
||||
use Chamilo\CourseBundle\Entity\CWiki; |
||||
use Chamilo\CourseBundle\Repository\CGroupRepository; |
||||
use Chamilo\CourseBundle\Repository\CSurveyRepository; |
||||
use Chamilo\CourseBundle\Repository\CWikiRepository; |
||||
use Chamilo\Kernel; |
||||
use Doctrine\DBAL\Connection; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
final class Version20201219115244 extends AbstractMigrationChamilo |
||||
{ |
||||
public function getDescription(): string |
||||
{ |
||||
return 'Migrate c_wiki'; |
||||
} |
||||
|
||||
public function up(Schema $schema): void |
||||
{ |
||||
$container = $this->getContainer(); |
||||
$doctrine = $container->get('doctrine'); |
||||
$em = $doctrine->getManager(); |
||||
/** @var Connection $connection */ |
||||
$connection = $em->getConnection(); |
||||
|
||||
$wikiRepo = $container->get(CWikiRepository::class); |
||||
$courseRepo = $container->get(CourseRepository::class); |
||||
$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 */ |
||||
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 = $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; |
||||
} |
||||
|
||||
$em->persist($resource); |
||||
$em->flush(); |
||||
} |
||||
|
||||
$em->flush(); |
||||
$em->clear(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CourseBundle\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Repository\ResourceRepository; |
||||
use Chamilo\CourseBundle\Entity\CWiki; |
||||
use Doctrine\Persistence\ManagerRegistry; |
||||
|
||||
final class CWikiRepository extends ResourceRepository |
||||
{ |
||||
public function __construct(ManagerRegistry $registry) |
||||
{ |
||||
parent::__construct($registry, CWiki::class); |
||||
} |
||||
} |
Loading…
Reference in new issue