Update flysystem, update composer libs

pull/3844/head
Julio Montoya 4 years ago
parent 748bcdb1c5
commit 0ba7080714
  1. 16
      composer.json
  2. 21
      config/packages/oneup_flysystem.yaml
  3. 6
      config/packages/oneup_uploader.yaml
  4. 4
      config/packages/vich_uploader.yaml
  5. 16
      config/services.yaml
  6. 4
      src/CoreBundle/Controller/AssetController.php
  7. 4
      src/CoreBundle/Controller/ResourceUploadController.php
  8. 6
      src/CoreBundle/Entity/Listener/ResourceNodeListener.php
  9. 2
      src/CoreBundle/EventListener/AssetListener.php
  10. 2
      src/CoreBundle/EventListener/CourseListener.php
  11. 42
      src/CoreBundle/Repository/AssetRepository.php
  12. 16
      src/CoreBundle/Repository/ResourceNodeRepository.php

@ -57,7 +57,7 @@
"api-platform/core": "^2.6",
"beberlei/doctrineextensions": "^1.2",
"chamilo/settings-bundle": "dev-master",
"clue/graph": "~0.9",
"clue/graph": "^0.9.2",
"cocur/slugify": "^4.0",
"doctrine/data-fixtures": "~1.0",
"doctrine/dbal": "~2.0",
@ -86,16 +86,16 @@
"laminas/laminas-filter": "~2.9",
"laminas/laminas-permissions-acl": "~2.7",
"league/csv": "^9.1",
"league/flysystem-ziparchive": "^1.0",
"league/glide-symfony": "^1.0",
"league/glide-symfony": "dev-master",
"maennchen/zipstream-php": "^2.0",
"masterminds/html5": "^2.0",
"michelf/php-markdown": "~1.8",
"mpdf/mpdf": "~8.0",
"nelexa/zip": "^4.0",
"nesbot/carbon": "^2.33",
"oneup/flysystem-bundle": "~3.0",
"oneup/flysystem-bundle": "~4.0",
"oneup/uploader-bundle": "~3.0",
"pagerfanta/pagerfanta": "~2.0",
"pagerfanta/pagerfanta": "~3.0",
"paragonie/random-lib": "~2.0",
"php-ffmpeg/php-ffmpeg": "~0.14",
"phpoffice/phpspreadsheet": "~1.16",
@ -137,11 +137,11 @@
"symfony/web-link": "^5.0",
"symfony/webpack-encore-bundle": "^1.7",
"symfony/yaml": "^5.0",
"symfonycasts/reset-password-bundle": "^1.3",
"symfonycasts/reset-password-bundle": "^1.5",
"szymach/c-pchart": "^3.0",
"tgalopin/html-sanitizer-bundle": "^1.1",
"twig/intl-extra": "^3.0",
"vich/uploader-bundle": "^1.13",
"vich/uploader-bundle": "dev-master",
"webit/eval-math": "^1.0"
},
"config": {
@ -164,7 +164,7 @@
"symfony/browser-kit": "^4.0|^5.0",
"symfony/css-selector": "^5.0",
"symfony/debug-pack": "*",
"symfony/maker-bundle": "^1.15",
"symfony/maker-bundle": "1.30",
"symfony/phpunit-bridge": "^5.0",
"symfony/profiler-pack": "*",
"symfony/test-pack": "*",

@ -1,26 +1,23 @@
oneup_flysystem:
cache:
my_cache:
memory: ~
adapters:
asset_adapter:
local:
directory: '%kernel.project_dir%/var/upload/assets'
location: '%kernel.project_dir%/var/upload/assets'
resource_adapter:
local:
directory: '%kernel.project_dir%/var/upload/resource'
location: '%kernel.project_dir%/var/upload/resource'
resource_cache_adapter:
local:
directory: '%kernel.project_dir%/var/cache/resource'
location: '%kernel.project_dir%/var/cache/resource'
filesystems:
assets:
asset:
adapter: asset_adapter
mount: assets_fs
resources:
mount: asset
resource:
adapter: resource_adapter
mount: resources_fs
mount: resource
visibility: private
cache_resources:
resource_cache:
adapter: resource_cache_adapter
mount: cache_resources_fs
mount: resource_cache
visibility: private

@ -2,15 +2,11 @@
oneup_uploader:
mappings:
resource:
#frontend: dropzone # or any uploader you use in the frontend
#frontend: blueimp
frontend: custom
storage:
type: flysystem
filesystem: oneup_flysystem.resources_filesystem
filesystem: oneup_flysystem.resource_filesystem
root_folder: true
custom_frontend:
class: 'Chamilo\CoreBundle\Controller\ResourceUploadController'
name: upload
# namer: oneup_uploader.namer.urlsafe

@ -5,7 +5,7 @@ vich_uploader:
mappings:
resources:
uri_prefix: ''
upload_destination: resources_fs
upload_destination: oneup_flysystem.resource_filesystem
namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
directory_namer:
service: Vich\UploaderBundle\Naming\SubdirDirectoryNamer
@ -15,7 +15,7 @@ vich_uploader:
delete_on_remove: true
assets:
uri_prefix: ''
upload_destination: assets_fs
upload_destination: asset_filesystem
namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
directory_namer:
service: Chamilo\CoreBundle\Component\Utils\AssetDirectoryNamer

@ -55,7 +55,7 @@ services:
Chamilo\CoreBundle\Component\Utils\NameConvention: ~
Chamilo\CoreBundle\Component\Utils\Glide:
arguments:
- {source: '@oneup_flysystem.resources_filesystem', cache: '@oneup_flysystem.cache_resources_filesystem'}
- {source: '@oneup_flysystem.resource_filesystem', cache: '@oneup_flysystem.resource_cache_filesystem'}
- '%glide_media_filters%'
# makes classes in src/ available to be used as services
@ -80,8 +80,6 @@ services:
class: Chamilo\LtiBundle\Util\Utils
arguments: ['@chamilo.settings.manager']
League\Flysystem\MountManager: '@oneup_flysystem.mount_manager'
Chamilo\CoreBundle\EventListener\HTTPExceptionListener:
tags:
- {name: kernel.event_listener, event: kernel.exception}
@ -91,12 +89,12 @@ services:
tags:
- {name: kernel.event_listener, event: kernel.exception}
sylius_settings:
driver: doctrine/orm
# Course settings
chamilo_course:
driver: doctrine/orm
#sylius_settings:
# driver: doctrine/orm
#
## Course settings
#chamilo_course:
# driver: doctrine/orm
# gregwar_captcha:
# width: 200

@ -30,8 +30,8 @@ class AssetController
public function showFile($category, $path, AssetRepository $assetRepository)
{
$filePath = $category.'/'.$path;
$has = $assetRepository->getFileSystem()->has($filePath);
if ($has) {
$exists = $assetRepository->getFileSystem()->fileExists($filePath);
if ($exists) {
$fileName = basename($filePath);
$stream = $assetRepository->getFileSystem()->readStream($filePath);

@ -51,8 +51,8 @@ class ResourceUploadController extends BlueimpController
$session = $doctrine->getRepository(Session::class)->find($sessionId);
}
$token = $container->get('security.token_storage')->getToken();
$user = $token->getUser();
/*$token = $container->get('security.token_storage')->getToken();
$user = $token->getUser();*/
// Create repository from tool and type.
$factory = $container->get(ResourceFactory::class);

@ -52,14 +52,16 @@ class ResourceNodeListener
public function preUpdate(ResourceNode $resourceNode, PreUpdateEventArgs $event)
{
error_log('resource node preUpdate');
if ($resourceNode->hasResourceFile() && $resourceNode->hasEditableTextContent()) {
$fileName = $this->resourceNodeRepository->getFilename($resourceNode->getResourceFile());
error_log(sprintf('fileName: %s', $fileName));
if ($fileName) {
error_log('updated');
$content = $resourceNode->getContent();
$this->resourceNodeRepository->getFileSystem()->update($fileName, $content);
// Skip saving null.
if (null !== $content) {
$this->resourceNodeRepository->getFileSystem()->write($fileName, $content);
}
}
}

@ -30,7 +30,7 @@ class AssetListener
// Deletes scorm folder: example: assets/scorm/myABC .
if (Asset::SCORM === $asset->getCategory() && !empty($folder)) {
$folder = Asset::SCORM.'/'.$folder;
$this->assetRepository->getFileSystem()->deleteDir($folder);
$this->assetRepository->getFileSystem()->deleteDirectory($folder);
}
}
}

@ -149,7 +149,6 @@ class CourseListener
if (!$session->hasCourse($course)) {
throw new AccessDeniedException($translator->trans('Course is not registered in the Session'));
}
//$course->setCurrentSession($session);
$session->setCurrentCourse($course);
// Check if user is allowed to this course-session
@ -157,7 +156,6 @@ class CourseListener
if (false === $checker->isGranted(SessionVoter::VIEW, $session)) {
throw new AccessDeniedException($translator->trans('Unauthorised access to session!'));
}
$sessionHandler->set('session_name', $session->getName());
$sessionHandler->set('sid', $session->getId());
$sessionHandler->set('session', $session);

@ -9,34 +9,29 @@ namespace Chamilo\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\Asset;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\MountManager;
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use League\Flysystem\FilesystemOperator;
use PhpZip\ZipFile;
use Symfony\Component\Routing\RouterInterface;
use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
class AssetRepository extends ServiceEntityRepository
{
protected MountManager $mountManager;
protected RouterInterface $router;
protected UploaderHelper $uploaderHelper;
protected FilesystemOperator $filesystem;
public function __construct(ManagerRegistry $registry, RouterInterface $router, MountManager $mountManager, UploaderHelper $uploaderHelper)
public function __construct(ManagerRegistry $registry, RouterInterface $router, UploaderHelper $uploaderHelper, FilesystemOperator $assetFilesystem)
{
parent::__construct($registry, Asset::class);
$this->router = $router;
$this->mountManager = $mountManager;
$this->uploaderHelper = $uploaderHelper;
// Flysystem mount name is saved in config/packages/oneup_flysystem.yaml
$this->filesystem = $assetFilesystem;
}
/**
* @return FilesystemInterface
*/
public function getFileSystem()
{
// Flysystem mount name is saved in config/packages/oneup_flysystem.yaml
return $this->mountManager->getFilesystem('assets_fs');
return $this->filesystem;
}
/*public function getUploaderHelper(): UploaderHelper
@ -44,26 +39,28 @@ class AssetRepository extends ServiceEntityRepository
return $this->uploaderHelper;
}*/
public function unZipFile(Asset $asset, ZipArchiveAdapter $zipArchiveAdapter): void
public function unZipFile(Asset $asset, ZipFile $zipFile): void
{
$folder = '/'.$asset->getCategory().'/'.$asset->getTitle();
$fs = $this->getFileSystem();
if ($fs->has($folder)) {
$contents = $zipArchiveAdapter->listContents();
foreach ($contents as $data) {
if ($fs->has($folder.'/'.$data['path'])) {
if ($fs->fileExists($folder)) {
$list = $zipFile->getEntries();
foreach ($list as $item) {
$name = $item->getName();
if ($fs->fileExists($folder.'/'.$name)) {
continue;
}
if ('dir' === $data['type']) {
$fs->createDir($folder.'/'.$data['path']);
if ($item->isDirectory()) {
$fs->createDirectory($folder.'/'.$name);
continue;
}
$content = (string) $zipArchiveAdapter->read($data['path']);
$fs->write($folder.'/'.$data['path'], $content);
$content = $zipFile->getEntryContents($name);
$fs->write($folder.'/'.$name, $content);
}
}
}
@ -91,8 +88,7 @@ class AssetRepository extends ServiceEntityRepository
);
}
// Classic
// Classic.
$helper = $this->uploaderHelper;
return '/assets'.$helper->asset($asset);

@ -14,22 +14,22 @@ use Chamilo\CoreBundle\Entity\ResourceType;
use Chamilo\CoreBundle\Entity\Session;
use Doctrine\ORM\EntityManagerInterface;
use Gedmo\Tree\Entity\Repository\MaterializedPathRepository;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\MountManager;
use League\Flysystem\FilesystemOperator;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
use Throwable;
use Vich\UploaderBundle\Storage\FlysystemStorage;
class ResourceNodeRepository extends MaterializedPathRepository
{
protected MountManager $mountManager;
protected FlysystemStorage $storage;
protected FilesystemOperator $filesystem;
public function __construct(EntityManagerInterface $manager, FlysystemStorage $storage, MountManager $mountManager)
public function __construct(EntityManagerInterface $manager, FlysystemStorage $storage, FilesystemOperator $resourceFilesystem)
{
parent::__construct($manager, $manager->getClassMetadata(ResourceNode::class));
$this->storage = $storage;
$this->mountManager = $mountManager;
// Flysystem mount name is saved in config/packages/oneup_flysystem.yaml
$this->filesystem = $resourceFilesystem;
}
public function getFilename(ResourceFile $resourceFile): ?string
@ -52,13 +52,9 @@ class ResourceNodeRepository extends MaterializedPathRepository
}
}*/
/**
* @return FilesystemInterface
*/
public function getFileSystem()
{
// Flysystem mount name is saved in config/packages/oneup_flysystem.yaml @todo add it as a service.
return $this->mountManager->getFilesystem('resources_fs');
return $this->filesystem;
}
public function getResourceNodeFileContent(ResourceNode $resourceNode): string

Loading…
Cancel
Save