Skip to content

Commit

Permalink
Merge branch 'master' into fix-stock
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Sep 27, 2016
2 parents 81ab7c9 + d8324b8 commit 2fa389b
Show file tree
Hide file tree
Showing 34 changed files with 2,390 additions and 317 deletions.
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ install:
#- cinst mysql
#- SET PATH=C:\tools\mysql\current\bin\;%PATH%
# Set PHP.
#- cinst php php7になってしまうので
- cinst php -version 5.6.17
- cinst php
- SET PATH=C:\tools\php\;%PATH%
- copy C:\tools\php\php.ini-production C:\tools\php\php.ini
- echo date.timezone="Asia/Tokyo" >> C:\tools\php\php.ini
Expand Down
1 change: 1 addition & 0 deletions html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
}

// output_config_php = true に設定することで、Config Yaml ファイルを元に Config PHP ファイルが出力されます。
// app/config/eccube, src/Eccube/Resource/config 以下に書き込み権限が必要です。
// Config PHP ファイルが存在する場合は、 Config Yaml より優先されます。
// Yaml ファイルをパースする必要が無いため、高速化が期待できます。
$app = \Eccube\Application::getInstance(array('output_config_php' => false));
Expand Down
1 change: 1 addition & 0 deletions html/index_dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
}

// output_config_php = true に設定することで、Config Yaml ファイルを元に Config PHP ファイルが出力されます。
// app/config/eccube, src/Eccube/Resource/config 以下に書き込み権限が必要です。
// Config PHP ファイルが存在する場合は、 Config Yaml より優先されます。
// Yaml ファイルをパースする必要が無いため、高速化が期待できます。
$app = \Eccube\Application::getInstance(array('output_config_php' => false));
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 @@ -28,7 +28,7 @@ class Constant {
/**
* EC-CUBE VERSION.
*/
const VERSION = '3.0.10';
const VERSION = '3.0.11';

/**
* Enable value.
Expand Down
18 changes: 14 additions & 4 deletions src/Eccube/Controller/Admin/Product/CsvImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,20 @@ protected function getImportData($app, $formFile)
$formFile->move($app['config']['csv_temp_realdir'], $this->fileName);

$file = file_get_contents($app['config']['csv_temp_realdir'] . '/' . $this->fileName);
// アップロードされたファイルがUTF-8以外は文字コード変換を行う
$encode = Str::characterEncoding(substr($file, 0, 6));
if ($encode != 'UTF-8') {
$file = mb_convert_encoding($file, 'UTF-8', $encode);

if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID >= 70000) {
// Windows 環境の PHP7 の場合はファイルエンコーディングを CP932 に合わせる
// see https://github.com/EC-CUBE/ec-cube/issues/1780
setlocale(LC_ALL, ''); // 既定のロケールに設定
if (mb_detect_encoding($file) === 'UTF-8') { // UTF-8 を検出したら SJIS-win に変換
$file = mb_convert_encoding($file, 'SJIS-win', 'UTF-8');
}
} else {
// アップロードされたファイルがUTF-8以外は文字コード変換を行う
$encode = Str::characterEncoding(substr($file, 0, 6));
if ($encode != 'UTF-8') {
$file = mb_convert_encoding($file, 'UTF-8', $encode);
}
}
$file = Str::convertLineFeed($file);

Expand Down
53 changes: 31 additions & 22 deletions src/Eccube/Controller/Admin/Setting/System/MasterdataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace Eccube\Controller\Admin\Setting\System;

use Doctrine\Common\Persistence\Mapping\MappingException;
use Eccube\Application;
use Eccube\Controller\AbstractController;
use Eccube\Event\EccubeEvents;
Expand All @@ -32,7 +33,7 @@

class MasterdataController extends AbstractController
{
public function index(Application $app, Request $request)
public function index(Application $app, Request $request, $entity = null)
{
$data = array();

Expand All @@ -51,34 +52,38 @@ public function index(Application $app, Request $request)
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$event = new EventArgs(
array(
'form' => $form,
),
$request
);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_COMPLETE, $event);

if ($data['masterdata']) {
$masterdata = $app['orm.em']->getRepository($data['masterdata'])->findBy(array(), array('rank' => 'ASC'));
if ($event->hasResponse()) {
return $event->getResponse();
}

return $app->redirect($app->url('admin_setting_system_masterdata_view', array('entity' => $form['masterdata']->getData())));
}
} elseif (!is_null($entity)) {
$form->submit(array('masterdata' => $entity));
if ($form['masterdata']->isValid()) {
$entityName = str_replace('-', '\\', $entity);
try {
$masterdata = $app['orm.em']->getRepository($entityName)->findBy(array(), array('rank' => 'ASC'));
$data['data'] = array();
$data['masterdata_name'] = $entity;
foreach ($masterdata as $value) {
$data['data'][$value['id']]['id'] = $value['id'];
$data['data'][$value['id']]['name'] = $value['name'];
}

// 新規登録様に空のデータを追加する。
$data['data'][] = array(
'id' => '',
'name' => '',
);

// hidden値
$data['masterdata_name'] = $data['masterdata'];
} catch (MappingException $e) {
}

$event = new EventArgs(
array(
'form' => $form,
),
$request
);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_COMPLETE, $event);

}
}

Expand Down Expand Up @@ -120,17 +125,19 @@ public function edit(Application $app, Request $request)
if ($form2->isValid()) {
$data = $form2->getData();

$entity = new $data['masterdata_name']();
$entityName = str_replace('-', '\\', $data['masterdata_name']);
$entity = new $entityName();
$rank = 0;
$ids = array_map(function ($v) {return $v['id'];}, $data['data']);
foreach ($data['data'] as $key => $value) {
if ($value['id'] !== null && $value['name'] !== null) {
$entity->setId($value['id']);
$entity->setName($value['name']);
$entity->setRank($rank++);
$app['orm.em']->merge($entity);
} else {
} elseif (!in_array($key, $ids)) {
// remove
$delKey = $app['orm.em']->getRepository($data['masterdata_name'])->find($key);
$delKey = $app['orm.em']->getRepository($entityName)->find($key);
if ($delKey) {
$app['orm.em']->remove($delKey);
}
Expand All @@ -154,7 +161,7 @@ public function edit(Application $app, Request $request)
$app->addError('admin.register.failed', 'admin');
}

return $app->redirect($app->url('admin_setting_system_masterdata'));
return $app->redirect($app->url('admin_setting_system_masterdata_view', array('entity' => $data['masterdata_name'])));
}
}

Expand All @@ -169,6 +176,8 @@ public function edit(Application $app, Request $request)
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_EDIT_FORM_INITIALIZE, $event);

$form = $builder->getForm();
$parameter = array_merge($request->request->all(), array('masterdata' => $form2['masterdata_name']->getData()));
$form->submit($parameter);

return $app->render('Setting/System/masterdata.twig', array(
'form' => $form->createView(),
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/ControllerProvider/AdminControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public function connect(Application $app)

// system/masterdata
$c->match('/setting/system/masterdata', '\Eccube\Controller\Admin\Setting\System\MasterdataController::index')->bind('admin_setting_system_masterdata');
$c->match('/setting/system/masterdata/{entity}/edit', '\Eccube\Controller\Admin\Setting\System\MasterdataController::index')->bind('admin_setting_system_masterdata_view');
$c->match('/setting/system/masterdata/edit', '\Eccube\Controller\Admin\Setting\System\MasterdataController::edit')->bind('admin_setting_system_masterdata_edit');

// store
Expand Down
3 changes: 2 additions & 1 deletion src/Eccube/Form/Type/Admin/MasterdataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
&& $meta->hasField('name')
&& $meta->hasField('rank')
) {
$masterdata[$meta->getName()] = $meta->getTableName();
$metadataName = str_replace('\\', '-', $meta->getName());
$masterdata[$metadataName] = $meta->getTableName();
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/Eccube/Resource/config/http_cache.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ http_cache:
age: 10
# フロントでキャッシュを適用させる画面のrouteを設定
route:
- homepage
- product_list
- block_category
- block_news
- block_search_product
- help_about
- help_guide
- help_privacy
- help_tradelaw
- help_agreement
# - homepage
# - product_list
# - block_category
# - block_news
# - block_search_product
# - help_about
# - help_guide
# - help_privacy
# - help_tradelaw
# - help_agreement
2 changes: 1 addition & 1 deletion src/Eccube/Resource/template/admin/default_frame.twig
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<dd class="dropdown-menu">
最終ログイン<br>
{{ app.user.login_date.format('Y/m/d H:i')|default('') }}
<a class="btn btn-primary btn-xs" href="{{ url(app.config.admin_route ~ '_change_password') }}">パスワード変更</a>
<a class="btn btn-primary btn-xs" href="{{ url('admin_change_password') }}">パスワード変更</a>
<a class="btn btn-primary btn-xs" href="{{ url(app.config.admin_route ~ '_logout') }}">ログアウト</a>
</dd>
{% endif %}
Expand Down
22 changes: 20 additions & 2 deletions src/Eccube/Service/CsvImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ public function current()

// Since the CSV has column headers use them to construct an associative array for the columns in this line
if ($this->valid()) {
$line = $this->file->current();
$current = $this->file->current();
$current = $this->convertEncodingRows($current);

$line = $current;

// See if values for duplicate headers should be merged
if (self::DUPLICATE_HEADERS_MERGE === $this->duplicateHeadersFlag) {
Expand Down Expand Up @@ -181,6 +184,7 @@ public function getColumnHeaders()
*/
public function setColumnHeaders(array $columnHeaders)
{
$columnHeaders = $this->convertEncodingRows($columnHeaders);
$this->columnHeaders = array_count_values($columnHeaders);
$this->headersCount = count($columnHeaders);
}
Expand All @@ -204,7 +208,7 @@ public function setHeaderRowNumber($rowNumber, $duplicates = null)
$headers = $this->readHeaderRow($rowNumber);

if ($headers === false) {
return false;
return false;
}
$this->setColumnHeaders($headers);
return true;
Expand Down Expand Up @@ -400,4 +404,18 @@ protected function mergeDuplicates(array $line)
return $values;
}

