-
Notifications
You must be signed in to change notification settings - Fork 130
Command execution events + subrequests support + volume_id setting #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I've made this PR as I talk about in #126 (multiple thumbnails). In my opinion it looks better to do like this than in #126 . First I've set the namespace AppBundle\EventListener\ElFinder;
use FM\ElfinderBundle\Event\ElFinderEvents;
abstract class ExecutionListener
{
/**
* Performs a subrequest to elFinderBundle to return informations.
* @param ElFinderEvents $event
* @return array
*/
protected function getInfos(ElFinderEvents $event)
{
$queryParameters = $event->getRequest()->query->all();
$queryParameters['cmd'] = 'info';
if (isset($queryParameters['target']) && !isset($queryParameters['targets'])) {
$queryParameters['targets'] = array($queryParameters['target']);
unset($queryParameters['target']);
}
$jsonResponse = $event->subRequest(array(
'instance' => $event->getInstance(),
'homeFolder' => $event->getHomeFolder()
), $queryParameters);
$filesInfos = json_decode($jsonResponse->getContent());
return $filesInfos->files;
}
} namespace AppBundle\EventListener\ElFinder;
use Liip\ImagineBundle\Controller\ImagineController;
use FM\ElfinderBundle\Event\ElFinderPostExecutionEvent;
use Symfony\Component\HttpFoundation\Request;
class PostExecutionListener extends ExecutionListener
{
/**
* LiipImagineBundle Controller
* @var ImagineController
*/
private $imagineController;
/**
* Constructor.
* @param ImagineController $imagineController
*/
public function __construct(ImagineController $imagineController)
{
$this->imagineController = $imagineController;
}
/**
* Manages thumbnails creation.
* @param ElFinderPostExecutionEvent $event
*/
public function onPostExecute(ElFinderPostExecutionEvent $event)
{
if (!$event->hasErrors() && $event->getCommand() == 'tmb') {
$this->createThumbnails($event);
}
}
/**
* Creates picture's thumbnails with LiipImagineBundle.
* @param ElFinderPostExecutionEvent $event
*/
private function createThumbnails(ElFinderPostExecutionEvent $event)
{
$imagesInfos = $this->getInfos($event);
$request = new Request();
foreach ($imagesInfos as $imageInfo) {
$path = '/'.$imageInfo->path;
$this->imagineController->filterAction($request, $path, 'tmb_64');
$this->imagineController->filterAction($request, $path, 'tmb_128');
}
}
} namespace AppBundle\EventListener\ElFinder;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use FM\ElfinderBundle\Event\ElFinderPreExecutionEvent;
class PreExecutionListener extends ExecutionListener
{
/**
* LiipImagineBundle CacheManager
* @var CacheManager
*/
private $cacheManager;
/**
* Constructor.
* @param CacheManager $cacheManager
*/
public function __construct(CacheManager $cacheManager)
{
$this->cacheManager = $cacheManager;
}
/**
* Manages thumbnails delete.
* @param ElFinderPreExecutionEvent $event
*/
public function onPreExecute(ElFinderPreExecutionEvent $event)
{
$command = $event->getCommand();
if ($command == 'rm' || $command == 'rename' || $command == 'resize') {
$this->removeThumbnails($event);
}
}
/**
* Removes picture's thumbnails created with LiipImagineBundle.
* @param ElFinderPreExecutionEvent $event
*/
private function removeThumbnails(ElFinderPreExecutionEvent $event)
{
$imagesInfos = $this->getInfos($event);
foreach ($imagesInfos as $imageInfo) {
$path = '/'.$imageInfo->path;
$this->cacheManager->remove($path);
}
}
} |
|
||
return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this became incompatible with 2.3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, compatible with ElFinderPHP pull request # 19
Hi @helios-ag , Do you have some news about it? |
Hi @nicolasmure, well it looks better of course. Anyway i support 2.3 in a separate branch. I could accept this if you can rebase PR. I will hold accepting PRs if you wish. |
OK, I was just wondering if you were interested by this or not. Thank you 😉 |
Command execution events + subrequests support + volume_id setting
thank you @helios-ag 😉 please do not forget that this PR is related to PR # 19 on the lib side |
👍 |
Changes Unknown when pulling b2bfad3 on nicolasmure:event-dispatcher into * on helios-ag:master*. |
Hi,
This PR provides events on elFinder command execution (pre and post).
It also allows to make subrequests to relaunch an elFinder command.
A new setting has been added :
volume_id
, necessary to keep the volume identifier when making subrequests on the same volume than the main request.Related to # 19 on the lib side.