From d8d0e7ff5ec1fa2c3e473ef876b1d699468d606b Mon Sep 17 00:00:00 2001 From: Julio Date: Tue, 8 Oct 2019 15:55:42 +0200 Subject: [PATCH] Use VichUploaderBundle with flysystem for resources --- composer.json | 5 ++- config/bundles.php | 1 + config/packages/liip_imagine.yaml | 4 +- config/packages/oneup_flysystem.yaml | 40 ++----------------- config/packages/oneup_uploader.yaml | 13 +----- config/services.yaml | 3 ++ .../Controller/ResourceDownloadController.php | 6 +-- .../Resources/views/Resource/upload.html.twig | 2 +- 8 files changed, 18 insertions(+), 56 deletions(-) diff --git a/composer.json b/composer.json index 535cac79f9..bd6abfc89b 100755 --- a/composer.json +++ b/composer.json @@ -102,7 +102,7 @@ "stephpy/timeline-bundle": "~3.0", "stof/doctrine-extensions-bundle": "~1.3", "sunra/php-simple-html-dom-parser": "~1.5.0", - "sylius/resource-bundle": "~1.5", + "sylius/resource-bundle": "~1.6", "friendsofsymfony/jsrouting-bundle": "~2.0", "gedmo/doctrine-extensions": "~2.4", @@ -159,7 +159,8 @@ "simplethings/entity-audit-bundle": "^1.0", "masterminds/html5": "2.*", "league/csv": "^9.1", - "brumann/polyfill-unserialize": "^1.0" + "brumann/polyfill-unserialize": "^1.0", + "vich/uploader-bundle": "1.8.*" }, "config": { "component-dir": "public/assets" diff --git a/config/bundles.php b/config/bundles.php index 24f5aa448c..445f95d3cb 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -78,4 +78,5 @@ return [ Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true], HtmlSanitizer\Bundle\HtmlSanitizerBundle::class => ['all' => true], + Vich\UploaderBundle\VichUploaderBundle::class => ['all' => true], ]; diff --git a/config/packages/liip_imagine.yaml b/config/packages/liip_imagine.yaml index e96a3f2b27..1345736661 100644 --- a/config/packages/liip_imagine.yaml +++ b/config/packages/liip_imagine.yaml @@ -8,9 +8,9 @@ liip_imagine: web_path: cache_prefix: '../var/cache/resource' loaders: - default: + resources: filesystem: - data_root: '%kernel.root_dir%/../var/upload/resource' + data_root: '%kernel.root_dir%/../var/upload/resource2' filter_sets: # Chamilo filters hotspot_question: diff --git a/config/packages/oneup_flysystem.yaml b/config/packages/oneup_flysystem.yaml index 3605b01b9d..048148501a 100644 --- a/config/packages/oneup_flysystem.yaml +++ b/config/packages/oneup_flysystem.yaml @@ -1,43 +1,11 @@ oneup_flysystem: adapters: - courses_adapter: - local: - directory: '%kernel.project_dir%/var/courses' - - home_adapter: - local: - directory: '%kernel.project_dir%/var/home' - resource_adapter: local: - directory: '%kernel.project_dir%/var/upload/resource' - -# resource_private_adapter: -# local: -# directory: '%kernel.project_dir%/var/upload/resource' -# -# resource_public_adapter: -# local: -# directory: '%kernel.project_dir%/public/upload/resource' + directory: '%kernel.project_dir%/var/upload/resource2' filesystems: - courses: - adapter: courses_adapter - visibility: private - cache: ~ - alias: ~ - mount: ~ - - home: - adapter: home_adapter - visibility: private - alias: home_filesystem - - resource: + resources: adapter: resource_adapter - -# resource_public: -# adapter: resource_public_adapter -# -# resource_private: -# adapter: resource_private_adapter + mount: resources_fs + visibility: private diff --git a/config/packages/oneup_uploader.yaml b/config/packages/oneup_uploader.yaml index e64ce13604..a0060f33d8 100644 --- a/config/packages/oneup_uploader.yaml +++ b/config/packages/oneup_uploader.yaml @@ -1,24 +1,13 @@ # Read the documentation: https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md oneup_uploader: mappings: - courses: - #frontend: dropzone # or any uploader you use in the frontend - #frontend: blueimp - frontend: custom - storage: - type: flysystem - filesystem: oneup_flysystem.courses_filesystem - root_folder: true - custom_frontend: - class: Chamilo\CoreBundle\Controller\ResourceUploaderController - name: courses resource: #frontend: dropzone # or any uploader you use in the frontend #frontend: blueimp frontend: custom storage: type: flysystem - filesystem: oneup_flysystem.resource_filesystem + filesystem: oneup_flysystem.resources_filesystem root_folder: true custom_frontend: class: Chamilo\CoreBundle\Controller\ResourceUploaderController diff --git a/config/services.yaml b/config/services.yaml index 1a62ca9fad..d24a6c6a6f 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -30,6 +30,9 @@ services: exclude: '../src/PageBundle/{Entity,Migrations,Tests}' public: true + Vich\UploaderBundle\Naming\SubdirDirectoryNamer: + public: true + Chamilo\ThemeBundle\: autowire: true resource: '../src/ThemeBundle/*' diff --git a/src/CoreBundle/Controller/ResourceDownloadController.php b/src/CoreBundle/Controller/ResourceDownloadController.php index 09034cecd8..deba9e01ea 100644 --- a/src/CoreBundle/Controller/ResourceDownloadController.php +++ b/src/CoreBundle/Controller/ResourceDownloadController.php @@ -35,7 +35,7 @@ class ResourceDownloadController extends BaseController //$helper = $this->container->get('oneup_uploader.templating.uploader_helper'); //$endpoint = $helper->endpoint('courses'); return $this->render( - '@ChamiloTheme/Resource/upload.html.twig', + '@ChamiloCore/Resource/upload.html.twig', [ 'identifier' => $id, 'type' => $type, @@ -58,7 +58,7 @@ class ResourceDownloadController extends BaseController { try { /** @var Filesystem $fs */ - $fs = $this->container->get('oneup_flysystem.courses_filesystem'); + $fs = $this->container->get('oneup_flysystem.resources_filesystem'); $file = $request->get('file'); $path = $course.'/document/'.$file; @@ -117,7 +117,7 @@ class ResourceDownloadController extends BaseController { try { /** @var Filesystem $fs */ - $fs = $this->container->get('oneup_flysystem.courses_filesystem'); + $fs = $this->container->get('oneup_flysystem.resources_filesystem'); $file = $request->get('file'); $path = $course.'/document/'.$file; diff --git a/src/CoreBundle/Resources/views/Resource/upload.html.twig b/src/CoreBundle/Resources/views/Resource/upload.html.twig index cc52b044ad..c530ccb692 100644 --- a/src/CoreBundle/Resources/views/Resource/upload.html.twig +++ b/src/CoreBundle/Resources/views/Resource/upload.html.twig @@ -15,7 +15,7 @@ {% endblock %}