/**
* 行の文字エンコーディングを変換する.
*
* Windows 版 PHP7 環境では、ファイルエンコーディングが CP932 になるため UTF-8 に変換する.
* それ以外の環境では何もしない。
*/
protected function convertEncodingRows($row) {
if ('\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID >= 70000) {
foreach ($row as &$col) {
$col = mb_convert_encoding($col , 'UTF-8', 'SJIS-win');
}
}
return $row;
}
}
104 changes: 104 additions & 0 deletions tests/Eccube/Tests/Event/TemplateEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

namespace Eccube\Tests\Event;

use Eccube\Event\TemplateEvent;
use Eccube\Tests\EccubeTestCase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

/**
* Class TemplateEventTest
* @package Eccube\Tests\Event
*/
class TemplateEventTest extends EccubeTestCase
{
/**
* View test
*/
public function testView()
{
$templateEvent = new TemplateEvent(null, null);
$this->assertNull($templateEvent->getView());

$view = 'this is a test';

// set view
$templateEvent->setView($view);

$this->assertNotNull($templateEvent->getView());
}

/**
* Response test
*/
public function testResponse()
{
$event = new TemplateEvent(null, null);
$this->assertNull($event->getResponse());

// setResponse test
$response = new Response();
$event->setResponse($response);
$this->assertNotNull($event->getResponse());

// リダイレクトレスポンスの検証
$response = new RedirectResponse('http://www.ec-cube.net/');
$event->setResponse($response);

$this->assertNotNull($event->getResponse());
}

/**
* Source test
*/
public function testSource()
{
$templateEvent = new TemplateEvent(null, null);
$this->assertNull($templateEvent->getSource());

$source = 'this is a test';

// set source
$templateEvent->setSource($source);

$this->assertNotNull($templateEvent->getSource());
}

/**
* Parameter test
*/
public function testParameter()
{
$templateEvent = new TemplateEvent(null, null);
$this->assertSame(array(), $templateEvent->getParameters());

$parameter = array('id' => 1);

// set parameter
$templateEvent->setParameters($parameter);

$this->assertSame($parameter, $templateEvent->getParameters());
}
}
2 changes: 1 addition & 1 deletion tests/Eccube/Tests/Fixture/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public function createOrder(Customer $Customer, array $ProductClasses = array(),
$this->app['orm.em']->persist($Shipping);
$this->app['orm.em']->flush($Shipping);

if (empty($ProductClassess)) {
if (empty($ProductClasses)) {
$Product = $this->createProduct();
$ProductClasses = $Product->getProductClasses();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Eccube/Tests/Form/Type/Admin/MasterdataTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testEntityMetadata()
$view = $this->form['masterdata']->createView();
$choices = $view->vars['choices'];

$expect = 'Eccube\Entity';
$expect = 'Eccube-Entity';

foreach ($choices as $choice) {
$actual = $choice->data;
Expand Down

0 comments on commit 2fa389b

Please sign in to comment.