|
|
|
@ -4,10 +4,14 @@ declare(strict_types=1); |
|
|
|
|
|
|
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Entity\AccessUrl; |
|
|
|
|
use Chamilo\CoreBundle\Entity\AccessUrlRelUserGroup; |
|
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
|
|
|
use Chamilo\CoreBundle\Entity\Usergroup; |
|
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
|
|
|
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository; |
|
|
|
|
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository; |
|
|
|
|
use Chamilo\CoreBundle\Repository\Node\UsergroupRepository; |
|
|
|
|
use Doctrine\DBAL\Connection; |
|
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
|
|
|
@ -22,8 +26,7 @@ final class Version20210205082253 extends AbstractMigrationChamilo |
|
|
|
|
public function up(Schema $schema): void |
|
|
|
|
{ |
|
|
|
|
$container = $this->getContainer(); |
|
|
|
|
$doctrine = $container->get('doctrine'); |
|
|
|
|
$em = $doctrine->getManager(); |
|
|
|
|
$em = $this->getEntityManager(); |
|
|
|
|
/** @var Connection $connection */ |
|
|
|
|
$connection = $em->getConnection(); |
|
|
|
|
|
|
|
|
@ -72,21 +75,51 @@ final class Version20210205082253 extends AbstractMigrationChamilo |
|
|
|
|
$em->flush(); |
|
|
|
|
$em->clear(); |
|
|
|
|
|
|
|
|
|
// Migrate Usergroup images. |
|
|
|
|
// Migrate Usergroup. |
|
|
|
|
$counter = 1; |
|
|
|
|
$q = $em->createQuery('SELECT u FROM Chamilo\CoreBundle\Entity\Usergroup u'); |
|
|
|
|
$admin = $this->getAdmin(); |
|
|
|
|
|
|
|
|
|
$userGroupRepo = $container->get(UsergroupRepository::class); |
|
|
|
|
$urlRepo = $container->get(AccessUrlRepository::class); |
|
|
|
|
$urlList = $urlRepo->findAll(); |
|
|
|
|
/** @var AccessUrl $url */ |
|
|
|
|
$url = $urlList[0]; |
|
|
|
|
|
|
|
|
|
/** @var Usergroup $userGroup */ |
|
|
|
|
foreach ($q->toIterable() as $userGroup) { |
|
|
|
|
if ($userGroup->hasResourceNode()) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$id = $userGroup->getId(); |
|
|
|
|
|
|
|
|
|
$userGroup->setCreator($admin); |
|
|
|
|
|
|
|
|
|
if (0 === $userGroup->getUrls()->count()) { |
|
|
|
|
$accessUrlRelUserGroup = (new AccessUrlRelUserGroup()) |
|
|
|
|
->setUserGroup($userGroup) |
|
|
|
|
->setUrl($url) |
|
|
|
|
; |
|
|
|
|
$userGroup->getUrls()->add($accessUrlRelUserGroup); |
|
|
|
|
} |
|
|
|
|
$userGroupRepo->addResourceNode($userGroup, $admin, $url); |
|
|
|
|
$em->persist($userGroup); |
|
|
|
|
$em->flush(); |
|
|
|
|
} |
|
|
|
|
$em->clear(); |
|
|
|
|
|
|
|
|
|
// Migrate Usergroup images. |
|
|
|
|
$q = $em->createQuery('SELECT u FROM Chamilo\CoreBundle\Entity\Usergroup u'); |
|
|
|
|
/** @var Usergroup $userGroup */ |
|
|
|
|
foreach ($q->toIterable() as $userGroup) { |
|
|
|
|
if (!$userGroup->hasResourceNode()) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$picture = $userGroup->getPicture(); |
|
|
|
|
if (empty($picture)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$id = $userGroup->getId(); |
|
|
|
|
$path = "groups/{$id}/"; |
|
|
|
|
if (!empty($setting) && 'true' === $setting['selected_value']) { |
|
|
|
|
$path = 'groups/'.substr((string) $id, 0, 1).'/'.$id.'/'; |
|
|
|
|