Fix installation

pull/3215/head
Julio Montoya 5 years ago
parent a0f4cc06e4
commit 2704ce6e82
  1. 2
      public/main/inc/lib/api.lib.php
  2. 1
      public/main/inc/lib/usermanager.lib.php
  3. 10
      public/main/install/install.lib.php
  4. 23
      src/CoreBundle/EventListener/LegacyListener.php
  5. 4
      src/CoreBundle/EventListener/LoginSuccessHandler.php
  6. 7
      src/CoreBundle/Framework/Container.php
  7. 6
      src/CoreBundle/Repository/ResourceRepository.php
  8. 6
      src/CourseBundle/EventListener/CourseListener.php
  9. 9
      src/CourseBundle/Manager/SettingsManager.php
  10. 9
      src/SettingsBundle/Manager/SettingsManager.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);

@ -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

@ -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');

@ -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,9 +40,12 @@ 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');
// Set legacy twig globals _p, _u, _s
@ -52,22 +57,20 @@ class LegacyListener
$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();
//$userId = $session->get('_uid');
if ($userObject instanceof UserInterface) {
$userInfo = api_get_user_info($userObject->getId());
if ($userInfo) {
$userStatus = $userInfo['status'];
$isAdmin = $userInfo['is_admin'];
$userInfo['is_anonymous'] = false;
$userStatus = $userObject->getStatus();
$isAdmin = $userObject->hasGroup('ROLE_ADMIN');
}
$allowedCreateCourse = 1 === $userStatus;
}
@ -114,7 +117,7 @@ class LegacyListener
$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

@ -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 = [];

@ -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');
}

@ -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");
}
}

@ -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);
}
}

@ -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);
}

@ -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;

Loading…
Cancel
Save