Skip to content

Commit

Permalink
Merge pull request #4 from 13watanabe/add-maintenance-mode__
Browse files Browse the repository at this point in the history
(WIP)Add maintenance mode
  • Loading branch information
kanako-kina authored Nov 22, 2018
2 parents bf681f9 + 9161581 commit 3b3390e
Show file tree
Hide file tree
Showing 165 changed files with 3,210 additions and 2,244 deletions.
2 changes: 1 addition & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ APP_DEBUG=1
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For a sqlite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Set "serverVersion" to your server version to avoid edge-case exceptions and extra database calls
DATABASE_URL=sqlite:///%kernel.project_dir%/var/eccube.db
DATABASE_URL=sqlite:///var/eccube.db
# The version of your database engine
DATABASE_SERVER_VERSION=3
###< doctrine/doctrine-bundle ###
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ composer.phar
.idea
*.php~
.env
.maintenance

###> symfony/phpunit-bridge ###
.phpunit
Expand Down
21 changes: 20 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DirectoryIndex index.php index.html .ht

<FilesMatch "^composer|^COPYING|^\.env|^Procfile|^app\.json|^gulpfile\.js|^package\.json|^package-lock\.json|web\.config|\.(ini|lock|dist|git|sh|bak|swp|env|twig|yml|yaml)$">
<FilesMatch "^composer|^COPYING|^\.env|^\.maintenance|^Procfile|^app\.json|^gulpfile\.js|^package\.json|^package-lock\.json|web\.config|\.(ini|lock|dist|git|sh|bak|swp|env|twig|yml|yaml)$">
order allow,deny
deny from all
</FilesMatch>
Expand All @@ -19,6 +19,11 @@ DirectoryIndex index.php index.html .ht
Header set X-Content-Type-Options nosniff
</IfModule>

# デフォルトテンプレートの状態で 2M 以上となるため
<IfModule mod_php7.c>
php_value upload_max_filesize 5M
</IfModule>

<IfModule mod_rewrite.c>
#403 Forbidden対応方法
#ページアクセスできない時シンボリックリンクが有効になっていない可能性あります、
Expand Down Expand Up @@ -49,3 +54,17 @@ DirectoryIndex index.php index.html .ht
RewriteCond %{REQUEST_FILENAME} !^(.*)\.(gif|png|jpe?g|css|ico|js|svg|map)$ [NC]
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

# 管理画面へのBasic認証サンプル
#
# AuthType Basic
# AuthName "Please enter username and password"
# AuthUserFile /path/to/.htpasswd
# AuthGroupFile /dev/null
# require valid-user
#
# SetEnvIf Request_URI "^/admin" admin_path # ^/adminは, 管理画面URLに応じて変更してください
# <RequireAll>
# Require all granted
# Require not env admin_path
# </RequireAll>#
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ php:
env:
- DATABASE_URL=mysql://root:@localhost/cube4_dev DATABASE_SERVER_VERSION=5
- DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9
- DATABASE_URL=sqlite:///%kernel.project_dir%/var/eccube.db DATABASE_SERVER_VERSION=3 COVERAGE=1
- DATABASE_URL=sqlite:///var/eccube.db DATABASE_SERVER_VERSION=3 COVERAGE=1

matrix:
allow_failures:
- env: DATABASE_URL=sqlite:///%kernel.project_dir%/var/eccube.db DATABASE_SERVER_VERSION=3 COVERAGE=1
- env: DATABASE_URL=sqlite:///var/eccube.db DATABASE_SERVER_VERSION=3 COVERAGE=1

## see https://github.com/symfony/symfony/blob/e0bdc0c35e9afdb3bee8af172f90e9648c4012fc/.travis.yml#L92-L97
before_install: &php_setup |
Expand Down
2 changes: 1 addition & 1 deletion app/config/eccube/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ doctrine:
collate: 'utf8_general_ci'

# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
url: '%env(DATABASE_URL)%'

