Internal: Refactoring method to get the admin user in migrations

ofaj2
Angel Fernando Quiroz Campos 2 years ago
parent 8a5f31ceac
commit 7516e6624b
  1. 8
      .env.test
  2. 16
      src/CoreBundle/Migrations/AbstractMigrationChamilo.php

@ -5,14 +5,14 @@ SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
DATABASE_HOST='127.0.0.1'
DATABASE_HOST='database'
DATABASE_PORT='3306'
DATABASE_NAME='chamilo_test'
DATABASE_NAME='chamilo2'
DATABASE_USER='root'
DATABASE_PASSWORD='root'
DATABASE_PASSWORD='afqc'
APP_INSTALLED='1'
APP_ENV='test'
APP_DEBUG='1'
APP_LOCALE='en_US'
APP_MULTIPLE_ACCESS_URL=''
APP_MULTIPLE_ACCESS_URL=''

@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\Migrations;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\Admin;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\SettingsCurrent;
@ -66,17 +67,12 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con
public function getAdmin(): User
{
$container = $this->getContainer();
$em = $this->getEntityManager();
$connection = $em->getConnection();
$userRepo = $container->get(UserRepository::class);
$sql = 'SELECT user_id FROM admin ORDER BY id LIMIT 1';
$result = $connection->executeQuery($sql);
$adminRow = $result->fetchAssociative();
$adminId = $adminRow['user_id'];
$admin = $this->getEntityManager()
->getRepository(Admin::class)
->findOneBy([], ['id' => 'ASC'])
;
return $userRepo->find($adminId);
return $admin->getUser();
}
/**

Loading…
Cancel
Save