Skip to content

Commit

Permalink
Merge pull request #5002 from okazy/feature/41beta2
Browse files Browse the repository at this point in the history
4.1-beta2 への機能取り込み
  • Loading branch information
chihiro-adachi committed Apr 12, 2021
2 parents 4574bdd + 4e3cf4c commit 9b94ccf
Show file tree
Hide file tree
Showing 33 changed files with 860 additions and 75 deletions.
36 changes: 36 additions & 0 deletions app/DoctrineMigrations/Version20210401120000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

/*
* 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 DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210401120000 extends AbstractMigration
{
public function up(Schema $schema): void
{
// 会員登録完了ページに noindex を設定
$this->addSql("UPDATE dtb_page SET meta_robots = 'noindex' WHERE url = 'entry_activate' AND meta_robots = ''");
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
1 change: 1 addition & 0 deletions app/config/eccube/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ security:
logout:
path: admin_logout
target: admin_login
success_handler: eccube.security.logout.success_handler
customer:
pattern: ^/
anonymous: true
Expand Down
3 changes: 3 additions & 0 deletions app/config/eccube/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ services:
eccube.security.failure_handler:
class: Eccube\Security\Http\Authentication\EccubeAuthenticationFailureHandler

eccube.security.logout.success_handler:
class: Eccube\Security\Http\Authentication\EccubeLogoutSuccessHandler

# Autowiring can't guess the constructor arguments that are not type-hinted with
# classes (e.g. container parameters) so you must define those arguments explicitly
# Eccube\Command\ListUsersCommand:
Expand Down
22 changes: 22 additions & 0 deletions html/template/default/assets/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html/template/default/assets/css/style.min.css.map

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions html/template/default/assets/scss/project/_11.2.header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -826,3 +826,30 @@ Styleguide 11.2.7
.ec-itemNavAccordion {
display: none;
}

.ec-maintenanceAlert {
background: steelblue;
height: 5rem;
position: fixed;
top: 0;
width: 100%;
color: white;
z-index: 9999;
display: flex;
font-weight: bold;
& > * {
margin: auto;
}
& &__icon {
display: inline-block;
margin-right: 1rem;
width: 20px;
height: 20px;
color: #fff;
fill: #fff;
vertical-align: top;
}
& +* {
margin-top: 5rem;
}
}
20 changes: 13 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Eccube\Kernel;
use Eccube\Service\SystemService;
use Symfony\Component\Debug\Debug;
use Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -62,13 +63,18 @@
$adminPath = env('ECCUBE_ADMIN_ROUTE', 'admin');
$adminPath = '/'.\trim($adminPath, '/').'/';
if (\strpos($pathInfo, $adminPath) !== 0) {
$locale = env('ECCUBE_LOCALE');
$templateCode = env('ECCUBE_TEMPLATE_CODE');
$baseUrl = \htmlspecialchars(\rawurldecode($request->getBaseUrl()), ENT_QUOTES);

header('HTTP/1.1 503 Service Temporarily Unavailable');
require __DIR__.'/maintenance.php';
return;
$maintenanceContents = file_get_contents($maintenanceFile);
$maintenanceToken = explode(':', $maintenanceContents)[1] ?? null;
$tokenInCookie = $request->cookies->get(SystemService::MAINTENANCE_TOKEN_KEY);
if ($tokenInCookie === null || $tokenInCookie !== $maintenanceToken) {
$locale = env('ECCUBE_LOCALE');
$templateCode = env('ECCUBE_TEMPLATE_CODE');
$baseUrl = \htmlspecialchars(\rawurldecode($request->getBaseUrl()), ENT_QUOTES);

header('HTTP/1.1 503 Service Temporarily Unavailable');
require __DIR__.'/maintenance.php';
return;
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/Eccube/Controller/Admin/Content/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@ public function index(Request $request)

if ($form->isSubmitted() && $form->isValid()) {
$changeTo = $request->request->get('maintenance');
$path = $this->container->getParameter('eccube_content_maintenance_file_path');

if ($isMaintenance === false && $changeTo == 'on') {
// 現在メンテナンスモードではない かつ メンテナンスモードを有効 にした場合
// メンテナンスモードを有効にする
file_put_contents($path, null);

$this->systemService->enableMaintenance('', true);
$this->addSuccess('admin.content.maintenance_switch__on_message', 'admin');
} elseif ($isMaintenance && $changeTo == 'off') {
// 現在メンテナンスモード かつ メンテナンスモードを無効 にした場合
// メンテナンスモードを無効にする
unlink($path);
$this->systemService->disableMaintenanceNow('', true);

$this->addSuccess('admin.content.maintenance_switch__off_message', 'admin');
}
Expand Down
159 changes: 159 additions & 0 deletions src/Eccube/Controller/SitemapController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?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 Eccube\Controller;

use Eccube\Entity\Page;
use Eccube\Repository\CategoryRepository;
use Eccube\Repository\PageRepository;
use Eccube\Repository\ProductRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;

class SitemapController extends AbstractController
{
/**
* @var ProductRepository
*/
private $productRepository;

