diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index 9d84967cbb..3f5e62469a 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -1147,6 +1147,7 @@ function api_protect_teacher_script() function api_block_anonymous_users($printHeaders = true) { $user = api_get_user_info(); + if (!(isset($user['user_id']) && $user['user_id']) || api_is_anonymous($user['user_id'], true)) { api_not_allowed($printHeaders); @@ -3614,6 +3615,7 @@ function api_not_allowed( $message = null, $responseCode = 0 ) { + throw new Exception('You are not allowed'); $message = empty($message) ? get_lang('You are not allowed') : $message; Session::write('error_message', $message); diff --git a/public/main/inc/lib/usermanager.lib.php b/public/main/inc/lib/usermanager.lib.php index e7f4f3a7b7..b3ca7542be 100644 --- a/public/main/inc/lib/usermanager.lib.php +++ b/public/main/inc/lib/usermanager.lib.php @@ -342,7 +342,6 @@ class UserManager try { $factory = Container::$container->get('Chamilo\CoreBundle\Repository\ResourceFactory'); $repo = $factory->createRepository('global', 'users'); - $userManager->updateUser($user); // Add user as a node diff --git a/public/main/install/install.lib.php b/public/main/install/install.lib.php index 9c89f32fb6..f8983cc94e 100644 --- a/public/main/install/install.lib.php +++ b/public/main/install/install.lib.php @@ -1000,8 +1000,10 @@ function display_requirements( } else { $error = false; // First, attempt to set writing permissions if we don't have them yet - $perm = api_get_permissions_for_new_directories(); - $perm_file = api_get_permissions_for_new_files(); + //$perm = api_get_permissions_for_new_directories(); + $perm = octdec('0777'); + //$perm_file = api_get_permissions_for_new_files(); + $perm_file = octdec('0666'); $notWritable = []; $checked_writable = api_get_path(SYS_PUBLIC_PATH); @@ -3018,8 +3020,7 @@ function installPages($container) */ function installSchemas($container, $manager, $upgrade = false) { - error_log('installSchemas'); - $settingsManager = Container::getSettingsManager(); + $settingsManager = $container->get('chamilo.settings.manager'); // Install course tools (table "tool") $toolChain = $container->get(ToolChain::class); @@ -3144,7 +3145,6 @@ function finishInstallationWithContainer( error_log('finishInstallationWithContainer'); $sysPath = !empty($sysPath) ? $sysPath : api_get_path(SYMFONY_SYS_PATH); Container::setContainer($container); - error_log('Container set'); Container::setLegacyServices($container, false); error_log('setLegacyServices'); diff --git a/src/CoreBundle/EventListener/LegacyListener.php b/src/CoreBundle/EventListener/LegacyListener.php index 0d4f78a8d8..7a0d4fb93c 100644 --- a/src/CoreBundle/EventListener/LegacyListener.php +++ b/src/CoreBundle/EventListener/LegacyListener.php @@ -5,11 +5,13 @@ namespace Chamilo\CoreBundle\EventListener; use Chamilo\CoreBundle\Framework\Container; +use Chamilo\UserBundle\Entity\User; use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\Security\Core\User\UserInterface; /** * Class LegacyListener @@ -38,83 +40,84 @@ class LegacyListener // Legacy way of detect current access_url $installed = $container->getParameter('installed'); + $urlId = 1; + if (empty($installed)) { + throw new \Exception('Chamilo is not installed'); + } - if (!empty($installed)) { - $twig = $container->get('twig'); + $twig = $container->get('twig'); - // Set legacy twig globals _p, _u, _s - /*$globals = \Template::getGlobals(); - foreach ($globals as $index => $value) { - $twig->addGlobal($index, $value); - }*/ + // Set legacy twig globals _p, _u, _s + /*$globals = \Template::getGlobals(); + foreach ($globals as $index => $value) { + $twig->addGlobal($index, $value); + }*/ - $token = $container->get('security.token_storage')->getToken(); - $userObject = null; - if (null !== $token) { - $userObject = $container->get('security.token_storage')->getToken()->getUser(); - } + $token = $container->get('security.token_storage')->getToken(); + $userObject = null; + if (null !== $token) { + /** @var User $userObject */ + $userObject = $container->get('security.token_storage')->getToken()->getUser(); + } - $userInfo = []; - $userInfo['is_anonymous'] = true; - $isAdmin = false; - $allowedCreateCourse = false; - $userStatus = null; - $userId = $session->get('_uid'); - - if (null !== $userObject && !empty($userId)) { - $userInfo = api_get_user_info(); - if ($userInfo) { - $userStatus = $userInfo['status']; - $isAdmin = $userInfo['is_admin']; - $userInfo['is_anonymous'] = false; - } - $allowedCreateCourse = 1 === $userStatus; - } - $session->set('_user', $userInfo); - $session->set('is_platformAdmin', $isAdmin); - $session->set('is_allowedCreateCourse', $allowedCreateCourse); - - /*$adminInfo = [ - 'email' => api_get_setting('emailAdministrator'), - 'surname' => api_get_setting('administratorSurname'), - 'name' => api_get_setting('administratorName'), - 'telephone' => api_get_setting('administratorTelephone'), - ]; - $twig->addGlobal('_admin', $adminInfo);*/ - - // Theme icon is loaded in the TwigListener src/ThemeBundle/EventListener/TwigListener.php - //$theme = api_get_visual_theme(); - $languages = api_get_languages(); - $languageList = []; - foreach ($languages as $isoCode => $language) { - $languageList[languageToCountryIsoCode($isoCode)] = $language; + $userInfo = []; + $isAdmin = false; + $allowedCreateCourse = false; + $userStatus = null; + //$userId = $session->get('_uid'); + if ($userObject instanceof UserInterface) { + $userInfo = api_get_user_info($userObject->getId()); + if ($userInfo) { + $userStatus = $userObject->getStatus(); + $isAdmin = $userObject->hasGroup('ROLE_ADMIN'); } + $allowedCreateCourse = 1 === $userStatus; + } + $session->set('_user', $userInfo); + $session->set('is_platformAdmin', $isAdmin); + $session->set('is_allowedCreateCourse', $allowedCreateCourse); + + /*$adminInfo = [ + 'email' => api_get_setting('emailAdministrator'), + 'surname' => api_get_setting('administratorSurname'), + 'name' => api_get_setting('administratorName'), + 'telephone' => api_get_setting('administratorTelephone'), + ]; + $twig->addGlobal('_admin', $adminInfo);*/ + + // Theme icon is loaded in the TwigListener src/ThemeBundle/EventListener/TwigListener.php + //$theme = api_get_visual_theme(); + $languages = api_get_languages(); + $languageList = []; + foreach ($languages as $isoCode => $language) { + $languageList[languageToCountryIsoCode($isoCode)] = $language; + } - $isoFixed = languageToCountryIsoCode($request->getLocale()); + $isoFixed = languageToCountryIsoCode($request->getLocale()); - if (!isset($languageList[$isoFixed])) { - $isoFixed = 'en'; - } + if (!isset($languageList[$isoFixed])) { + $isoFixed = 'en'; + } - $twig->addGlobal( - 'current_locale_info', - [ - 'flag' => $isoFixed, - 'text' => $languageList[$isoFixed] ?? 'English', - ] - ); - $twig->addGlobal('current_locale', $request->getLocale()); - $twig->addGlobal('available_locales', $languages); - $twig->addGlobal('show_toolbar', \Template::isToolBarDisplayedForUser() ? 1 : 0); - - // Extra content - $extraHeader = ''; - if (!api_is_platform_admin()) { - $extraHeader = trim(api_get_setting('header_extra_content')); - } - $twig->addGlobal('header_extra_content', $extraHeader); + $twig->addGlobal( + 'current_locale_info', + [ + 'flag' => $isoFixed, + 'text' => $languageList[$isoFixed] ?? 'English', + ] + ); + $twig->addGlobal('current_locale', $request->getLocale()); + $twig->addGlobal('available_locales', $languages); + $twig->addGlobal('show_toolbar', \Template::isToolBarDisplayedForUser() ? 1 : 0); + + // Extra content + $extraHeader = ''; + if (!api_is_platform_admin()) { + $extraHeader = trim(api_get_setting('header_extra_content')); } + $twig->addGlobal('header_extra_content', $extraHeader); + // We set cid_reset = true if we enter inside a main/admin url // CourseListener check this variable and deletes the course session diff --git a/src/CoreBundle/EventListener/LoginSuccessHandler.php b/src/CoreBundle/EventListener/LoginSuccessHandler.php index b49096bae5..4b9b083c6f 100644 --- a/src/CoreBundle/EventListener/LoginSuccessHandler.php +++ b/src/CoreBundle/EventListener/LoginSuccessHandler.php @@ -96,12 +96,14 @@ class LoginSuccessHandler } } + $goToCourse = $this->settingsManager->getSetting('course.go_to_course_after_login'); + $session->set('_uid', $user->getId()); //$session->set('_user', $userInfo); //$session->set('is_platformAdmin', \UserManager::is_admin($userId)); //$session->set('is_allowedCreateCourse', $userInfo['status'] === 1); // Redirecting to a course or a session. - if ('true' === api_get_setting('course.go_to_course_after_login')) { + if ('true' === $goToCourse) { // Get the courses list $personal_course_list = \UserManager::get_personal_session_course_list($userId); $my_session_list = []; diff --git a/src/CoreBundle/Framework/Container.php b/src/CoreBundle/Framework/Container.php index b0a1924158..90733512fd 100644 --- a/src/CoreBundle/Framework/Container.php +++ b/src/CoreBundle/Framework/Container.php @@ -258,7 +258,7 @@ class Container */ public static function getSettingsManager() { - return self::$settingsManager; + return self::$container->get('chamilo.settings.manager'); } /** @@ -330,7 +330,7 @@ class Container */ public static function getCourseRepository() { - return self::$container->get('Chamilo\CoreBundle\Repository\CourseRepository'); + return self::$container->get(CourseRepository::class); } /** @@ -624,15 +624,12 @@ class Container $em = $container->get('doctrine.orm.entity_manager'); \Database::setManager($em); \CourseManager::setEntityManager($em); - self::setSettingsManager($container->get('chamilo.settings.manager')); self::setUserManager($container->get('fos_user.user_manager')); self::setSiteManager($container->get('sonata.page.manager.site')); - \CourseManager::setCourseSettingsManager($container->get('Chamilo\CourseBundle\Manager\SettingsManager')); // Setting course tool chain (in order to create tools to a course) \CourseManager::setToolList($container->get(ToolChain::class)); - if ($setSession) { self::$session = $container->get('session'); } diff --git a/src/CoreBundle/Repository/ResourceRepository.php b/src/CoreBundle/Repository/ResourceRepository.php index 2927d44e16..51a9413d2e 100644 --- a/src/CoreBundle/Repository/ResourceRepository.php +++ b/src/CoreBundle/Repository/ResourceRepository.php @@ -107,14 +107,14 @@ class ResourceRepository extends BaseEntityRepository $this->settings = new Settings(); $this->templates = new Template(); - $em = $this->getEntityManager(); $service = get_class($this); $name = $this->toolChain->getResourceTypeNameFromRepository($service); - $repo = $em->getRepository('ChamiloCoreBundle:Resource\ResourceType'); + + $repo = $entityManager->getRepository('ChamiloCoreBundle:Resource\ResourceType'); $this->resourceType = $repo->findOneBy(['name' => $name]); if (empty($this->resourceType)) { - throw new \Exception("Resource Type missing in repo: $service, you need to add a record in the resource_type table"); + //throw new \Exception("Resource Type missing in repo: $service, you need to add a record in the resource_type table"); } } diff --git a/src/CourseBundle/EventListener/CourseListener.php b/src/CourseBundle/EventListener/CourseListener.php index 3a8a57c75b..fa5a956fc6 100644 --- a/src/CourseBundle/EventListener/CourseListener.php +++ b/src/CourseBundle/EventListener/CourseListener.php @@ -183,9 +183,9 @@ class CourseListener $sessionHandler->set('course_already_visited', $courseCode); }*/ - Container::setRequest($request); - Container::setContainer($container); - Container::setLegacyServices($container); +// Container::setRequest($request); +// Container::setContainer($container); +// Container::setLegacyServices($container); } } diff --git a/src/CourseBundle/Manager/SettingsManager.php b/src/CourseBundle/Manager/SettingsManager.php index 80be7de4fb..ac9935c995 100644 --- a/src/CourseBundle/Manager/SettingsManager.php +++ b/src/CourseBundle/Manager/SettingsManager.php @@ -5,6 +5,7 @@ namespace Chamilo\CourseBundle\Manager; use Chamilo\CoreBundle\Entity\Course; +use Chamilo\CoreBundle\Entity\SettingsCurrent; use Chamilo\CourseBundle\Entity\CCourseSetting; use Chamilo\SettingsBundle\Manager\SettingsManager as ChamiloSettingsManager; use Sylius\Bundle\SettingsBundle\Model\Settings; @@ -100,15 +101,13 @@ class SettingsManager extends ChamiloSettingsManager $repo = $this->manager->getRepository('ChamiloCoreBundle:SettingsCurrent'); $persistedParameters = $repo->findBy(['category' => $settings->getSchemaAlias()]); - $persistedParametersMap = []; + $persistedParametersMap = []; foreach ($persistedParameters as $parameter) { $persistedParametersMap[$parameter->getTitle()] = $parameter; } - /** @var \Chamilo\CoreBundle\Entity\SettingsCurrent $url */ - //$url = $event->getArgument('url'); - //$url = $this->getUrl(); + /** @var SettingsCurrent $url */ $simpleCategoryName = str_replace('chamilo_course.settings.', '', $namespace); foreach ($parameters as $name => $value) { @@ -123,7 +122,6 @@ class SettingsManager extends ChamiloSettingsManager ->setValue($value) ->setCId($this->getCourse()->getId()) ; - $this->manager->persist($parameter); } } @@ -184,7 +182,6 @@ class SettingsManager extends ChamiloSettingsManager } $this->parameterManager->flush(); - $this->cache->save($namespace, $parameters); } diff --git a/src/SettingsBundle/Manager/SettingsManager.php b/src/SettingsBundle/Manager/SettingsManager.php index a662dcd673..a47756e40c 100644 --- a/src/SettingsBundle/Manager/SettingsManager.php +++ b/src/SettingsBundle/Manager/SettingsManager.php @@ -32,11 +32,6 @@ class SettingsManager implements SettingsManagerInterface */ protected $schemaRegistry; - /** - * @var ServiceRegistryInterface - */ - protected $resolverRegistry; - /** * @var EntityManager */ @@ -58,7 +53,6 @@ class SettingsManager implements SettingsManagerInterface * @var Settings[] */ protected $resolvedSettings = []; - protected $settings; protected $schemaList; @@ -211,7 +205,6 @@ class SettingsManager implements SettingsManagerInterface */ $schemaList = []; $settingsBuilder = new SettingsBuilder(); - $all = $this->getAllParametersByCategory(); foreach ($schemas as $schema) { @@ -219,7 +212,6 @@ class SettingsManager implements SettingsManagerInterface $schemaRegister->buildSettings($settingsBuilder); $name = $this->convertServiceToNameSpace($schema); $settings = new Settings(); - //$settings = $this->load($name); $parameters = $all[$name]; foreach ($settingsBuilder->getTransformers() as $parameter => $transformer) { if (array_key_exists($parameter, $parameters)) { @@ -235,7 +227,6 @@ class SettingsManager implements SettingsManagerInterface $parameters = $settingsBuilder->resolve($parameters); $settings->setParameters($parameters); - $schemaList[$name] = $settings; } $this->schemaList = $schemaList;