Skip to content

Commit

Permalink
Merge pull request #5 from chihiro-adachi/fix-conflict-routing
Browse files Browse the repository at this point in the history
GMCプラグインとルーティングが競合する問題を修正
  • Loading branch information
Kiyotaka Oku committed Sep 9, 2021
2 parents 50e2e36 + a42d9a1 commit 351f62a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
41 changes: 33 additions & 8 deletions Controller/Admin/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Eccube\Controller\AbstractController;
use Eccube\Entity\Member;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Service\SystemService;
use Eccube\Util\CacheUtil;
use Eccube\Util\StringUtil;
use Google_Service_SiteVerification;
use Google_Service_Webmasters;
Expand All @@ -24,14 +26,16 @@
use Plugin\SiteKit\Repository\IdTokenRepository;
use Plugin\SiteKit\Service\Google_Site_Kit_Client;
use Plugin\SiteKit\Service\Google_Site_Kit_Proxy_Client;
use Plugin\SiteKit\Service\SiteKitClientFactory;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Yaml\Yaml;

class ConfigController extends AbstractController
{
Expand Down Expand Up @@ -114,20 +118,22 @@ public function analyticsCallback()
{
}

/**
* @Route("/google{token}.html")
*/
public function siteVerification(string $token)
public function siteVerification()
{
$verificationToken = file_get_contents($this->eccubeConfig['plugin_data_realdir'].'/SiteKit/google-site-verification.txt');
return new Response($verificationToken);
$file = $this->eccubeConfig['plugin_data_realdir'].'/SiteKit/google-site-verification.txt';
if (file_exists($file)) {
$verificationToken = file_get_contents($file);
return new Response($verificationToken);
}

throw new NotFoundHttpException();
}

/**
* @Route("/%eccube_admin_route%/cube_kit/action_callback", name="site_kit_action_callback", methods={"GET"})
* @Route("/cube_kit/action_callback", methods={"GET"})
*/
public function actionCallback(Request $request)
public function actionCallback(Request $request, CacheUtil $cacheUtil, SystemService $systemService, RouterInterface $router)
{
$nonce = $this->session->get(self::SESSION_KEY_SITE_KIT_NONCE);
if ($nonce !== $request->get('nonce')) {
Expand All @@ -142,6 +148,25 @@ public function actionCallback(Request $request)
$this->eccubeConfig['plugin_data_realdir'].'/SiteKit/google-site-verification.txt',
'google-site-verification: '.$token
);

$systemService->switchMaintenance(true);

// ルーティング生成
$yaml = Yaml::dump([
'site_kit_google_site_verification' => [
'path' => '/google'.$token.'.html',
'controller' => 'Plugin\SiteKit\Controller\Admin\ConfigController::siteVerification',
]
]);
$filesystem->dumpFile(
$this->eccubeConfig['plugin_data_realdir'].'/SiteKit/routes.yaml',
$yaml);

$cacheUtil->clearCache();

// sitekit.withgoogle.comへリダイレクトするため、画面描画後のメンテナンス解除ができない。
// 従来のEventでのメンテナンス解除を行う
$systemService->disableMaintenance();
}

$params = http_build_query([
Expand Down
41 changes: 41 additions & 0 deletions PluginManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\SiteKit;


use Eccube\Plugin\AbstractPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Yaml;

class PluginManager extends AbstractPluginManager
{
public function install(array $meta, ContainerInterface $container)
{
$fs = new Filesystem();
$routeYaml = $container->getParameter('plugin_data_realdir').'/SiteKit/routes.yaml';
if (!$fs->exists($routeYaml)) {
$fs->dumpFile($routeYaml, '');
}
}

public function update(array $meta, ContainerInterface $container)
{
$fs = new Filesystem();
$routeYaml = $container->getParameter('plugin_data_realdir').'/SiteKit/routes.yaml';
if (!$fs->exists($routeYaml)) {
$fs->dumpFile($routeYaml, '');
}
}
}
3 changes: 3 additions & 0 deletions Resource/config/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
site_kit_routes:
resource: '../../../../PluginData/SiteKit/routes.yaml'
prefix: /

0 comments on commit 351f62a

Please sign in to comment.