# types
types:
Expand Down
12 changes: 0 additions & 12 deletions app/config/eccube/packages/mobile_detect.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions app/config/eccube/services_dev.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
services:
easycorp.easylog.handler:
class: EasyCorp\EasyLog\EasyLogHandler
public: false
arguments:
- '%kernel.logs_dir%/%kernel.environment%/site.log'

# 開発時はエラーページを表示しない
Eccube\EventListener\ExceptionListener:
autoconfigure: false
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "project",
"homepage": "https://www.ec-cube.net/",
"license": [
"GPL-2.0-only"
"GPL-2.0-only",
"proprietary"
],
"support": {
"issues": "https://github.com/EC-CUBE/ec-cube/issues"
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

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

18 changes: 17 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,24 @@
Request::setTrustedHosts(explode(',', $trustedHosts));
}

$kernel = new Kernel($env, $debug);
$request = Request::createFromGlobals();

if (file_exists(__DIR__.'/.maintenance')) {
$pathInfo = \rawurldecode($request->getPathInfo());
$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;
}
}

$kernel = new Kernel($env, $debug);
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
37 changes: 37 additions & 0 deletions maintenance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!doctype html>
<?php /*
This file is part of EC-CUBE
Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
http://www.lockon.co.jp/
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
*/ ?>
<html lang="<?php echo $locale; ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>ただいまメンテナンス中です。</title>
<link rel="icon" href="<?php echo $baseUrl; ?>/html/template/<?php echo $templateCode; ?>/assets/img/common/favicon.ico">
<link rel="stylesheet" href="<?php echo $baseUrl; ?>/html/template/<?php echo $templateCode; ?>/assets/css/style.css">
</head>
<body>
<div class="ec-layoutRole">
<div class="ec-404Role">
<div class="ec-off4Grid">
<div class="ec-off4Grid__cell">
<div style="font-size:100px;text-align:center;">
<div class="ec-404Role__icon ec-icon">
<img src="<?php echo $baseUrl; ?>/html/template/<?php echo $templateCode; ?>/assets/icon/exclamation-pale.svg" alt="">
</div>
</div>
<p class="ec-404Role__title ec-reportHeading">ただいまメンテナンス中です。</p>
<p class="ec-404Role__description ec-reportDescription">大変お手数ですが、しばらくしてから再度アクセスをお願いします。</p>
</div>
</div>
</div>
</div>
</body>
</html>
102 changes: 102 additions & 0 deletions src/Eccube/Command/ComposerRequireAlreadyInstalledPluginsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

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

namespace Eccube\Command;

use Doctrine\Common\Collections\Criteria;
use Eccube\Common\Constant;
use Eccube\Repository\PluginRepository;
use Eccube\Service\Composer\ComposerApiService;
use Eccube\Service\PluginApiService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;


class ComposerRequireAlreadyInstalledPluginsCommand extends Command
{
protected static $defaultName = 'eccube:composer:require-already-installed';

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

/**
* @var PluginApiService
*/
private $pluginApiService;

/**
* @var PluginRepository
*/
private $pluginRepository;

/**
* @var SymfonyStyle
*/
private $io;

public function __construct(
ComposerApiService $composerService,
PluginRepository $pluginRepository,
PluginApiService $pluginApiService
) {
parent::__construct();
$this->composerService = $composerService;
$this->pluginApiService = $pluginApiService;
$this->pluginRepository = $pluginRepository;
}

public function initialize(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$packageNames = [];
$unSupportedPlugins = [];

$criteria = Criteria::create()
->where(Criteria::expr()->neq('source', 0))
->orderBy(['code' => 'ASC']);
$Plugins = $this->pluginRepository->matching($criteria);

foreach ($Plugins as $Plugin) {
$packageNames[] = 'ec-cube/'.$Plugin->getCode().':'.$Plugin->getVersion();
$data = $this->pluginApiService->getPlugin($Plugin->getCode());
if (isset($data['version_check']) && !$data['version_check']) {
$unSupportedPlugins[] = $Plugin;
}
}

foreach ($unSupportedPlugins as $Plugin) {
$message = trans('command.composer_require_already_installed.not_supported_plugin', [
'%name%' => $Plugin->getName(),
'%plugin_version%' => $Plugin->getVersion(),
'%eccube_version%' => Constant::VERSION
]);
$question = new ConfirmationQuestion($message);
if (!$this->io->askQuestion($question)) {
return;
}
}

if ($packageNames) {
$this->composerService->execRequire(implode(' ', $packageNames), $this->io);
}
}
}
5 changes: 4 additions & 1 deletion src/Eccube/Command/InstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
// DATABASE_URL
$databaseUrl = $this->container->getParameter('eccube_database_url');
if (empty($databaseUrl)) {
$databaseUrl = 'sqlite:///%kernel.project_dir%/var/eccube.db';
$databaseUrl = 'sqlite:///var/eccube.db';
}
$databaseUrl = $this->io->ask('Database Url', $databaseUrl);

