diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php b/src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php new file mode 100644 index 0000000000..18d69f0f40 --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php @@ -0,0 +1,85 @@ +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(); + } + } +} diff --git a/src/CourseBundle/Entity/CWiki.php b/src/CourseBundle/Entity/CWiki.php index 1b9081d2ee..0841de69db 100644 --- a/src/CourseBundle/Entity/CWiki.php +++ b/src/CourseBundle/Entity/CWiki.php @@ -4,6 +4,8 @@ namespace Chamilo\CourseBundle\Entity; +use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\ResourceInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; @@ -23,7 +25,7 @@ use Symfony\Component\Validator\Constraints as Assert; * ) * @ORM\Entity */ -class CWiki +class CWiki extends AbstractResource implements ResourceInterface { /** * @var int @@ -218,6 +220,11 @@ class CWiki */ protected $sessionId; + public function getIid(): int + { + return $this->iid; + } + /** * Set pageId. * @@ -841,4 +848,24 @@ class CWiki { return $this->cId; } + + public function __toString(): string + { + return $this->getTitle(); + } + + public function getResourceIdentifier(): int + { + return $this->getIid(); + } + + public function getResourceName(): string + { + return $this->getTitle(); + } + + public function setResourceName(string $name): self + { + return $this->setTitle($name); + } } diff --git a/src/CourseBundle/Repository/CWikiRepository.php b/src/CourseBundle/Repository/CWikiRepository.php new file mode 100644 index 0000000000..3090168d24 --- /dev/null +++ b/src/CourseBundle/Repository/CWikiRepository.php @@ -0,0 +1,17 @@ +