From 69f2c46d980f695019c7144940baa4eea9c2ff0b Mon Sep 17 00:00:00 2001 From: christian Date: Thu, 22 Jun 2023 01:20:19 -0500 Subject: [PATCH] Learnpath: Rename table c_lp_category user - refs #3808 --- .../lp/lp_subscribe_users_to_category.php | 8 ++--- .../Schema/V200/Version20230622150000.php | 31 +++++++++++++++++++ src/CourseBundle/Entity/CLpCategory.php | 12 +++---- ...ategoryUser.php => CLpCategoryRelUser.php} | 6 ++-- .../Repository/CLpCategoryRepositoryTest.php | 4 +-- 5 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/CoreBundle/Migrations/Schema/V200/Version20230622150000.php rename src/CourseBundle/Entity/{CLpCategoryUser.php => CLpCategoryRelUser.php} (91%) diff --git a/public/main/lp/lp_subscribe_users_to_category.php b/public/main/lp/lp_subscribe_users_to_category.php index b90b9128b0..cd7424570a 100644 --- a/public/main/lp/lp_subscribe_users_to_category.php +++ b/public/main/lp/lp_subscribe_users_to_category.php @@ -5,7 +5,7 @@ use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Framework\Container; use Chamilo\CourseBundle\Entity\CLpCategory; -use Chamilo\CourseBundle\Entity\CLpCategoryUser; +use Chamilo\CourseBundle\Entity\CLpCategoryRelUser; use Doctrine\Common\Collections\Criteria; require_once __DIR__.'/../inc/global.inc.php'; @@ -183,7 +183,7 @@ if ($allowUserGroups) { foreach ($userList as $userId) { $user = api_get_user_entity($userId); if ($user) { - $categoryUser = new CLpCategoryUser(); + $categoryUser = new CLpCategoryRelUser(); $categoryUser->setUser($user); $category->addUser($categoryUser); } @@ -278,7 +278,7 @@ if ($form->validate()) { if (!empty($userForm)) { $deleteUsers = []; if ($subscribedUsersInCategory) { - /** @var CLpCategoryUser $user */ + /** @var CLpCategoryRelUser $user */ foreach ($subscribedUsersInCategory as $user) { $userId = $user->getUser()->getId(); @@ -289,7 +289,7 @@ if ($form->validate()) { } foreach ($users as $userId) { - $categoryUser = new CLpCategoryUser(); + $categoryUser = new CLpCategoryRelUser(); $user = UserManager::getRepository()->find($userId); if ($user) { $categoryUser->setUser($user); diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230622150000.php b/src/CoreBundle/Migrations/Schema/V200/Version20230622150000.php new file mode 100644 index 0000000000..19154b9ef4 --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20230622150000.php @@ -0,0 +1,31 @@ +hasTable('c_lp_category_user')) { + $this->addSql("ALTER TABLE c_lp_category_user RENAME TO c_lp_category_rel_user"); + } + } + + public function down(Schema $schema): void + { + if ($schema->hasTable('c_lp_category_rel_user')) { + $this->addSql("ALTER TABLE c_lp_category_rel_user RENAME TO c_lp_category_user"); + } + } +} diff --git a/src/CourseBundle/Entity/CLpCategory.php b/src/CourseBundle/Entity/CLpCategory.php index 15b2ed8a0e..fe02067d22 100644 --- a/src/CourseBundle/Entity/CLpCategory.php +++ b/src/CourseBundle/Entity/CLpCategory.php @@ -38,9 +38,9 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa protected int $position; /** - * @var Collection|CLpCategoryUser[] + * @var Collection|CLpCategoryRelUser[] */ - #[ORM\OneToMany(targetEntity: \Chamilo\CourseBundle\Entity\CLpCategoryUser::class, mappedBy: 'category', cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ORM\OneToMany(targetEntity: \Chamilo\CourseBundle\Entity\CLpCategoryRelUser::class, mappedBy: 'category', cascade: ['persist', 'remove'], orphanRemoval: true)] protected Collection $users; /** @@ -119,7 +119,7 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa } } - public function addUser(CLpCategoryUser $categoryUser): void + public function addUser(CLpCategoryRelUser $categoryUser): void { $categoryUser->setCategory($this); @@ -128,7 +128,7 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa } } - public function hasUser(CLpCategoryUser $categoryUser): bool + public function hasUser(CLpCategoryRelUser $categoryUser): bool { if (0 !== $this->getUsers()->count()) { $criteria = Criteria::create()->where( @@ -148,7 +148,7 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa public function hasUserAdded(User $user): bool { if (0 !== $this->getUsers()->count()) { - $categoryUser = new CLpCategoryUser(); + $categoryUser = new CLpCategoryRelUser(); $categoryUser->setCategory($this); $categoryUser->setUser($user); @@ -158,7 +158,7 @@ class CLpCategory extends AbstractResource implements ResourceInterface, Stringa return false; } - public function removeUsers(CLpCategoryUser $user): self + public function removeUsers(CLpCategoryRelUser $user): self { $this->users->removeElement($user); diff --git a/src/CourseBundle/Entity/CLpCategoryUser.php b/src/CourseBundle/Entity/CLpCategoryRelUser.php similarity index 91% rename from src/CourseBundle/Entity/CLpCategoryUser.php rename to src/CourseBundle/Entity/CLpCategoryRelUser.php index a420574157..fa7484b227 100644 --- a/src/CourseBundle/Entity/CLpCategoryUser.php +++ b/src/CourseBundle/Entity/CLpCategoryRelUser.php @@ -12,11 +12,11 @@ use Doctrine\ORM\Mapping as ORM; use Stringable; /** - * CLpCategoryUser. + * CLpCategoryRelUser. */ -#[ORM\Table(name: 'c_lp_category_user')] +#[ORM\Table(name: 'c_lp_category_rel_user')] #[ORM\Entity] -class CLpCategoryUser implements Stringable +class CLpCategoryRelUser implements Stringable { use UserTrait; diff --git a/tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php b/tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php index 1429420707..9b4c1d425a 100644 --- a/tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php +++ b/tests/CourseBundle/Repository/CLpCategoryRepositoryTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace Chamilo\Tests\CourseBundle\Repository; use Chamilo\CourseBundle\Entity\CLpCategory; -use Chamilo\CourseBundle\Entity\CLpCategoryUser; +use Chamilo\CourseBundle\Entity\CLpCategoryRelUser; use Chamilo\CourseBundle\Repository\CLpCategoryRepository; use Chamilo\Tests\AbstractApiTest; use Chamilo\Tests\ChamiloTestTrait; @@ -62,7 +62,7 @@ class CLpCategoryRepositoryTest extends AbstractApiTest $em->persist($category); $em->flush(); - $categoryRelUser = (new CLpCategoryUser()) + $categoryRelUser = (new CLpCategoryRelUser()) ->setCategory($category) ->setUser($teacher) ;