diff --git a/.env.test b/.env.test index 414430e7ff..46e0e41acd 100644 --- a/.env.test +++ b/.env.test @@ -1,4 +1,4 @@ # define your env variables for the test env here -KERNEL_CLASS='App\Kernel' +KERNEL_CLASS='Chamilo\Kernel' APP_SECRET='s$cretf0rt3st' SYMFONY_DEPRECATIONS_HELPER=999999 diff --git a/composer.json b/composer.json index c4dda2f793..daae1fc61f 100755 --- a/composer.json +++ b/composer.json @@ -63,14 +63,14 @@ "sensiolabs/security-checker": "~6.0", "symfony/asset": "^4.0", - "symfony/dotenv": "^4.0", + "symfony/dotenv": "^5.0", "symfony/expression-language": "^4.0", - "symfony/flex": "^1.0", + "symfony/flex": "^1.6", "symfony/form": "^4.0", "symfony/framework-bundle": "^4.0", "symfony/http-kernel": "^4.0", "symfony/monolog-bundle": "^3.1", - "symfony/mailer": "^4.0", + "symfony/mailer": "^5.0", "symfony/polyfill-apcu": "^1.9", "symfony/requirements-checker": "^1.1", "symfony/security-bundle": "^4.0", @@ -78,7 +78,7 @@ "symfony/translation": "^4.0", "symfony/twig-bundle": "^4.0", "symfony/validator": "^4.0", - "symfony/webpack-encore-bundle": "^1.1", + "symfony/webpack-encore-bundle": "^1.7", "symfony/yaml": "^4.0", "tgalopin/html-sanitizer-bundle": "^1.1", @@ -212,7 +212,7 @@ "extra": { "symfony": { "allow-contrib": true, - "require": "4.4.*" + "require": "5.0.*" } } } diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index ffb2f9aa69..12fa56dd65 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -14,4 +14,4 @@ framework: name: chamilo2 fragments: ~ http_method_override: true - annotations: true + annotations: true \ No newline at end of file diff --git a/config/packages/sonata_page.yaml b/config/packages/sonata_page.yaml index 424afb3bc8..2b0f41a545 100644 --- a/config/packages/sonata_page.yaml +++ b/config/packages/sonata_page.yaml @@ -21,17 +21,9 @@ sonata_page: - ^/connect/(.*) - ^/editor/(.*) - ^/login/(.*) - - ^/main(.*) - - ^/plugin(.*) + - ^/error - ^/packages/(.*) - ^/package/(.*) - - ^install - - ^/install/(.*) - - install.php - - install.php/(.*) - - install.php/packages/(.*) - - install.php/package/(.*) - - install.php/(.*)/(.*) - ^/bundles/(.*) - ^/_wdt/(.*) - ^/_profiler/(.*) diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index e37f3b3c38..c792e77171 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -9,7 +9,9 @@ twig: - '@SonataFormatter/Form/formatter.html.twig' - '@SonataCore/Form/datepicker.html.twig' - '@SonataCore/Form/color.html.twig' - exception_controller: 'Chamilo\ThemeBundle\Controller\ExceptionController::showAction' + + exception_controller: Chamilo\CoreBundle\Controller\ExceptionController::showAction + globals: show_toolbar: true show_footer: true diff --git a/config/routes/dev/twig.yaml b/config/routes/dev/twig.yaml index f4ee83960b..bcbbf13d08 100644 --- a/config/routes/dev/twig.yaml +++ b/config/routes/dev/twig.yaml @@ -1,3 +1,3 @@ _errors: - resource: '@TwigBundle/Resources/config/routing/errors.xml' + resource: '@FrameworkBundle/Resources/config/routing/errors.xml' prefix: /_error diff --git a/config/services.yaml b/config/services.yaml index d72dfe26f3..f044ef9371 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,6 +1,7 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: + app_env: '%env(APP_ENV)%' password_encryption: '%env(APP_ENCRYPT_METHOD)%' secret: '%env(APP_SECRET)%' locale: '%env(APP_LOCALE)%' @@ -19,7 +20,6 @@ parameters: glide_config: source: 'oneup_flysystem.resources_filesystem' cache: 'oneup_flysystem.cache_resources_filesystem' - #cache: 'var/cache/resource/' glide_media_filters: editor_thumbnail: @@ -87,11 +87,6 @@ services: exclude: '../src/ThemeBundle/{Entity,Migrations,Tests}' public: true - Chamilo\ThemeBundle\Controller\ExceptionController: - public: true - arguments: - $debug: '%kernel.debug%' - Doctrine\ORM\EntityManager: "@doctrine.orm.default_entity_manager" chamilo_core.hook_factory: @@ -170,17 +165,10 @@ gregwar_captcha: height: 50 length: 6 +cocur_slugify: + lowercase: true + imports: - {resource: ../src/CoreBundle/Resources/config/services.yml} - {resource: ../src/PageBundle/Resources/config/services.yml} - {resource: ../vendor/knplabs/doctrine-behaviors/config/orm-services.yml} - -#sylius_resource: -# resources: -# app.exercise_category: -# driver: 'doctrine/orm' -# classes: -# model: 'Chamilo\CourseBundle\Entity\CExerciseCategory' - -cocur_slugify: - lowercase: true diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 00fc9ae088..2376661328 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,11 +9,11 @@ > + - diff --git a/public/main/calendar/agenda_js.php b/public/main/calendar/agenda_js.php index 9082e8835a..a174ecdb10 100644 --- a/public/main/calendar/agenda_js.php +++ b/public/main/calendar/agenda_js.php @@ -1,9 +1,6 @@ showAction($request, $exception); - $response->send(); + header('Location: '.api_get_path(WEB_PUBLIC_PATH).'error'); exit; } diff --git a/src/CoreBundle/Controller/ExceptionController.php b/src/CoreBundle/Controller/ExceptionController.php new file mode 100644 index 0000000000..bcf84fb56f --- /dev/null +++ b/src/CoreBundle/Controller/ExceptionController.php @@ -0,0 +1,83 @@ +getParameter('app_env')) { + throw new HttpException($exception->getCode(), $exception->getMessage()); + } + + $showException = true; + $name = $showException ? 'exception' : 'error'; + $code = $exception->getCode(); + $format = 'html'; + $loader = $this->container->get('twig')->getLoader(); + // when not in debug, try to find a template for the specific HTTP status code and format + if (!$showException) { + $template = sprintf('@ChamiloTheme/Exception/%s%s.%s.twig', $name, $code, $format); + if ($loader->exists($template)) { + return $template; + } + } + + // try to find a template for the given format + $template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format); + if ($loader->exists($template)) { + return $template; + } + + // default to a generic HTML exception + //$request->setRequestFormat('html'); + $template = sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name); + + return $this->render($template, ['exception' => $exception]); + } + + /** + * @Route("/error") + */ + public function errorAction(Request $request) + { + $message = $request->getSession()->get('error_message', ''); + $exception = new FlattenException(); + $exception->setCode(500); + + $exception->setMessage($message); + + $showException = true; + $name = $showException ? 'exception' : 'error'; + $code = $exception->getCode(); + $format = 'html'; + $loader = $this->container->get('twig')->getLoader(); + // when not in debug, try to find a template for the specific HTTP status code and format + if (!$showException) { + $template = sprintf('@ChamiloTheme/Exception/%s%s.%s.twig', $name, $code, $format); + if ($loader->exists($template)) { + return $template; + } + } + + // try to find a template for the given format + $template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format); + if ($loader->exists($template)) { + return $template; + } + + // default to a generic HTML exception + //$request->setRequestFormat('html'); + $template = sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name); + + return $this->render($template, ['exception' => $exception]); + } +} diff --git a/src/CoreBundle/Entity/Manager/SessionManager.php b/src/CoreBundle/Entity/Manager/SessionManager.php index 525f882950..8e677e98f0 100644 --- a/src/CoreBundle/Entity/Manager/SessionManager.php +++ b/src/CoreBundle/Entity/Manager/SessionManager.php @@ -8,7 +8,7 @@ use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\SessionRelUser; use Chamilo\UserBundle\Entity\User; -use Sonata\CoreBundle\Model\BaseEntityManager; +use Sonata\Doctrine\Entity\BaseEntityManager; /** * Class SessionManager. diff --git a/src/CoreBundle/Entity/Manager/SettingsCurrentManager.php b/src/CoreBundle/Entity/Manager/SettingsCurrentManager.php index 9714c1fe16..8a960995e4 100644 --- a/src/CoreBundle/Entity/Manager/SettingsCurrentManager.php +++ b/src/CoreBundle/Entity/Manager/SettingsCurrentManager.php @@ -4,7 +4,7 @@ namespace Chamilo\CoreBundle\Entity\Manager; -use Sonata\CoreBundle\Model\BaseEntityManager; +use Sonata\Doctrine\Entity\BaseEntityManager; /** * Class SettingsCurrentRepository. diff --git a/src/CoreBundle/Menu/NavBuilder.php b/src/CoreBundle/Menu/NavBuilder.php index 3b8e4093aa..adbbb006b8 100644 --- a/src/CoreBundle/Menu/NavBuilder.php +++ b/src/CoreBundle/Menu/NavBuilder.php @@ -11,6 +11,7 @@ use Knp\Menu\FactoryInterface; use Knp\Menu\ItemInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; +use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; /** * Class NavBuilder. @@ -20,10 +21,12 @@ class NavBuilder implements ContainerAwareInterface use ContainerAwareTrait; private $factory; + private $checker; - public function __construct(FactoryInterface $factory) + public function __construct(FactoryInterface $factory, AuthorizationChecker $checker) { $this->factory = $factory; + $this->checker = $checker; } /** @@ -60,7 +63,7 @@ class NavBuilder implements ContainerAwareInterface public function menuApp(array $options): ItemInterface { $container = $this->container; - $checker = $container->get('security.authorization_checker'); + $checker = $this->checker; $translator = $container->get('translator'); $router = $container->get('router'); $factory = $this->factory; diff --git a/src/CoreBundle/Resources/config/services.yml b/src/CoreBundle/Resources/config/services.yml index e0f85fa0e6..ef39d9faca 100644 --- a/src/CoreBundle/Resources/config/services.yml +++ b/src/CoreBundle/Resources/config/services.yml @@ -217,6 +217,9 @@ services: chamilo_core.menu.nav_builder: class: Chamilo\CoreBundle\Menu\NavBuilder + arguments: + - '@knp_menu.factory' + - '@security.authorization_checker' calls: - [setContainer, ['@service_container']] tags: diff --git a/src/ThemeBundle/Controller/ExceptionController.php b/src/ThemeBundle/Controller/ExceptionController.php deleted file mode 100644 index 1475d5c664..0000000000 --- a/src/ThemeBundle/Controller/ExceptionController.php +++ /dev/null @@ -1,54 +0,0 @@ -templateExists($template)) { - return $template; - } - } - - // try to find a template for the given format - $template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format); - if ($this->templateExists($template)) { - return $template; - } - - // default to a generic HTML exception - $request->setRequestFormat('html'); - - return sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name); - } -} diff --git a/src/ThemeBundle/Resources/views/Exception/exception_full.html.twig b/src/ThemeBundle/Resources/views/Exception/exception_full.html.twig index b73d88b2dd..f58750eeec 100644 --- a/src/ThemeBundle/Resources/views/Exception/exception_full.html.twig +++ b/src/ThemeBundle/Resources/views/Exception/exception_full.html.twig @@ -1,4 +1,5 @@ {% extends '@ChamiloTheme/Layout/base-layout.html.twig' %} + {% block page_title %} Error {% endblock %} {% block page_subtitle %} {{ status_code }} {% endblock %} {% block page_content %} diff --git a/src/ThemeBundle/Resources/views/Layout/sidebar.html.twig b/src/ThemeBundle/Resources/views/Layout/sidebar.html.twig index 666bd0682b..4d613b19a8 100644 --- a/src/ThemeBundle/Resources/views/Layout/sidebar.html.twig +++ b/src/ThemeBundle/Resources/views/Layout/sidebar.html.twig @@ -4,8 +4,7 @@ - {##} + {% endif %} {% endautoescape %} \ No newline at end of file