Add Fixtures to use in phpunit and during installation

pull/3904/head
Julio Montoya 4 years ago
parent 8ec4d81196
commit da9d92b297
  1. 10
      public/main/install/index.php
  2. 251
      public/main/install/install.lib.php
  3. 30
      src/CoreBundle/DataFixtures/AccessGroupFixtures.php
  4. 9
      src/CoreBundle/DataFixtures/AccessUserFixtures.php
  5. 8
      src/CoreBundle/DataFixtures/AccessUserUrlFixtures.php
  6. 2
      src/CoreBundle/DataFixtures/BranchFixtures.php
  7. 2
      src/CoreBundle/DataFixtures/CourseCategoryFixtures.php
  8. 79
      src/CoreBundle/DataFixtures/GroupFixtures.php
  9. 381
      src/CoreBundle/DataFixtures/LanguageFixtures.php
  10. 311
      src/CoreBundle/DataFixtures/SequenceFixtures.php
  11. 1
      src/CoreBundle/DataFixtures/SystemTemplateFixtures.php
  12. 21
      src/CoreBundle/DataFixtures/TicketFixtures.php
  13. 1
      src/CoreBundle/Entity/User.php
  14. 72
      src/CoreBundle/Repository/GroupRepository.php

@ -367,7 +367,7 @@ if (isset($_POST['step2'])) {
$form .= ob_get_contents();
ob_end_clean();
} elseif (isset($_POST['step4'])) {
//STEP 5 : CONFIGURATION SETTINGS
// STEP 5 : CONFIGURATION SETTINGS
if ('update' === $installType) {
$db_name = $dbNameForm;
$database = connectToDatabase(
@ -637,6 +637,7 @@ if (isset($_POST['step2'])) {
Container::setLegacyServices($container, false);
$manager = $container->get('doctrine')->getManager();
migrateSwitch($my_old_version, $manager);
upgradeWithContainer($container);
error_log('Set upgradeWithContainer');
@ -703,7 +704,12 @@ if (isset($_POST['step2'])) {
$result = $command->run($input, new ConsoleOutput());
// No errors
if (0 == $result) {
if (0 === $result) {
$input = new ArrayInput([]);
$input->setInteractive(false);
$command = $application->find('doctrine:fixtures:load');
$result = $command->run($input, new ConsoleOutput());
error_log('Delete PHP Session');
session_unset();
$_SESSION = [];

@ -10,6 +10,7 @@ use Chamilo\CoreBundle\Entity\TicketPriority;
use Chamilo\CoreBundle\Entity\TicketProject;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CoreBundle\Repository\GroupRepository;
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\ToolChain;
@ -2210,73 +2211,6 @@ function updateEnvFile($distFile, $envFile, $params)
error_log("File env saved here: $envFile");
}
/**
* @param EntityManager $manager
*/
function installGroups($manager)
{
error_log('installGroups');
// Creating fos_group (groups and roles)
$groups = [
[
'code' => 'ADMIN',
'title' => 'Administrators',
'roles' => ['ROLE_ADMIN'],
],
[
'code' => 'STUDENT',
'title' => 'Students',
'roles' => ['ROLE_STUDENT'],
],
[
'code' => 'TEACHER',
'title' => 'Teachers',
'roles' => ['ROLE_TEACHER'],
],
[
'code' => 'RRHH',
'title' => 'Human resources manager',
'roles' => ['ROLE_RRHH'],
],
[
'code' => 'SESSION_MANAGER',
'title' => 'Session',
'roles' => ['ROLE_SESSION_MANAGER'],
],
[
'code' => 'QUESTION_MANAGER',
'title' => 'Question manager',
'roles' => ['ROLE_QUESTION_MANAGER'],
],
[
'code' => 'STUDENT_BOSS',
'title' => 'Student boss',
'roles' => ['ROLE_STUDENT_BOSS'],
],
[
'code' => 'INVITEE',
'title' => 'Invitee',
'roles' => ['ROLE_INVITEE'],
],
];
$repo = $manager->getRepository('ChamiloCoreBundle:Group');
foreach ($groups as $groupData) {
$criteria = ['code' => $groupData['code']];
$groupExists = $repo->findOneBy($criteria);
if (!$groupExists) {
$group = new Group($groupData['title']);
$group
->setCode($groupData['code']);
foreach ($groupData['roles'] as $role) {
$group->addRole($role);
}
$manager->persist($group);
}
}
$manager->flush();
}
function installTools($container, $manager, $upgrade = false)
{
error_log('installTools');
@ -2333,7 +2267,11 @@ function upgradeWithContainer($container)
Container::setLegacyServices($container, false);
error_log('setLegacyServices');
$manager = Database::getManager();
installGroups($manager);
/** @var GroupRepository $repo */
$repo = $container->get(GroupRepository::class);
$repo->createDefaultGroups();
// @todo check if adminId = 1
installTools($container, $manager, true);
installSchemas($container, true);
@ -2379,114 +2317,20 @@ function finishInstallationWithContainer(
$installationProfile = ''
) {
error_log('finishInstallationWithContainer');
$sysPath = !empty($sysPath) ? $sysPath : api_get_path(SYMFONY_SYS_PATH);
Container::setContainer($container);
Container::setLegacyServices($container, false);
error_log('setLegacyServices');
$manager = Database::getManager();
$trans = $container->get('translator');
// Add tickets defaults
$ticketProject = new TicketProject();
$ticketProject
->setName('Ticket System')
->setInsertUserId(1);
$manager->persist($ticketProject);
$categories = [
$trans->trans('Enrollment') => $trans->trans('Tickets about enrollment'),
$trans->trans('General information') => $trans->trans('Tickets about general information'),
$trans->trans('Requests and paperwork') => $trans->trans('Tickets about requests and paperwork'),
$trans->trans('Academic Incidents') => $trans->trans('Tickets about academic incidents, like exams, practices, tasks, etc.'),
$trans->trans('Virtual campus') => $trans->trans('Tickets about virtual campus'),
$trans->trans('Online evaluation') => $trans->trans('Tickets about online evaluation'),
];
$i = 1;
foreach ($categories as $category => $description) {
// Online evaluation requires a course
$ticketCategory = new TicketCategory();
$ticketCategory
->setName($category)
->setDescription($description)
->setProject($ticketProject)
->setInsertUserId(1);
$isRequired = 6 == $i;
$ticketCategory->setCourseRequired($isRequired);
$manager->persist($ticketCategory);
$i++;
}
// Default Priorities
$defaultPriorities = [
TicketManager::PRIORITY_NORMAL => $trans->trans('Normal'),
TicketManager::PRIORITY_HIGH => $trans->trans('High'),
TicketManager::PRIORITY_LOW => $trans->trans('Low'),
];
$i = 1;
foreach ($defaultPriorities as $code => $priority) {
$ticketPriority = new TicketPriority();
$ticketPriority
->setName($priority)
->setCode($code)
->setInsertUserId(1);
$manager->persist($ticketPriority);
$i++;
}
error_log('Save ticket data');
$manager->flush();
$table = Database::get_main_table(TABLE_TICKET_STATUS);
// Default status
$defaultStatus = [
TicketManager::STATUS_NEW => $trans->trans('New'),
TicketManager::STATUS_PENDING => $trans->trans('Pending'),
TicketManager::STATUS_UNCONFIRMED => $trans->trans('Unconfirmed'),
TicketManager::STATUS_CLOSE => $trans->trans('Close'),
TicketManager::STATUS_FORWARDED => $trans->trans('Forwarded'),
];
$i = 1;
foreach ($defaultStatus as $code => $status) {
$attributes = [
'id' => $i,
'code' => $code,
'name' => $status,
];
Database::insert($table, $attributes);
$i++;
}
installGroups($manager);
error_log('Inserting data.sql');
// Inserting default data
$data = file_get_contents($sysPath.'public/main/install/data.sql');
$result = $manager->getConnection()->prepare($data);
$executeResult = $result->executeQuery();
if ($executeResult) {
error_log('data.sql Ok');
}
$result->free();
UserManager::setPasswordEncryption($encryptPassForm);
//UserManager::setPasswordEncryption($encryptPassForm);
$timezone = api_get_timezone();
error_log('user creation - admin');
$now = new DateTime();
// Creating admin user.
$admin = new User();
$repo = Container::getUserRepository();
/** @var User $admin */
$admin = $repo->findOneBy(['username' => 'admin']);
$admin
->setSkipResourceNode(true)
->setLastname($adminFirstName)
->setFirstname($adminLastName)
->setUsername($loginForm)
@ -2494,84 +2338,16 @@ function finishInstallationWithContainer(
->setPlainPassword($passForm)
->setEmail($emailForm)
->setOfficialCode('ADMIN')
->setCreatorId(1)
->setAuthSource(PLATFORM_AUTH_SOURCE)
->setPhone($adminPhoneForm)
->setLocale($languageForm)
->setRegistrationDate($now)
->setActive(1)
->setEnabled(1)
->setTimezone($timezone)
;
$repo = Container::getUserRepository();
$repo->updateUser($admin);
UserManager::addUserAsAdmin($admin);
$adminId = $admin->getId();
error_log('user creation - anon');
$anon = new User();
$anon
->setSkipResourceNode(true)
->setLastname('Joe')
->setFirstname('Anonymous')
->setUsername('anon')
->setStatus(ANONYMOUS)
->setPlainPassword('anon')
->setEmail('anonymous@localhost')
->setOfficialCode('anonymous')
->setCreatorId(1)
->setAuthSource(PLATFORM_AUTH_SOURCE)
->setLocale($languageForm)
->setRegistrationDate($now)
->setActive(1)
->setEnabled(1)
->setTimezone($timezone)
;
$repo->updateUser($anon);
$anonId = $anon->getId();
$userRepo = $container->get(UserRepository::class);
$urlRepo = $container->get(AccessUrlRepository::class);
installTools($container, $manager, false);
/** @var User $admin */
$admin = $userRepo->find($adminId);
$admin->addRole('ROLE_GLOBAL_ADMIN');
$manager->persist($admin);
// Login as admin
$token = new UsernamePasswordToken(
$admin,
$admin->getPassword(),
'public',
$admin->getRoles()
);
$container->get('security.token_storage')->setToken($token);
$userRepo->addUserToResourceNode($adminId, $adminId);
$userRepo->addUserToResourceNode($anonId, $adminId);
$manager->persist($anon);
$manager->flush();
installSchemas($container);
$accessUrl = $urlRepo->find(1);
UrlManager::add_user_to_url($adminId, $adminId);
UrlManager::add_user_to_url($anonId, $adminId);
$branch = new BranchSync();
$branch->setBranchName('localhost');
$branch->setUrl($accessUrl);
$manager->persist($branch);
$manager->flush();
$repo = Container::getUserRepository();
$repo->updateUser($admin);
// Set default language
Database::update(
@ -2593,7 +2369,6 @@ function finishInstallationWithContainer(
$allowSelfRegProf,
$installationProfile
);
lockSettings();
updateDirAndFilesPermissions();
}

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\DataFixtures;
use Chamilo\CoreBundle\Repository\GroupRepository;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AccessGroupFixtures extends Fixture implements ContainerAwareInterface
{
private ContainerInterface $container;
public function setContainer(ContainerInterface $container = null): void
{
$this->container = $container;
}
public function load(ObjectManager $manager): void
{
/** @var GroupRepository $repo */
$repo = $this->container->get(GroupRepository::class);
$repo->createDefaultGroups($this);
}
}

@ -14,12 +14,11 @@ use Doctrine\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AccessUrlAdminFixtures extends Fixture implements ContainerAwareInterface
class AccessUserFixtures extends Fixture implements ContainerAwareInterface
{
public const ADMIN_USER_REFERENCE = 'admin';
public const ANON_USER_REFERENCE = 'anon';
public const ACCESS_URL_REFERENCE = 'accessUrl';
private ContainerInterface $container;
public function setContainer(ContainerInterface $container = null): void
@ -30,12 +29,13 @@ class AccessUrlAdminFixtures extends Fixture implements ContainerAwareInterface
public function load(ObjectManager $manager): void
{
$timezone = 'Europe\Paris';
$container = $this->container;
$toolChain = $container->get(ToolChain::class);
$toolChain->createTools();
// Defined in AccessGroupFixtures.php.
$group = $this->getReference('GROUP_ADMIN');
$admin = (new User())
->setSkipResourceNode(true)
->setLastname('Doe')
@ -50,6 +50,7 @@ class AccessUrlAdminFixtures extends Fixture implements ContainerAwareInterface
->setTimezone($timezone)
->addUserAsAdmin()
->addRole('ROLE_GLOBAL_ADMIN')
->addGroup($group)
;
$manager->persist($admin);

@ -14,7 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
class AccessUrlFixtures extends Fixture implements ContainerAwareInterface
class AccessUserUrlFixtures extends Fixture implements ContainerAwareInterface
{
private ContainerInterface $container;
@ -27,8 +27,8 @@ class AccessUrlFixtures extends Fixture implements ContainerAwareInterface
{
$container = $this->container;
/** @var User $admin */
$admin = $this->getReference(AccessUrlAdminFixtures::ADMIN_USER_REFERENCE);
$anon = $this->getReference(AccessUrlAdminFixtures::ANON_USER_REFERENCE);
$admin = $this->getReference(AccessUserFixtures::ADMIN_USER_REFERENCE);
$anon = $this->getReference(AccessUserFixtures::ANON_USER_REFERENCE);
// Login as admin
$token = new UsernamePasswordToken(
@ -58,7 +58,7 @@ class AccessUrlFixtures extends Fixture implements ContainerAwareInterface
$accessUrl->addUser($anon);
$manager->flush();
$this->addReference(AccessUrlAdminFixtures::ACCESS_URL_REFERENCE, $accessUrl);
$this->addReference(AccessUserFixtures::ACCESS_URL_REFERENCE, $accessUrl);
$settingsManager = $container->get('chamilo.settings.manager');
$settingsManager->installSchemas($accessUrl);

@ -19,7 +19,7 @@ class BranchFixtures extends Fixture
// INSERT INTO branch_sync (access_url_id, branch_name, unique_id, ssl_pub_key)
// VALUES (1, 'localhost', SHA1(UUID()), SHA1(UUID()));
$url = $this->getReference(AccessUrlAdminFixtures::ACCESS_URL_REFERENCE);
$url = $this->getReference(AccessUserFixtures::ACCESS_URL_REFERENCE);
$branch = (new BranchSync())
->setBranchName('localhost')

@ -29,7 +29,7 @@ class CourseCategoryFixtures extends Fixture
],
];
$url = $this->getReference(AccessUrlAdminFixtures::ACCESS_URL_REFERENCE);
$url = $this->getReference(AccessUserFixtures::ACCESS_URL_REFERENCE);
foreach ($list as $key => $data) {
$courseCategory = (new CourseCategory())

@ -1,79 +0,0 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\DataFixtures;
use Chamilo\CoreBundle\Entity\Group;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class GroupFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
$groups = [
[
'code' => 'ADMIN',
'title' => 'Administrators',
'roles' => ['ROLE_ADMIN'],
],
[
'code' => 'STUDENT',
'title' => 'Students',
'roles' => ['ROLE_STUDENT'],
],
[
'code' => 'TEACHER',
'title' => 'Teachers',
'roles' => ['ROLE_TEACHER'],
],
[
'code' => 'RRHH',
'title' => 'Human resources manager',
'roles' => ['ROLE_RRHH'],
],
[
'code' => 'SESSION_MANAGER',
'title' => 'Session',
'roles' => ['ROLE_SESSION_MANAGER'],
],
[
'code' => 'QUESTION_MANAGER',
'title' => 'Question manager',
'roles' => ['ROLE_QUESTION_MANAGER'],
],
[
'code' => 'STUDENT_BOSS',
'title' => 'Student boss',
'roles' => ['ROLE_STUDENT_BOSS'],
],
[
'code' => 'INVITEE',
'title' => 'Invitee',
'roles' => ['ROLE_INVITEE'],
],
];
$repo = $manager->getRepository(Group::class);
foreach ($groups as $groupData) {
$criteria = [
'code' => $groupData['code'],
];
$groupExists = $repo->findOneBy($criteria);
if (!$groupExists) {
$group = new Group($groupData['title']);
$group
->setCode($groupData['code'])
;
foreach ($groupData['roles'] as $role) {
$group->addRole($role);
}
$manager->persist($group);
}
}
$manager->flush();
}
}

@ -14,32 +14,385 @@ class LanguageFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
/*$list = [
$list = [
[
'name' => 'Language skills',
'code' => 'LANG',
'original_name' => 'العربية',
'english_name' => 'arabic',
'isocode' => 'ar',
'available' => 0,
],
[
'name' => 'PC Skills',
'code' => 'PC',
'original_name' => 'Asturianu',
'english_name' => 'asturian',
'isocode' => 'ast_ES',
'available' => 0,
],
[
'name' => 'Projects',
'code' => 'PROJ',
'original_name' => 'Euskara',
'english_name' => 'basque',
'isocode' => 'eu_ES',
'available' => 1,
],
[
'original_name' => 'ব',
'english_name' => 'bengali',
'isocode' => 'bn_BD',
'available' => 0,
],
[
'original_name' => 'Bosanski',
'english_name' => 'bosnian',
'isocode' => 'bs_BA',
'available' => 1,
],
[
'original_name' => 'Português do Brasil',
'english_name' => 'brazilian',
'isocode' => 'pt_PT',
'available' => 1,
],
[
'original_name' => 'Български',
'english_name' => 'bulgarian',
'isocode' => 'bg',
'available' => 1,
],
[
'original_name' => 'Català',
'english_name' => 'catalan',
'isocode' => 'ca_ES',
'available' => 0,
],
[
'original_name' => 'Hrvatski',
'english_name' => 'croatian',
'isocode' => 'hr_HR',
'available' => 0,
],
[
'original_name' => 'Česky',
'english_name' => 'czech',
'isocode' => 'cs_CZ',
'available' => 0,
],
[
'original_name' => 'Dansk',
'english_name' => 'danish',
'isocode' => 'da',
'available' => 0,
],
[
'original_name' => 'دری',
'english_name' => 'dari',
'isocode' => 'fa_AF',
'available' => 0,
],
[
'original_name' => 'Nederlands',
'english_name' => 'dutch',
'isocode' => 'nl',
'available' => 1,
],
[
'original_name' => 'English',
'english_name' => 'english',
'isocode' => 'en_US',
'available' => 1,
],
/*[
'original_name' => 'Estonian',
'english_name' => 'estonian',
'isocode' => 'ety',
'available' => 0,
],*/
[
'original_name' => 'Esperanto',
'english_name' => 'esperanto',
'isocode' => 'eo',
'available' => 0,
],
[
'original_name' => 'Føroyskt',
'english_name' => 'faroese',
'isocode' => 'fo_FO',
'available' => 0,
],
[
'original_name' => 'Suomi',
'english_name' => 'finnish',
'isocode' => 'fi_FI',
'available' => 0,
],
[
'original_name' => 'Français',
'english_name' => 'french',
'isocode' => 'fr_FR',
'available' => 1,
],
[
'original_name' => 'Furlan',
'english_name' => 'friulian',
'isocode' => 'fur',
'available' => 0,
],
[
'original_name' => 'Galego',
'english_name' => 'galician',
'isocode' => 'gl',
'available' => 0,
],
[
'original_name' => 'ქართული',
'english_name' => 'georgian',
'isocode' => 'ka_GE',
'available' => 0,
],
[
'original_name' => 'Deutsch',
'english_name' => 'german',
'isocode' => 'de',
'available' => 1,
],
[
'original_name' => 'Ελληνικά',
'english_name' => 'greek',
'isocode' => 'el',
'available' => 1,
],
[
'original_name' => 'עברית',
'english_name' => 'hebrew',
'isocode' => 'he_IL',
'available' => 1,
],
[
'original_name' => 'हि',
'english_name' => 'hindi',
'isocode' => 'hi',
'available' => 0,
],
[
'original_name' => 'Magyar',
'english_name' => 'hungarian',
'isocode' => 'hu_HU',
'available' => 1,
],
[
'original_name' => 'Bahasa Indonesia',
'english_name' => 'indonesian',
'isocode' => 'id_ID',
'available' => 0,
],
[
'original_name' => 'Italiano',
'english_name' => 'italian',
'isocode' => 'it',
'available' => 1,
],
[
'original_name' => '日本語',
'english_name' => 'japanese',
'isocode' => 'ja',
'available' => 0,
],
[
'original_name' => '한국어',
'english_name' => 'korean',
'isocode' => 'ko_KR',
'available' => 0,
],
[
'original_name' => 'Latviešu',
'english_name' => 'latvian',
'isocode' => 'lv_LV',
'available' => 0,
],
[
'original_name' => 'Lietuvių',
'english_name' => 'lithuanian',
'isocode' => 'lt_LT',
'available' => 0,
],
[
'original_name' => 'Македонски',
'english_name' => 'macedonian',
'isocode' => 'mk_MK',
'available' => 0,
],
[
'original_name' => 'Bahasa Melayu',
'english_name' => 'malay',
'isocode' => 'ms_MY',
'available' => 0,
],
[
'original_name' => 'Norsk',
'english_name' => 'norwegian',
'isocode' => 'nn_NO',
'available' => 0,
],
[
'original_name' => 'Occitan',
'english_name' => 'occitan',
'isocode' => 'oc',
'available' => 0,
],
[
'original_name' => 'پښتو',
'english_name' => 'pashto',
'isocode' => 'ps',
'available' => 0,
],
[
'original_name' => 'فارسی',
'english_name' => 'persian',
'isocode' => 'fa_IR',
'available' => 0,
],
[
'original_name' => 'Polski',
'english_name' => 'polish',
'isocode' => 'pl_PL',
'available' => 0,
],
[
'original_name' => 'Português europeu',
'english_name' => 'portuguese',
'isocode' => 'pt_PT',
'available' => 0,
],
[
'original_name' => 'Runasimi',
'english_name' => 'quechua_cusco',
'isocode' => 'quz_PE',
'available' => 0,
],
[
'original_name' => 'Română',
'english_name' => 'romanian',
'isocode' => 'ro_RO',
'available' => 0,
],
[
'original_name' => 'Русский',
'english_name' => 'russian',
'isocode' => 'ru_RU',
'available' => 0,
],
[
'original_name' => 'Srpski',
'english_name' => 'serbian',
'isocode' => 'sr_RS',
'available' => 0,
],
[
'original_name' => '中文(简体',
'english_name' => 'simpl_chinese',
'isocode' => 'zh_CN',
'available' => 0,
],
[
'original_name' => 'Slovenčina',
'english_name' => 'slovak',
'isocode' => 'sk_SK',
'available' => 0,
],
[
'original_name' => 'Slovenščina',
'english_name' => 'slovenian',
'isocode' => 'sl_SI',
'available' => 0,
],
[
'original_name' => 'الصومالية',
'english_name' => 'somali',
'isocode' => 'so_SO',
'available' => 0,
],
[
'original_name' => 'Español',
'english_name' => 'spanish',
'isocode' => 'es',
'available' => 0,
],
[
'original_name' => 'Kiswahili',
'english_name' => 'swahili',
'isocode' => 'sw_KE',
'available' => 0,
],
[
'original_name' => 'Svenska',
'english_name' => 'swedish',
'isocode' => 'sv_SE',
'available' => 0,
],
[
'original_name' => 'Tagalog',
'english_name' => 'tagalog',
'isocode' => 'tl_PH',
'available' => 0,
],
[
'original_name' => 'ไทย',
'english_name' => 'thai',
'isocode' => 'th',
'available' => 0,
],
[
'original_name' => 'Tibetan',
'english_name' => 'tibetan',
'isocode' => 'bo_CN',
'available' => 0,
],
[
'original_name' => '繁體中文',
'english_name' => 'trad_chinese',
'isocode' => 'zh_TW',
'available' => 0,
],
[
'original_name' => 'Türkçe',
'english_name' => 'turkish',
'isocode' => 'tr',
'available' => 0,
],
[
'original_name' => 'Українська',
'english_name' => 'ukrainian',
'isocode' => 'uk_UA',
'available' => 0,
],
[
'original_name' => 'Tiếng Việt',
'english_name' => 'vietnamese',
'isocode' => 'vi_VN',
'available' => 0,
],
[
'original_name' => 'isiXhosa',
'english_name' => 'xhosa',
'isocode' => 'xh_ZA',
'available' => 0,
],
[
'original_name' => 'Yorùbá',
'english_name' => 'yoruba',
'isocode' => 'yo_NG',
'available' => 0,
],
];
foreach ($list as $data) {
$lang = (new Language())
->set($data['name'])
->setCode($data['code'])
->setTreePos($key + 1)
->setOriginalName($data['original_name'])
->setEnglishName($data['english_name'])
->setIsocode($data['isocode'])
->setAvailable(1 === (int) $data['available'])
;
$manager->persist($lang);
}*/
// $product = new Product();
// $manager->persist($product);
}
//$manager->flush();
$manager->flush();
}
}

@ -6,6 +6,15 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\DataFixtures;
use Chamilo\CoreBundle\Entity\SequenceCondition;
use Chamilo\CoreBundle\Entity\SequenceFormula;
use Chamilo\CoreBundle\Entity\SequenceMethod;
use Chamilo\CoreBundle\Entity\SequenceRule;
use Chamilo\CoreBundle\Entity\SequenceRuleCondition;
use Chamilo\CoreBundle\Entity\SequenceRuleMethod;
use Chamilo\CoreBundle\Entity\SequenceTypeEntity;
use Chamilo\CoreBundle\Entity\SequenceValid;
use Chamilo\CoreBundle\Entity\SequenceVariable;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
@ -13,6 +22,306 @@ class SequenceFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
//$manager->flush();
$sequenceRule = (new SequenceRule())
->setDescription(
'If user completes 70% of an entity or group of items, he will be able to access another entity or group of items'
)
;
$manager->persist($sequenceRule);
$sequenceCondition1 = (new SequenceCondition())
->setDescription('<= 100%')
->setMathOperation('<=')
->setParam('100.0')
->setActTrue('2')
->setActFalse('0')
;
$manager->persist($sequenceCondition1);
$sequenceCondition2 = (new SequenceCondition())
->setDescription('>= 70%')
->setMathOperation('>=')
->setParam('70.0')
->setActTrue('0')
->setActFalse('')
;
$manager->persist($sequenceCondition2);
$sequenceRuleCondition1 = (new SequenceRuleCondition())
->setCondition($sequenceCondition1)
->setRule($sequenceRule)
;
$manager->persist($sequenceRuleCondition1);
$sequenceRuleCondition2 = (new SequenceRuleCondition())
->setCondition($sequenceCondition2)
->setRule($sequenceRule)
;
$manager->persist($sequenceRuleCondition2);
$list = [
[
'description' => 'Add completed item',
'formula' => 'v#2 + $complete_items;',
'assign' => 2,
'met_type' => 'add',
'act_false' => '',
],
[
'description' => 'Update progress by division',
'formula' => 'v#2 / v#3 * 100;',
'assign' => 1,
'met_type' => 'div',
'act_false' => '',
],
[
'description' => 'Add completed item',
'formula' => 'v#2 + $complete_items;',
'assign' => 2,
'met_type' => 'add',
'act_false' => '',
],
[
'description' => 'Update items count',
'formula' => '$total_items;',
'assign' => 3,
'met_type' => 'update',
'act_false' => '',
],
[
'description' => 'Enable success',
'formula' => '1;',
'assign' => 4,
'met_type' => 'success',
'act_false' => '',
],
[
'description' => 'Store success date',
'formula' => '(empty(v#5))? api_get_utc_datetime() : v#5;',
'assign' => 5,
'met_type' => 'success',
'act_false' => '',
],
[
'description' => 'Enable availability',
'formula' => '1;',
'assign' => 6,
'met_type' => 'pre',
'act_false' => '',
],
[
'description' => 'Store availability start date',
'formula' => '(empty(v#7))? api_get_utc_datetime() : v#7;',
'assign' => 7,
'met_type' => 'pre',
'act_false' => '',
],
[
'description' => 'Store availability end date',
'formula' => '(empty($available_end_date))? api_get_utc_datetime($available_end_date) : "0000-00-00 00:00:00";',
'assign' => 8,
'met_type' => 'pre',
'act_false' => '',
],
[
'description' => 'Increase the items count',
'formula' => 'v#3 + $total_items;',
'assign' => 3,
'met_type' => 'add',
'act_false' => '',
],
[
'description' => 'Update completed items',
'formula' => '$complete_items;',
'assign' => 2,
'met_type' => 'update',
'act_false' => '',
],
[
'description' => 'Update progress',
'formula' => '$complete_items / $total_items * 100;',
'assign' => 1,
'met_type' => 'update',
'act_false' => '',
],
];
$methods = [];
foreach ($list as $key => $item) {
$sequenceMethod = (new SequenceMethod())
->setDescription($item['description'])
->setFormula($item['formula'])
->setAssign((string) $item['assign'])
->setMetType($item['met_type'])
->setActFalse($item['act_false'])
;
$manager->persist($sequenceMethod);
$methods[] = $sequenceMethod;
$sequenceRuleMethod = (new SequenceRuleMethod())
->setRule($sequenceRule)
->setMethod($sequenceMethod)
->setMethodOrder((string) ($key + 1))
;
$manager->persist($sequenceRuleMethod);
}
$list = [
[
'name' => 'Percentile progress',
'description' => 'advance',
'default_val' => '0.0',
],
[
'name' => 'Completed items',
'description' => 'complete_items',
'default_val' => '0',
],
[
'name' => 'Items count',
'description' => 'total_items',
'default_val' => '0',
],
[
'name' => 'Completed',
'description' => 'success',
'default_val' => '0',
],
[
'name' => 'Completion date',
'description' => 'success_date',
'default_val' => '0000-00-00 00:00:00',
],
[
'name' => 'Available',
'description' => 'available',
'default_val' => '0',
],
[
'name' => 'Availability start date',
'description' => 'available_start_date',
'default_val' => '0000-00-00 00:00:00',
],
[
'name' => 'Availability end date',
'description' => 'available_end_date',
'default_val' => '0000-00-00 00:00:00',
],
];
$variables = [];
foreach ($list as $item) {
$sequenceVariable = (new SequenceVariable())
->setName($item['name'])
->setDescription($item['description'])
->setDefaultValue($item['default_val'])
;
$manager->persist($sequenceVariable);
$variables[] = $sequenceVariable;
}
$list = [
[
'method' => 1,
'variable' => 2,
],
[
'method' => 2,
'variable' => 2,
],
[
'method' => 2,
'variable' => 3,
],
[
'method' => 2,
'variable' => 1,
],
[
'method' => 3,
'variable' => 3,
],
[
'method' => 4,
'variable' => 4,
],
[
'method' => 5,
'variable' => 5,
],
[
'method' => 6,
'variable' => 6,
],
[
'method' => 7,
'variable' => 7,
],
[
'method' => 8,
'variable' => 8,
],
[
'method' => 9,
'variable' => 3,
],
[
'method' => 10,
'variable' => 2,
],
[
'method' => 11,
'variable' => 1,
],
];
foreach ($list as $item) {
$sequenceFormula = (new SequenceFormula())
->setMethod($methods[$item['method'] - 1])
->setVariable($variables[$item['variable'] - 1])
;
$manager->persist($sequenceFormula);
}
$sequenceValid = (new SequenceValid())
->setVariable($variables[0])
->setCondition($sequenceCondition1)
;
$manager->persist($sequenceValid);
$sequenceValid = (new SequenceValid())
->setVariable($variables[0])
->setCondition($sequenceCondition2)
;
$manager->persist($sequenceValid);
$list = [
[
'name' => 'Lp',
'description' => 'Learning Path',
'entity_table' => 'c_lp',
],
[
'name' => 'Quiz',
'description' => 'Quiz and Tests',
'entity_table' => 'c_quiz',
],
[
'name' => 'LpItem',
'description' => 'Items of a Learning Path',
'entity_table' => 'c_lp_item',
],
];
foreach ($list as $item) {
$sequenceType = (new SequenceTypeEntity())
->setName($item['name'])
->setDescription($item['description'])
->setEntityTable($item['entity_table'])
;
$manager->persist($sequenceType);
}
$manager->flush();
}
}

@ -13,5 +13,6 @@ class SystemTemplateFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
// @todo?
}
}

@ -10,21 +10,24 @@ use Chamilo\CoreBundle\Entity\TicketCategory;
use Chamilo\CoreBundle\Entity\TicketPriority;
use Chamilo\CoreBundle\Entity\TicketProject;
use Chamilo\CoreBundle\Entity\TicketStatus;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use TicketManager;
/**
* @internal
* @coversNothing
*/
class TicketFixtures extends KernelTestCase
class TicketFixtures extends Fixture implements ContainerAwareInterface
{
public function load(ObjectManager $manager): void
private ContainerInterface $container;
public function setContainer(ContainerInterface $container = null): void
{
self::bootKernel();
$this->container = $container;
}
$container = $this->getContainer();
public function load(ObjectManager $manager): void
{
$container = $this->container;
$trans = $container->get('translator');
$adminId = 1;

@ -748,6 +748,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
//$this->extraFields = new ArrayCollection();
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
$this->registrationDate = new DateTime();
$this->enabled = false;
$this->locked = false;

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Repository;
use Chamilo\CoreBundle\DataFixtures\AccessGroupFixtures;
use Chamilo\CoreBundle\Entity\Group;
use Chamilo\CoreBundle\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
@ -31,4 +32,75 @@ class GroupRepository extends ServiceEntityRepository
return $group->getUsers();
}
public function createDefaultGroups(AccessGroupFixtures $accessGroupFixtures = null): void
{
$groups = [
[
'code' => 'ADMIN',
'title' => 'Administrators',
'roles' => ['ROLE_ADMIN'],
],
[
'code' => 'STUDENT',
'title' => 'Students',
'roles' => ['ROLE_STUDENT'],
],
[
'code' => 'TEACHER',
'title' => 'Teachers',
'roles' => ['ROLE_TEACHER'],
],
[
'code' => 'RRHH',
'title' => 'Human resources manager',
'roles' => ['ROLE_RRHH'],
],
[
'code' => 'SESSION_MANAGER',
'title' => 'Session',
'roles' => ['ROLE_SESSION_MANAGER'],
],
[
'code' => 'QUESTION_MANAGER',
'title' => 'Question manager',
'roles' => ['ROLE_QUESTION_MANAGER'],
],
[
'code' => 'STUDENT_BOSS',
'title' => 'Student boss',
'roles' => ['ROLE_STUDENT_BOSS'],
],
[
'code' => 'INVITEE',
'title' => 'Invitee',
'roles' => ['ROLE_INVITEE'],
],
];
$manager = $this->getEntityManager();
$repo = $manager->getRepository(Group::class);
foreach ($groups as $groupData) {
$criteria = [
'code' => $groupData['code'],
];
$groupExists = $repo->findOneBy($criteria);
if (!$groupExists) {
$group = new Group($groupData['title']);
$group
->setCode($groupData['code'])
;
foreach ($groupData['roles'] as $role) {
$group->addRole($role);
}
$manager->persist($group);
$accessGroupFixtures->addReference('GROUP_'.$groupData['code'], $group);
}
}
$manager->flush();
}
}

Loading…
Cancel
Save