Skip to content

Commit

Permalink
Merge pull request #19 from eccubevn/new-log
Browse files Browse the repository at this point in the history
- ログ対応
- #18
- #12
  • Loading branch information
ryo-endo committed Nov 14, 2016
2 parents 6c5a8a0 + db14630 commit 1a368b8
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 62 deletions.
22 changes: 13 additions & 9 deletions Controller/RecommendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@

use Eccube\Application;
use Eccube\Controller\AbstractController;
use Plugin\Recommend\Entity\RecommendProduct;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

// include log functions (for 3.0.0 - 3.0.11)
require_once(__DIR__.'/../log.php');

/**
* Class RecommendController.
*/
Expand Down Expand Up @@ -53,6 +52,7 @@ public function index(Application $app, Request $request)
*/
public function edit(Application $app, Request $request, $id = null)
{
/* @var RecommendProduct $Recommend */
$Recommend = null;
$Product = null;
if (!is_null($id)) {
Expand All @@ -61,7 +61,7 @@ public function edit(Application $app, Request $request, $id = null)

if (!$Recommend) {
$app->addError('admin.recommend.not_found', 'admin');
log_error('the recommend product is not found.', array('Recommend id' => $id));
log_info('The recommend product is not found.', array('Recommend id' => $id));

return $app->redirect($app->url('admin_recommend_list'));
}
Expand All @@ -70,6 +70,7 @@ public function edit(Application $app, Request $request, $id = null)
}

// formの作成
/* @var Form $form */
$form = $app['form.factory']
->createBuilder('admin_recommend', $Recommend)
->getForm();
Expand All @@ -81,18 +82,18 @@ public function edit(Application $app, Request $request, $id = null)
if (is_null($data['id'])) {
if ($status = $service->createRecommend($data)) {
$app->addSuccess('admin.plugin.recommend.register.success', 'admin');
log_info('add the new recommend product.', array('Product id' => $data['Product']->getId()));
log_info('Add the new recommend product success.', array('Product id' => $data['Product']->getId()));
}
} else {
if ($status = $service->updateRecommend($data)) {
$app->addSuccess('admin.plugin.recommend.update.success', 'admin');
log_info('update the recommend product.', array('Product id' => $data['Product']->getId()));
log_info('Update the recommend product success.', array('Recommend id' => $Recommend->getId(), 'Product id' => $data['Product']->getId()));
}
}

if (!$status) {
$app->addError('admin.recommend.not_found', 'admin');
log_error('failed the recommend product updating.', array('Product id' => $data['Product']->getId()));
log_info('Failed the recommend product updating.', array('Product id' => $data['Product']->getId()));
}

return $app->redirect($app->url('admin_recommend_list'));
Expand Down Expand Up @@ -132,6 +133,7 @@ public function delete(Application $app, Request $request, $id)

// Check request
if (!'POST' === $request->getMethod()) {
log_error('Delete with bad method!');
throw new BadRequestHttpException();
}

Expand All @@ -146,10 +148,11 @@ public function delete(Application $app, Request $request, $id)

// おすすめ商品情報を削除する
if ($service->deleteRecommend($id)) {
log_info('The recommend product delete success!', array('Recommend id' => $id));
$app->addSuccess('admin.plugin.recommend.delete.success', 'admin');
} else {
$app->addError('admin.recommend.not_found', 'admin');
log_error('the recommend product is not found.', array('Recommend id' => $id));
log_info('The recommend product is not found.', array('Recommend id' => $id));
}

return $app->redirect($app->url('admin_recommend_list'));
Expand All @@ -167,7 +170,8 @@ public function moveRank(Application $app, Request $request)
{
if ($request->isXmlHttpRequest()) {
$arrRank = $request->request->all();
$app['eccube.plugin.recommend.repository.recommend_product']->moveRecommendRank($arrRank);
$arrRankMoved = $app['eccube.plugin.recommend.repository.recommend_product']->moveRecommendRank($arrRank);
log_info('Recommend move rank', $arrRankMoved);
}

return true;
Expand Down
9 changes: 3 additions & 6 deletions Controller/RecommendSearchModelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
use Eccube\Application;
use Symfony\Component\HttpFoundation\Request;

// include log functions (for 3.0.0 - 3.0.11)
require_once(__DIR__.'/../log.php');

/**
* Class RecommendSearchModelController.
*/
Expand All @@ -37,7 +34,7 @@ public function searchProduct(Application $app, Request $request, $page_no = nul
return null;
}

log_debug('search product start.');
log_debug('Search product start.');

$pageCount = $app['config']['default_page_count'];
$session = $app['session'];
Expand Down Expand Up @@ -76,9 +73,9 @@ public function searchProduct(Application $app, Request $request, $page_no = nul
/** @var ArrayCollection */
$arrProduct = $pagination->getItems();

log_debug('search product finish.');
log_debug('Search product finish.');
if (count($arrProduct) == 0) {
log_debug('search product not found.');
log_debug('Search product not found.');
}

return $app->render('Recommend/Resource/template/admin/search_product.twig', array(
Expand Down
5 changes: 0 additions & 5 deletions Entity/RecommendProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ class RecommendProduct extends AbstractEntity
*/
private $rank;

/**
* @var int
*/
private $status;

/**
* @var int
*/
Expand Down
31 changes: 22 additions & 9 deletions PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Plugin\Recommend;

use Eccube\Common\Constant;
use Eccube\Entity\Block;
use Eccube\Entity\BlockPosition;
use Eccube\Entity\Master\DeviceType;
use Eccube\Entity\PageLayout;
Expand Down Expand Up @@ -116,19 +117,31 @@ public function update($config, $app)
private function createDataBlock($app)
{
$em = $app['orm.em'];

try {
$DeviceType = $app['eccube.repository.master.device_type']->find(DeviceType::DEVICE_TYPE_PC);

/** @var \Eccube\Entity\Block $Block */
$Block = $app['eccube.repository.block']->findOrCreate(null, $DeviceType);
// check exists block
/** @var Block $Block */
$Block = $app['eccube.repository.block']->findOneBy(array('DeviceType' => $DeviceType, 'file_name' => $this->blockFileName));
if (!$Block) {
/** @var Block $Block */
$Block = $app['eccube.repository.block']->findOrCreate(null, $DeviceType);

// Blockの登録
$Block->setName($this->blockName)
->setFileName($this->blockFileName)
->setDeletableFlg(Constant::DISABLED)
->setLogicFlg(1);
$em->persist($Block);
$em->flush($Block);
}

// Blockの登録
$Block->setName($this->blockName)
->setFileName($this->blockFileName)
->setDeletableFlg(Constant::DISABLED)
->setLogicFlg(1);
$em->persist($Block);
$em->flush($Block);
// check exists block position
$blockPos = $em->getRepository('Eccube\Entity\BlockPosition')->findOneBy(array('block_id' => $Block->getId()));
if ($blockPos) {
return;
}

// BlockPositionの登録
$blockPos = $em->getRepository('Eccube\Entity\BlockPosition')->findOneBy(
Expand Down
4 changes: 3 additions & 1 deletion Repository/RecommendProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ public function countRecommend()
public function moveRecommendRank(array $arrRank)
{
$this->getEntityManager()->beginTransaction();
$arrRankMoved = array();
try {
foreach ($arrRank as $recommendId => $rank) {
/* @var $Recommend RecommendProduct */
$Recommend = $this->find($recommendId);
if ($Recommend->getRank() == $rank) {
continue;
}
$arrRankMoved[$recommendId] = $rank;
$Recommend->setRank($rank);
$this->getEntityManager()->persist($Recommend);
}
Expand All @@ -111,7 +113,7 @@ public function moveRecommendRank(array $arrRank)
throw $e;
}

return true;
return $arrRankMoved;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ Plugin\Recommend\Entity\RecommendProduct:
manyToOne:
Product:
targetEntity: Eccube\Entity\Product
inversedBy: RecommendProduct
joinColumn:
name: product_id
referencedColumnName: product_id
lifecycleCallbacks: { }

6 changes: 3 additions & 3 deletions Resource/doctrine/migration/Version201510211300.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Tools\SchemaTool;
use Eccube\Application;
use Eccube\Common\Constant;
use Doctrine\ORM\EntityManager;
use Plugin\Recommend\Utils\Version;

/**
* Class Version201510211300.
Expand All @@ -38,7 +38,7 @@ class Version201510211300 extends AbstractMigration
*/
public function up(Schema $schema)
{
if (version_compare(Constant::VERSION, '3.0.9', '>=')) {
if (Version::isSupportGetInstanceFunction()) {
$this->createRecommendProduct($schema);
} else {
$this->createRecommendProductForOldVersion($schema);
Expand All @@ -52,7 +52,7 @@ public function up(Schema $schema)
*/
public function down(Schema $schema)
{
if (version_compare(Constant::VERSION, '3.0.9', '>=')) {
if (Version::isSupportGetInstanceFunction()) {
$app = Application::getInstance();
$meta = $this->getMetadata($app['orm.em']);
$tool = new SchemaTool($app['orm.em']);
Expand Down
2 changes: 1 addition & 1 deletion Resource/locale/message.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ admin.plugin.recommend.delete.confirm: おすすめ情報を削除してもよ
plugin.recommend.type.product.not_found: 商品を追加してください。
plugin.recommend.type.product_recommend.existed: この商品はすでにおすすめ商品として登録されています。
plugin.recommend.type.product.limit: おすすめ商品の登録件数の上限は100件です。
plugin.recommend.type.comment.placeholder: 説明文を入力してください(HTMLタグ使用可)。
plugin.recommend.type.comment.placeholder: 説明文を入力してください(HTMLタグ使用可)。
2 changes: 1 addition & 1 deletion Resource/template/Block/recommend_product_block.twig
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
{% endfor %}
</div>
</div>
<!-- ▲item_list▲ -->
<!-- ▲item_list▲ -->
2 changes: 1 addition & 1 deletion Resource/template/admin/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@
</div>
</div>
</form>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion Resource/template/admin/search_product.twig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</span>
</td>
<td class="text-right">
<button onclick="fnSelectProduct($(this).parent().parent(), '{{ Product.id }}', '{{ Product.name }}', '{{ url('admin_product_product_edit', { id : Product.id }) }}', '{{ app.config.image_save_urlpath }}/{{ Product.mainFileName|no_image_product }}', '{{ Product.code_min }}', '{{ Product.code_max }}')" type="button" class="btn btn-default btn-sm">
<button onclick="fnSelectProduct($(this).parent().parent(), '{{ Product.id }}', '{{ Product.name|escape('js') }}', '{{ url('admin_product_product_edit', { id : Product.id }) }}', '{{ app.config.image_save_urlpath }}/{{ Product.mainFileName|no_image_product }}', '{{ Product.code_min }}', '{{ Product.code_max }}')" type="button" class="btn btn-default btn-sm">
決定
</button>
</td>
Expand Down
7 changes: 4 additions & 3 deletions ServiceProvider/RecommendServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

namespace Plugin\Recommend\ServiceProvider;

use Eccube\Common\Constant;
use Plugin\Recommend\Form\Type\RecommendProductType;
use Plugin\Recommend\Service\RecommendService;
use Plugin\Recommend\Utils\Version;
use Silex\Application as BaseApplication;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Yaml\Yaml;

// include log functions (for 3.0.0 - 3.0.11)
Expand Down Expand Up @@ -84,7 +85,7 @@ public function register(BaseApplication $app)
});

// メッセージ登録
$app['translator'] = $app->share($app->extend('translator', function ($translator, Application $app) {
$app['translator'] = $app->share($app->extend('translator', function (Translator $translator, Application $app) {
$file = __DIR__.'/../Resource/locale/message.'.$app['locale'].'.yml';
if (file_exists($file)) {
$translator->addResource('yaml', $file, $app['locale']);
Expand Down Expand Up @@ -131,7 +132,7 @@ public function register(BaseApplication $app)
}));

// initialize logger (for 3.0.0 - 3.0.8)
if (version_compare(Constant::VERSION, '3.0.8', '<=')) {
if (!Version::isSupportGetInstanceFunction()) {
eccube_log_init($app);
}
}
Expand Down
40 changes: 40 additions & 0 deletions Utils/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Recommend plugin
*
* Copyright (C) 2016 LOCKON CO.,LTD. All Rights Reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Recommend\Utils;

use Eccube\Common\Constant;

/**
* Class Version.
* Util to check version
*/
class Version
{
/**
* Check version to support get instance function. (monolog, new style, ...)
*
* @return bool|int|mixed|void
*/
public static function isSupportGetInstanceFunction()
{
return version_compare(Constant::VERSION, '3.0.9', '>=');
}

/**
* Check version to support new log function.
*
* @return bool|int|mixed|void
*/
public static function isSupportLogFunction()
{
return version_compare(Constant::VERSION, '3.0.12', '>=');
}
}
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ before_test:
- php app/console plugin:develop enable --code=%PLUGIN_CODE%

test_script:
- vendor\bin\phpunit.bat app/Plugin/%PLUGIN_CODE%/Tests
- vendor\bin\phpunit.bat app/Plugin/%PLUGIN_CODE%/Tests

0 comments on commit 1a368b8

Please sign in to comment.