Skip to content

Commit

Permalink
Merge pull request #5764 from nanasess/fix-remove-cache-installer
Browse files Browse the repository at this point in the history
[4.2] インストーラでのプラグイン有効化/無効化時にキャッシュ削除が失敗する場合があるのを修正
  • Loading branch information
chihiro-adachi authored Sep 5, 2022
2 parents 81fe4c1 + 2dfb1a3 commit 2853db3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Eccube/Controller/InstallPluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
use Eccube\Service\PluginService;
use Eccube\Service\SystemService;
use Eccube\Util\CacheUtil;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Annotation\Route;

class InstallPluginController extends InstallController
Expand Down Expand Up @@ -77,14 +80,15 @@ public function plugins(Request $request)
* @param SystemService $systemService
* @param PluginService $pluginService
* @param string $code
* @param EventDispatcherInterface $dispatcher
*
* @return JsonResponse
*
* @throws BadRequestHttpException
* @throws NotFoundHttpException
* @throws PluginException
*/
public function pluginEnable(Request $request, SystemService $systemService, PluginService $pluginService, $code)
public function pluginEnable(Request $request, SystemService $systemService, PluginService $pluginService, $code, EventDispatcherInterface $dispatcher)
{
if (!$request->isXmlHttpRequest()) {
throw new BadRequestHttpException();
Expand Down Expand Up @@ -122,7 +126,12 @@ public function pluginEnable(Request $request, SystemService $systemService, Plu
}
}

$this->cacheUtil->clearCache();
// KernelEvents::TERMINATE で強制的にキャッシュを削除する
// see https://github.com/EC-CUBE/ec-cube/issues/5498#issuecomment-1205904083
$dispatcher->addListener(KernelEvents::TERMINATE, function () {
$fs = new Filesystem();
$fs->remove($this->getParameter('kernel.project_dir').'/var/cache/'.env('APP_ENV', 'prod'));
});

return $this->json(['success' => true, 'log' => $log]);
} else {
Expand Down

0 comments on commit 2853db3

Please sign in to comment.