Expand Down Expand Up @@ -119,6 +119,9 @@ protected function interact(InputInterface $input, OutputInterface $output)
'DATABASE_SERVER_VERSION' => $serverVersion,
'MAILER_URL' => $mailerUrl,
'ECCUBE_AUTH_MAGIC' => $authMagic,
'ECCUBE_ADMIN_ROUTE' => 'admin',
'ECCUBE_TEMPLATE_CODE' => 'default',
'ECCUBE_LOCALE' => 'ja',
];

$envDir = $this->container->getParameter('kernel.project_dir');
Expand Down
11 changes: 9 additions & 2 deletions src/Eccube/Command/LoadDataFixturesEccubeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$doctrine = $this->getContainer()->get('doctrine');
$em = $doctrine->getManager();

// for full locale code cases
$locale = env('ECCUBE_LOCALE', 'ja_JP');
$locale = str_replace('_', '-', $locale);
$locales = \Locale::parseLocale($locale);
$localeDir = is_null($locales) ? 'ja' : $locales['language'];

$loader = new \Eccube\Doctrine\Common\CsvDataFixtures\Loader();
$loader->loadFromDirectory(__DIR__.'/../Resource/doctrine/import_csv');
$loader->loadFromDirectory(__DIR__.'/../Resource/doctrine/import_csv/'.$localeDir);
$executer = new \Eccube\Doctrine\Common\CsvDataFixtures\Executor\DbalExecutor($em);
$fixtures = $loader->getFixtures();
$executer->execute($fixtures);
Expand Down Expand Up @@ -69,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'sort_no' => 1,
'update_date' => new \DateTime(),
'create_date' => new \DateTime(),
'name' => '管理者',
'name' => trans('install.member_name'),
'department' => 'EC-CUBE SHOP',
'discriminator_type' => 'member',
], [
Expand Down
2 changes: 1 addition & 1 deletion src/Eccube/Common/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Constant
/**
* EC-CUBE VERSION.
*/
const VERSION = '4.0.0';
const VERSION = '4.0.1';

/**
* Enable value.
Expand Down
6 changes: 6 additions & 0 deletions src/Eccube/Controller/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public function login(Request $request)
*/
public function index(Request $request)
{
$adminRoute = $this->eccubeConfig['eccube_admin_route'];
$is_danger_admin_url = false;
if ($adminRoute === 'admin') {
$is_danger_admin_url = true;
}
/**
* 受注状況.
*/
Expand Down Expand Up @@ -261,6 +266,7 @@ public function index(Request $request)
'countProducts' => $countProducts,
'countCustomers' => $countCustomers,
'recommendedPlugins' => $recommendedPlugins,
'is_danger_admin_url' => $is_danger_admin_url,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public function index(Request $request, CacheUtil $cacheUtil)
return $this->redirectToRoute('admin_setting_system_security');
}

// 管理画面URLがadminの場合アラートを表示する。
$adminRoute = $this->eccubeConfig['eccube_admin_route'];
if ($adminRoute === 'admin') {
$this->addWarning('admin.setting.system.security.admin_url_warning', 'admin');
}

return [
'form' => $form->createView(),
];
Expand Down
Loading

0 comments on commit 3b3390e

Please sign in to comment.