-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clear compiled option for versions, and allow disable recompile g… (
#285) * Add clear compiled option for versions, and allow disable recompile globally * Adapt Content test for clear_compiled option
- Loading branch information
Showing
21 changed files
with
280 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/EventListener/Admin/ContentVersion/ClearCompiledListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
namespace Softspring\CmsBundle\EventListener\Admin\ContentVersion; | ||
|
||
use Softspring\CmsBundle\Config\CmsConfig; | ||
use Softspring\CmsBundle\Manager\ContentManagerInterface; | ||
use Softspring\CmsBundle\Manager\ContentVersionManagerInterface; | ||
use Softspring\CmsBundle\Manager\RouteManagerInterface; | ||
use Softspring\CmsBundle\Model\ContentVersionInterface; | ||
use Softspring\CmsBundle\Render\ContentVersionCompiler; | ||
use Softspring\CmsBundle\Request\FlashNotifier; | ||
use Softspring\CmsBundle\SfsCmsEvents; | ||
use Softspring\Component\CrudlController\Event\ApplyEvent; | ||
use Softspring\Component\CrudlController\Event\ExceptionEvent; | ||
use Softspring\Component\CrudlController\Event\FailureEvent; | ||
use Softspring\Component\CrudlController\Event\SuccessEvent; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | ||
|
||
class ClearCompiledListener extends AbstractContentVersionListener | ||
{ | ||
protected const ACTION_NAME = 'version_clear_compiled'; | ||
|
||
public function __construct( | ||
ContentManagerInterface $contentManager, | ||
ContentVersionManagerInterface $contentVersionManager, | ||
RouteManagerInterface $routeManager, | ||
CmsConfig $cmsConfig, | ||
RouterInterface $router, | ||
FlashNotifier $flashNotifier, | ||
AuthorizationCheckerInterface $authorizationChecker, | ||
protected ContentVersionCompiler $contentVersionCompiler, | ||
) { | ||
parent::__construct($contentManager, $contentVersionManager, $routeManager, $cmsConfig, $router, $flashNotifier, $authorizationChecker); | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
SfsCmsEvents::ADMIN_CONTENT_VERSIONS_CLEAR_COMPILED_INITIALIZE => [ | ||
['onInitializeGetConfig', 20], | ||
['onEventDispatchContentTypeEvent', 10], | ||
['onEventLoadContentEntity', 9], | ||
['onInitializeIsGranted', 0], | ||
], | ||
SfsCmsEvents::ADMIN_CONTENT_VERSIONS_CLEAR_COMPILED_LOAD_ENTITY => [ | ||
['onEventDispatchContentTypeEvent', 10], | ||
['onLoadEntity', 0], | ||
], | ||
SfsCmsEvents::ADMIN_CONTENT_VERSIONS_CLEAR_COMPILED_NOT_FOUND => [ | ||
['onEventDispatchContentTypeEvent', 10], | ||
['onNotFound', 0], | ||
], | ||
SfsCmsEvents::ADMIN_CONTENT_VERSIONS_CLEAR_COMPILED_FOUND => [ | ||
['onEventDispatchContentTypeEvent', 10], | ||
], | ||
SfsCmsEvents::ADMIN_CONTENT_VERSIONS_CLEAR_COMPILED_APPLY => [ | ||
['onEventDispatchContentTypeEvent', 10], | ||
['onApply', 0], | ||
], | ||
SfsCmsEvents::ADMIN_CONTENT_VERSIONS_CLEAR_COMPILED_SUCCESS => [ | ||
['onEventDispatchContentTypeEvent', 10], | ||
['onSuccess', 0], | ||
], | ||
SfsCmsEvents::ADMIN_CONTENT_VERSIONS_CLEAR_COMPILED_FAILURE => [ | ||
['onEventDispatchContentTypeEvent', 10], | ||
['onFailure', 0], | ||
], | ||
SfsCmsEvents::ADMIN_CONTENT_VERSIONS_CLEAR_COMPILED_EXCEPTION => [ | ||
['onEventDispatchContentTypeEvent', 10], | ||
['onException', 0], | ||
], | ||
]; | ||
} | ||
|
||
public function onApply(ApplyEvent $event): void | ||
{ | ||
/** @var ContentVersionInterface $entity */ | ||
$entity = $event->getEntity(); | ||
|
||
$entity->setKeep($event->getRequest()->attributes->get('recompile') ?: false); | ||
|
||
$this->contentVersionCompiler->clearCompiled($entity); | ||
|
||
$this->contentVersionManager->saveEntity($entity); | ||
|
||
$event->setApplied(true); | ||
} | ||
|
||
public function onSuccess(SuccessEvent $event): void | ||
{ | ||
$contentConfig = $event->getRequest()->attributes->get('_content_config'); | ||
|
||
/** @var ContentVersionInterface $version */ | ||
$version = $event->getEntity(); | ||
|
||
$this->flashNotifier->addTrans('success', "admin_{$contentConfig['_id']}.version_clear_compiled.success_flash", [], 'sfs_cms_contents'); | ||
|
||
$content = $event->getRequest()->attributes->get('content'); | ||
|
||
$event->setResponse($this->redirectBack($contentConfig['_id'], $content, $event->getRequest(), $version)); | ||
} | ||
|
||
public function onFailure(FailureEvent $event): void | ||
{ | ||
$contentConfig = $event->getRequest()->attributes->get('_content_config'); | ||
|
||
/** @var ContentVersionInterface $version */ | ||
$version = $event->getEntity(); | ||
|
||
$this->flashNotifier->addTrans('error', "admin_{$contentConfig['_id']}.version_clear_compiled.failed_flash", ['%exception%' => $this->extractExceptionMessage($event->getException())], 'sfs_cms_contents'); | ||
|
||
$content = $event->getRequest()->attributes->get('content'); | ||
|
||
$event->setResponse($this->redirectBack($contentConfig['_id'], $content, $event->getRequest(), $version)); | ||
} | ||
|
||
public function onException(ExceptionEvent $event): void | ||
{ | ||
$contentConfig = $event->getRequest()->attributes->get('_content_config'); | ||
|
||
/** @var ?ContentVersionInterface $version */ | ||
$version = $event->getRequest()->attributes->get('version'); | ||
|
||
$this->flashNotifier->addTrans('error', "admin_{$contentConfig['_id']}.version_clear_compiled.failed_flash", ['%exception%' => $this->extractExceptionMessage($event->getException())], 'sfs_cms_contents'); | ||
|
||
$content = $event->getRequest()->attributes->get('content'); | ||
|
||
$event->setResponse($this->redirectBack($contentConfig['_id'], $content, $event->getRequest(), $version)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.