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