isMainRequest()) { // Do nothing on subrequests return; } $request = $event->getRequest(); // Ignore debug toolbar if ('_wdt' === $request->attributes->get('_route')) { return; } // Ignore profiler toolbar if ('_wdt' === $request->attributes->get('_profiler')) { return; } // Skip all course/session logic during installation pages. // This prevents crashes when APP_INSTALLED is wrong or the DB is not ready yet. $path = $request->getPathInfo(); if (\is_string($path) && str_starts_with($path, '/main/install/')) { return; } // Always reset context roles at the beginning of each main request $this->resetContextRolesOnTokenUser(); if (true === $cidReset) { $this->cleanSessionHandler($request); return; } // Prevent "Session has not been set" during early bootstrap or install. if (!$request->hasSession()) { // No session available yet, so we cannot safely store course/session context. return; } $sessionHandler = $request->getSession(); $twig = $this->twig; $course = null; $courseInfo = []; // Check if URL has cid value. Using Symfony request. $courseId = (int) $request->get('cid'); $checker = $this->authorizationChecker; if (!empty($courseId)) { if ($sessionHandler->has('course')) { /** @var Course $courseFromSession */ $courseFromSession = $sessionHandler->get('course'); if ($courseFromSession instanceof Course && $courseId === $courseFromSession->getId()) { $course = $courseFromSession; $courseInfo = (array) $sessionHandler->get('_course'); } } if (null === $course) { $course = $this->entityManager->find(Course::class, $courseId); if (null === $course) { throw new NotFoundHttpException($this->translator->trans('Course does not exist')); } $courseInfo = api_get_course_info($course->getCode()); } // Setting variables in the session. $sessionHandler->set('course', $course); $sessionHandler->set('_real_cid', $course->getId()); $sessionHandler->set('cid', $course->getId()); $sessionHandler->set('_cid', $course->getCode()); $sessionHandler->set('_course', $courseInfo); ChamiloSession::write('cid', $course->getId()); ChamiloSession::write('_real_cid', $course->getId()); ChamiloSession::write('_course', $courseInfo); // Setting variables for the twig templates. $twig->addGlobal('course', $course); $ltiAccessRestored = true === $request->attributes->get('_lti_provider_access_restored'); if ($ltiAccessRestored) { $ltiUserId = (int) $request->attributes->get('_lti_provider_user_id', 0); $ltiCourseId = (int) $request->attributes->get('_lti_provider_course_id', 0); if ( $ltiUserId > 0 && $ltiCourseId > 0 && $ltiCourseId === (int) $course->getId() ) { return; } } if (false === $checker->isGranted(CourseVoter::VIEW, $course)) { throw new NotAllowedException($this->translator->trans("You're not allowed in this course")); } // Checking if sid is used. $sessionId = (int) $request->get('sid'); if (empty($sessionId)) { $sessionHandler->remove('session_name'); $sessionHandler->remove('sid'); $sessionHandler->remove('session'); ChamiloSession::erase('session_name'); ChamiloSession::erase('sid'); ChamiloSession::erase('session'); } else { $session = $this->entityManager->find(Session::class, $sessionId); if (null !== $session) { $session->setCurrentCourse($course); if (false === $checker->isGranted(SessionVoter::VIEW, $session)) { throw new AccessDeniedHttpException($this->translator->trans("You're not allowed in this session")); } $sessionHandler->set('session_name', $session->getTitle()); $sessionHandler->set('sid', $session->getId()); $sessionHandler->set('session', $session); ChamiloSession::write('sid', $session->getId()); $twig->addGlobal('session', $session); } else { throw new NotFoundHttpException($this->translator->trans('Session not found')); } } // Group $groupId = (int) $request->get('gid'); if (empty($groupId)) { $sessionHandler->remove('gid'); ChamiloSession::erase('gid'); } else { $group = $this->entityManager->getRepository(CGroup::class)->find($groupId); if (null === $group) { throw new NotFoundHttpException($this->translator->trans('Group not found')); } $group->setParent($course); if (false === $checker->isGranted(GroupVoter::VIEW, $group)) { throw new AccessDeniedHttpException($this->translator->trans("You're not allowed in this group")); } $sessionHandler->set('group', $group); $sessionHandler->set('gid', $groupId); ChamiloSession::write('gid', $groupId); } $query = $request->query->all(); $body = $request->request->all(); $origin = self::normalizeOrigin( $query['origin'] ?? $body['origin'] ?? null ); if (!empty($origin)) { $sessionHandler->set('origin', $origin); } $courseParams = $this->generateCourseUrl($course, $sessionId, $groupId, $origin); $sessionHandler->set('course_url_params', $courseParams); $twig->addGlobal('course_url_params', $courseParams); } else { $this->cleanSessionHandler($request); } } /** * Once the onKernelRequest was fired, we check if the course/session object were set and we inject them in the controller. */ public function onKernelController(ControllerEvent $event): void { $controllerList = $event->getController(); if (!\is_array($controllerList)) { return; } $request = $event->getRequest(); // Prevent "Session has not been set" during early bootstrap or install. if (!$request->hasSession()) { return; } // Skip injection during installation pages. $path = $request->getPathInfo(); if (\is_string($path) && str_starts_with($path, '/main/install/')) { return; } $sessionHandler = $request->getSession(); $courseId = (int) $request->get('cid'); isMainRequest()) { // Do nothing on subrequests return; } $request = $event->getRequest(); // Ignore debug toolbar if ('_wdt' === $request->attributes->get('_route')) { return; } // Ignore profiler toolbar if ('_wdt' === $request->attributes->get('_profiler')) { return; } // Skip all course/session logic during installation pages. // This prevents crashes when APP_INSTALLED is wrong or the DB is not ready yet. $path = $request->getPathInfo(); if (\is_string($path) && str_starts_with($path, '/main/install/')) { return; } // Always reset context roles at the beginning of each main request $this->resetContextRolesOnTokenUser(); if (true === $cidReset) { $this->cleanSessionHandler($request); return; } // Prevent "Session has not been set" during early bootstrap or install. if (!$request->hasSession()) { // No session available yet, so we cannot safely store course/session context. return; } $sessionHandler = $request->getSession(); $twig = $this->twig; $course = null; $courseInfo = []; // Check if URL has cid value. Using Symfony request. $courseId = (int) $request->get('cid'); $checker = $this->authorizationChecker; if (!empty($courseId)) { if ($sessionHandler->has('course')) { /** @var Course $courseFromSession */ $courseFromSession = $sessionHandler->get('course'); if ($courseFromSession instanceof Course && $courseId === $courseFromSession->getId()) { $course = $courseFromSession; $courseInfo = (array) $sessionHandler->get('_course'); } } if (null === $course) { $course = $this->entityManager->find(Course::class, $courseId); if (null === $course) { throw new NotFoundHttpException($this->translator->trans('Course does not exist')); } $courseInfo = api_get_course_info($course->getCode()); } // Setting variables in the session. $sessionHandler->set('course', $course); $sessionHandler->set('_real_cid', $course->getId()); $sessionHandler->set('cid', $course->getId()); $sessionHandler->set('_cid', $course->getCode()); $sessionHandler->set('_course', $courseInfo); ChamiloSession::write('cid', $course->getId()); ChamiloSession::write('_real_cid', $course->getId()); ChamiloSession::write('_course', $courseInfo); // Setting variables for the twig templates. $twig->addGlobal('course', $course); $ltiAccessRestored = true === $request->attributes->get('_lti_provider_access_restored'); if ($ltiAccessRestored) { $ltiUserId = (int) $request->attributes->get('_lti_provider_user_id', 0); $ltiCourseId = (int) $request->attributes->get('_lti_provider_course_id', 0); if ( $ltiUserId > 0 && $ltiCourseId > 0 && $ltiCourseId === (int) $course->getId() ) { return; } } if (false === $checker->isGranted(CourseVoter::VIEW, $course)) { throw new NotAllowedException($this->translator->trans("You're not allowed in this course")); } // Checking if sid is used. $sessionId = (int) $request->get('sid'); if (empty($sessionId)) { $sessionHandler->remove('session_name'); $sessionHandler->remove('sid'); $sessionHandler->remove('session'); ChamiloSession::erase('session_name'); ChamiloSession::erase('sid'); ChamiloSession::erase('session'); } else { $session = $this->entityManager->find(Session::class, $sessionId); if (null !== $session) { $session->setCurrentCourse($course); if (false === $checker->isGranted(SessionVoter::VIEW, $session)) { throw new AccessDeniedHttpException($this->translator->trans("You're not allowed in this session")); } $sessionHandler->set('session_name', $session->getTitle()); $sessionHandler->set('sid', $session->getId()); $sessionHandler->set('session', $session); ChamiloSession::write('sid', $session->getId()); $twig->addGlobal('session', $session); } else { throw new NotFoundHttpException($this->translator->trans('Session not found')); } } // Group $groupId = (int) $request->get('gid'); if (empty($groupId)) { $sessionHandler->remove('gid'); ChamiloSession::erase('gid'); } else { $group = $this->entityManager->getRepository(CGroup::class)->find($groupId); if (null === $group) { throw new NotFoundHttpException($this->translator->trans('Group not found')); } $group->setParent($course); if (false === $checker->isGranted(GroupVoter::VIEW, $group)) { throw new AccessDeniedHttpException($this->translator->trans("You're not allowed in this group")); } $sessionHandler->set('group', $group); $sessionHandler->set('gid', $groupId); ChamiloSession::write('gid', $groupId); } $query = $request->query->all(); $body = $request->request->all(); $origin = self::normalizeOrigin( $query['origin'] ?? $body['origin'] ?? null ); if (!empty($origin)) { $sessionHandler->set('origin', $origin); } $courseParams = $this->generateCourseUrl($course, $sessionId, $groupId, $origin); $sessionHandler->set('course_url_params', $courseParams); $twig->addGlobal('course_url_params', $courseParams); } else { $this->cleanSessionHandler($request); } } /** * Once the onKernelRequest was fired, we check if the course/session object were set and we inject them in the controller. */ public function onKernelController(ControllerEvent $event): void { $controllerList = $event->getController(); if (!\is_array($controllerList)) { return; } $request = $event->getRequest(); // Prevent "Session has not been set" during early bootstrap or install. if (!$request->hasSession()) { return; } // Skip injection during installation pages. $path = $request->getPathInfo(); if (\is_string($path) && str_starts_with($path, '/main/install/')) { return; } $sessionHandler = $request->getSession(); $courseId = (int) $request->get('cid');
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.