Migrations: Add wiki as resource + add simple migration

pull/3733/head
Julio Montoya 4 years ago
parent da7d374383
commit 1fc421a4b4
  1. 85
      src/CoreBundle/Migrations/Schema/V200/Version20201219115244.php
  2. 29
      src/CourseBundle/Entity/CWiki.php
  3. 17
      src/CourseBundle/Repository/CWikiRepository.php

@ -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();
}
}
}

@ -4,6 +4,8 @@
namespace Chamilo\CourseBundle\Entity; namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
@ -23,7 +25,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* ) * )
* @ORM\Entity * @ORM\Entity
*/ */
class CWiki class CWiki extends AbstractResource implements ResourceInterface
{ {
/** /**
* @var int * @var int
@ -218,6 +220,11 @@ class CWiki
*/ */
protected $sessionId; protected $sessionId;
public function getIid(): int
{
return $this->iid;
}
/** /**
* Set pageId. * Set pageId.
* *
@ -841,4 +848,24 @@ class CWiki
{ {
return $this->cId; 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);
}
} }

@ -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…
Cancel
Save