Internal: Allow to set default resource type when migrating c_item_property to resource node with links - refs BT#22193

pull/5922/head
Angel Fernando Quiroz Campos 2 weeks ago
parent 6580e559e8
commit e375c5e57b
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 9
      src/CoreBundle/Migrations/AbstractMigrationChamilo.php
  2. 27
      src/CoreBundle/Repository/ResourceRepository.php

@ -259,6 +259,8 @@ abstract class AbstractMigrationChamilo extends AbstractMigration
$groupRepo = $this->container->get(CGroupRepository::class); $groupRepo = $this->container->get(CGroupRepository::class);
$userRepo = $this->container->get(UserRepository::class); $userRepo = $this->container->get(UserRepository::class);
$resourceType = $repo->getResourceType();
$resource->setParent($parentResource); $resource->setParent($parentResource);
$resourceNode = null; $resourceNode = null;
$userList = []; $userList = [];
@ -325,7 +327,12 @@ abstract class AbstractMigrationChamilo extends AbstractMigration
} }
if (null === $resourceNode) { if (null === $resourceNode) {
$resourceNode = $repo->addResourceNode($resource, $user, $parentResource); $resourceNode = $repo->addResourceNode(
$resource,
$user,
$parentResource,
$resourceType
);
$this->entityManager->persist($resourceNode); $this->entityManager->persist($resourceNode);
} }
$resource->addCourseLink($course, $session, $group, $newVisibility); $resource->addCourseLink($course, $session, $group, $newVisibility);

@ -615,21 +615,36 @@ abstract class ResourceRepository extends ServiceEntityRepository
$this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PENDING); $this->setLinkVisibility($resource, ResourceLink::VISIBILITY_PENDING);
} }
public function addResourceNode(ResourceInterface $resource, User $creator, ResourceInterface $parentResource): ResourceNode public function addResourceNode(
{ ResourceInterface $resource,
User $creator,
ResourceInterface $parentResource,
?ResourceType $resourceType = null,
): ResourceNode {
$parentResourceNode = $parentResource->getResourceNode(); $parentResourceNode = $parentResource->getResourceNode();
return $this->createNodeForResource($resource, $creator, $parentResourceNode); return $this->createNodeForResource(
$resource,
$creator,
$parentResourceNode,
null,
$resourceType,
);
} }
/** /**
* @todo remove this function and merge it with addResourceNode() * @todo remove this function and merge it with addResourceNode()
*/ */
public function createNodeForResource(ResourceInterface $resource, User $creator, ResourceNode $parentNode, ?UploadedFile $file = null): ResourceNode public function createNodeForResource(
{ ResourceInterface $resource,
User $creator,
ResourceNode $parentNode,
?UploadedFile $file = null,
?ResourceType $resourceType = null,
): ResourceNode {
$em = $this->getEntityManager(); $em = $this->getEntityManager();
$resourceType = $this->getResourceType(); $resourceType = $resourceType ?: $this->getResourceType();
$resourceName = $resource->getResourceName(); $resourceName = $resource->getResourceName();
$extension = $this->slugify->slugify(pathinfo($resourceName, PATHINFO_EXTENSION)); $extension = $this->slugify->slugify(pathinfo($resourceName, PATHINFO_EXTENSION));

Loading…
Cancel
Save