/**
* @var CategoryRepository
*/
private $categoryRepository;

/**
* @var PageRepository
*/
private $pageRepository;

/**
* @var RouterInterface
*/
private $router;

/**
* SitemapController constructor.
*/
public function __construct(
ProductRepository $productRepository,
CategoryRepository $categoryRepository,
PageRepository $pageRepository,
RouterInterface $router
) {
$this->productRepository = $productRepository;
$this->categoryRepository = $categoryRepository;
$this->pageRepository = $pageRepository;
$this->router = $router;
}

/**
* Output sitemap index
*
* @Route("/sitemap.xml", name="sitemap_xml")
*/
public function index()
{
$qb = $this->pageRepository->createQueryBuilder('p');
$Page = $qb->select('p')
->where("((p.meta_robots not like '%noindex%' and p.meta_robots not like '%none%') or p.meta_robots IS NULL)")
->andWhere('p.id <> 0')
->andWhere('p.MasterPage is null')
->orderBy('p.update_date', 'DESC')
->setMaxResults(1)
->getQuery()
->getSingleResult();

$Product = $this->productRepository->findOneBy(['Status' => 1], ['update_date' => 'DESC']);
$Category = $this->categoryRepository->findOneBy([], ['update_date' => 'DESC']);

return $this->outputXml(
[
'Category' => $Category,
'Product' => $Product,
'Page' => $Page,
],
'sitemap_index.xml.twig'
);
}

/**
* Output sitemap of product categories
*
* @Route("/sitemap_category.xml", name="sitemap_category_xml")
*/
public function category()
{
$Categories = $this->categoryRepository->getList(null, true);

return $this->outputXml(['Categories' => $Categories]);
}

/**
* Output sitemap of products
*
* Output sitemap of products as status is 1
*
* @Route("/sitemap_product.xml", name="sitemap_product_xml")
*/
public function product()
{
$Products = $this->productRepository->findBy(['Status' => 1], ['update_date' => 'DESC']);

return $this->outputXml(['Products' => $Products]);
}

/**
* Output sitemap of pages
*
* Output sitemap of pages without 'noindex' in meta robots.
*
* @Route("/sitemap_page.xml", name="sitemap_page_xml")
*/
public function page()
{
$Pages = $this->pageRepository->getPageList("((p.meta_robots not like '%noindex%' and p.meta_robots not like '%none%') or p.meta_robots IS NULL)");

// URL に変数が含まれる場合は URL の生成ができないためここで除外する
$Pages = array_filter($Pages, function (Page $Page) {
$route = $this->router->getRouteCollection()->get($Page->getUrl());
if (is_null($route)) {
return false;
}
return count($route->compile()->getPathVariables()) < 1;
});

return $this->outputXml(['Pages' => $Pages]);
}

/**
* Output XML response by data.
*
* @param array $data
* @param string $template_name
*
* @return Response
*/
private function outputXml(array $data, $template_name = 'sitemap.xml.twig')
{
$response = new Response();
$response->headers->set('Content-Type', 'application/xml'); //Content-Typeを設定

return $this->render(
$template_name,
$data,
$response
);
}
}
64 changes: 64 additions & 0 deletions src/Eccube/EventListener/MaintenanceListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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 Eccube\EventListener;

use Eccube\Entity;
use Eccube\Request\Context;
use Eccube\Service\SystemService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class MaintenanceListener implements EventSubscriberInterface
{

/** @var Context */
protected $requestContext;

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

public function __construct(Context $requestContext, SystemService $systemService)
{
$this->requestContext = $requestContext;
$this->systemService = $systemService;
}

public static function getSubscribedEvents()
{
return [
KernelEvents::RESPONSE => ['onResponse'],
];
}

public function onResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();

if (!$this->systemService->isMaintenanceMode()) {
$response->headers->clearCookie(SystemService::MAINTENANCE_TOKEN_KEY);
return;
}

$user = $this->requestContext->getCurrentUser();
if ($user instanceof Entity\Member && $this->requestContext->isAdmin()) {
$cookie = new Cookie(
SystemService::MAINTENANCE_TOKEN_KEY,
$this->systemService->getMaintenanceToken()
);
$response->headers->setCookie($cookie);
}
}
}

0 comments on commit 9b94ccf

Please sign in to comment.