diff --git a/composer.json b/composer.json index a19e278f98..3247e92582 100755 --- a/composer.json +++ b/composer.json @@ -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": "*", diff --git a/config/packages/oneup_flysystem.yaml b/config/packages/oneup_flysystem.yaml index b3fe011b1f..bd7a172d8d 100644 --- a/config/packages/oneup_flysystem.yaml +++ b/config/packages/oneup_flysystem.yaml @@ -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 diff --git a/config/packages/oneup_uploader.yaml b/config/packages/oneup_uploader.yaml index 5febc2d200..fadc15b1ce 100644 --- a/config/packages/oneup_uploader.yaml +++ b/config/packages/oneup_uploader.yaml @@ -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 diff --git a/config/packages/vich_uploader.yaml b/config/packages/vich_uploader.yaml index e3123bef53..76946a070c 100644 --- a/config/packages/vich_uploader.yaml +++ b/config/packages/vich_uploader.yaml @@ -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 diff --git a/config/services.yaml b/config/services.yaml index 36a905881a..d92e71a3bb 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -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 diff --git a/src/CoreBundle/Controller/AssetController.php b/src/CoreBundle/Controller/AssetController.php index 7ec8b1848d..0c1f4a1d41 100644 --- a/src/CoreBundle/Controller/AssetController.php +++ b/src/CoreBundle/Controller/AssetController.php @@ -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); diff --git a/src/CoreBundle/Controller/ResourceUploadController.php b/src/CoreBundle/Controller/ResourceUploadController.php index a6162e5640..b2fb1a80e4 100644 --- a/src/CoreBundle/Controller/ResourceUploadController.php +++ b/src/CoreBundle/Controller/ResourceUploadController.php @@ -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); diff --git a/src/CoreBundle/Entity/Listener/ResourceNodeListener.php b/src/CoreBundle/Entity/Listener/ResourceNodeListener.php index 89f55f2185..f640cab6ad 100644 --- a/src/CoreBundle/Entity/Listener/ResourceNodeListener.php +++ b/src/CoreBundle/Entity/Listener/ResourceNodeListener.php @@ -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); + } } } diff --git a/src/CoreBundle/EventListener/AssetListener.php b/src/CoreBundle/EventListener/AssetListener.php index f9844fcda8..75cbd774fa 100644 --- a/src/CoreBundle/EventListener/AssetListener.php +++ b/src/CoreBundle/EventListener/AssetListener.php @@ -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); } } } diff --git a/src/CoreBundle/EventListener/CourseListener.php b/src/CoreBundle/EventListener/CourseListener.php index f3978c1dbc..87d7dbbb60 100644 --- a/src/CoreBundle/EventListener/CourseListener.php +++ b/src/CoreBundle/EventListener/CourseListener.php @@ -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); diff --git a/src/CoreBundle/Repository/AssetRepository.php b/src/CoreBundle/Repository/AssetRepository.php index 46591816bf..034af273e2 100644 --- a/src/CoreBundle/Repository/AssetRepository.php +++ b/src/CoreBundle/Repository/AssetRepository.php @@ -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); diff --git a/src/CoreBundle/Repository/ResourceNodeRepository.php b/src/CoreBundle/Repository/ResourceNodeRepository.php index e19a0b37f7..1ca6e6e470 100644 --- a/src/CoreBundle/Repository/ResourceNodeRepository.php +++ b/src/CoreBundle/Repository/ResourceNodeRepository.php @@ -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