helios-ag / FMElfinderBundle

:file_folder: ElFinderBundle provides ElFinder integration with TinyMCE, CKEditor, Summernote editors
MIT License
275 stars 128 forks source link

Symfony5 - elfinder:install #407

Closed featuriz closed 3 years ago

featuriz commented 4 years ago

Short description of what this feature will allow to do: 1. elfinder:install This comments install to public folder, not on project public folder. This is wrong.

Example of how to use this feature 1.elfinder:install This can be solved by adding ->addOption('path', NULL, InputOption::VALUE_OPTIONAL, 'Website document root.', 'public') to configure, and at execute $publicDir = $this->parameterBag->get('kernel.project_dir').'/'.$input->getOption('docroot').'/bundles/fmelfinder';

So that users can install this to any folder. I'm using public_html for my server config.

featuriz commented 4 years ago
<?php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Filesystem;

class ElfinderInstallCommand extends Command {

    private const ELFINDER_CSS_DIR = 'vendor/studio-42/elfinder/css';
    private const ELFINDER_JS_DIR = 'vendor/studio-42/elfinder/js';
    private const ELFINDER_SOUNDS_DIR = 'vendor/studio-42/elfinder/sounds';
    private const ELFINDER_IMG_DIR = 'vendor/studio-42/elfinder/img';

    protected static $defaultName = 'app:elfinder-install';
    protected $fileSystem, $parameterBag;

    public function __construct(Filesystem $filesystem, ParameterBagInterface $parameterBag) {
        $this->fileSystem = $filesystem;
        $this->parameterBag = $parameterBag;
        parent::__construct();
    }

    protected function configure() {
        $this
                ->setDescription('Copies elfinder assets to public directory')
                ->addOption('docroot', NULL, InputOption::VALUE_OPTIONAL, 'Website document root.', 'public_html')
                ->setHelp(<<<'EOF'
Default docroot:
  <info>public_html</info>

You can pass docroot:
  <info>Where to install elfinder</info>
  <info>php %command.full_name% --docroot=public_html</info>
EOF
        );
    }

    protected function execute(InputInterface $input, OutputInterface $output): int {
        $io = new SymfonyStyle($input, $output);
        $dr = $input->getOption('docroot');
        $io->title('elFinder Installer');
        $io->comment('Trying to install elfinder to "' . $dr . '" folder');
        $publicDir = $this->parameterBag->get('kernel.project_dir') . '/' . $dr . '/bundles/fmelfinder';
        $io->note('Starting to install elfinder to ' . $publicDir . ' folder');

        $this->fileSystem->mirror(self::ELFINDER_CSS_DIR, $publicDir . '/css');
        $this->fileSystem->mirror(self::ELFINDER_IMG_DIR, $publicDir . '/img');
        $this->fileSystem->mirror(self::ELFINDER_JS_DIR, $publicDir . '/js');
        $this->fileSystem->mirror(self::ELFINDER_SOUNDS_DIR, $publicDir . '/sounds');

        $io->success('elFinder assets successfully installed');

        return 0;
    }

}
flohw commented 3 years ago

@helios-ag could you please improve this command as it's a blocking point for CI/CD tasks. Maybe the documentation and CHANGELOG.md needs some update too.

Let us know if you need some help or PR on the project.

Thank you