Skip to content

Commit

Permalink
プラグインのインストール、有効時に.maintenanceファイルを作成するよう実装
Browse files Browse the repository at this point in the history
  • Loading branch information
kanako-kina committed Nov 20, 2018
1 parent 50d4d2f commit 99a126b
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions src/Eccube/Controller/Admin/Store/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@
use Eccube\Service\Composer\ComposerServiceInterface;
use Eccube\Service\PluginApiService;
use Eccube\Service\PluginService;
use Eccube\Service\SystemService;
use Eccube\Util\CacheUtil;
use Eccube\Util\StringUtil;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;


class PluginController extends AbstractController
{
/**
Expand All @@ -62,11 +66,17 @@ class PluginController extends AbstractController
* @var PluginApiService
*/
protected $pluginApiService;

/**
* @var ComposerServiceInterface
*/
private $composerService;

/**
* @var SystemService
*/
private $systemService;

/**
* PluginController constructor.
*
Expand All @@ -79,13 +89,20 @@ class PluginController extends AbstractController
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function __construct(PluginRepository $pluginRepository, PluginService $pluginService, BaseInfoRepository $baseInfoRepository, PluginApiService $pluginApiService, ComposerServiceInterface $composerService)
{
public function __construct(
PluginRepository $pluginRepository,
PluginService $pluginService,
BaseInfoRepository $baseInfoRepository,
PluginApiService $pluginApiService,
ComposerServiceInterface $composerService,
SystemService $systemService
){
$this->pluginRepository = $pluginRepository;
$this->pluginService = $pluginService;
$this->BaseInfo = $baseInfoRepository->get();
$this->pluginApiService = $pluginApiService;
$this->composerService = $composerService;
$this->systemService = $systemService;
}

/**
Expand Down Expand Up @@ -256,8 +273,17 @@ public function update(Request $request, Plugin $Plugin, CacheUtil $cacheUtil)
*
* @throws PluginException
*/
public function enable(Plugin $Plugin, CacheUtil $cacheUtil, Request $request)
public function enable(Plugin $Plugin, CacheUtil $cacheUtil, Request $request, EventDispatcherInterface $dispatcher)
{
// .maintenanceファイルを設置
$this->systemService->switchMaintenance(true);

// TERMINATE時のイベントを設定
$dispatcher->addListener(KernelEvents::TERMINATE, function () {
// .maintenanceファイルを削除
$this->systemService->switchMaintenance();
});

$this->isTokenValid();

$cacheUtil->clearCache();
Expand Down Expand Up @@ -335,8 +361,17 @@ public function enable(Plugin $Plugin, CacheUtil $cacheUtil, Request $request)
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|RedirectResponse
*/
public function disable(Request $request, Plugin $Plugin, CacheUtil $cacheUtil)
public function disable(Request $request, Plugin $Plugin, CacheUtil $cacheUtil, EventDispatcherInterface $dispatcher)
{
// .maintenanceファイルを設置
$this->systemService->switchMaintenance(true);

// TERMINATE時のイベントを設定
$dispatcher->addListener(KernelEvents::TERMINATE, function () {
// .maintenanceファイルを削除
$this->systemService->switchMaintenance();
});

$this->isTokenValid();

$cacheUtil->clearCache();
Expand Down Expand Up @@ -401,8 +436,18 @@ public function disable(Request $request, Plugin $Plugin, CacheUtil $cacheUtil)
*
* @throws \Exception
*/
public function uninstall(Plugin $Plugin, CacheUtil $cacheUtil)
public function uninstall(Plugin $Plugin, CacheUtil $cacheUtil, EventDispatcherInterface $dispatcher)
{
die();
// .maintenanceファイルを設置
$this->systemService->switchMaintenance(true);

// TERMINATE時のイベントを設定
$dispatcher->addListener(KernelEvents::TERMINATE, function () {
// .maintenanceファイルを削除
$this->systemService->switchMaintenance();
});

$this->isTokenValid();

if ($Plugin->isEnabled()) {
Expand Down

0 comments on commit 99a126b

Please sign in to comment.