Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ページ管理でテンプレートが編集できない問題を修正 #62

Merged
merged 3 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,25 @@ matrix:
env: ECCUBE_VERSION=4.0.3 DATABASE_URL=mysql://root:@localhost/cube4_dev DATABASE_SERVER_VERSION=5
- php: 7.4
env: ECCUBE_VERSION=4.0.3 DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9

before_install: &php_setup |
phpenv config-rm xdebug.ini || true
echo "opcache.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

# composer.jsonが存在しないディレクトリで実行
setup_composer: &setup_composer |
cd ..
composer selfupdate --1
cd -

install_eccube: &install_eccube |
tar cvzf ${HOME}/${PLUGIN_CODE}.tar.gz ./*
git clone https://github.com/EC-CUBE/ec-cube.git
cd ec-cube
sh -c "if [ '${ECCUBE_VERSION}' = '4.0' ]; then git checkout origin/${ECCUBE_VERSION}; fi"
sh -c "if [ ! '${ECCUBE_VERSION}' = '4.0' ]; then git checkout refs/tags/${ECCUBE_VERSION}; fi"
composer selfupdate
composer install --dev --no-interaction -o --apcu-autoloader

eccube_setup: &eccube_setup |
Expand All @@ -91,6 +96,7 @@ eccube_setup: &eccube_setup |
bin/console eccube:plugin:enable --code=${PLUGIN_CODE}

install:
- *setup_composer
- *install_eccube
- *eccube_setup

Expand Down
17 changes: 14 additions & 3 deletions Controller/ProductReviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function __construct(

/**
* @Route("/product_review/{id}/review", name="product_review_index", requirements={"id" = "\d+"})
* @Route("/product_review/{id}/review", name="product_review_confirm", requirements={"id" = "\d+"})
*
* @param Request $request
* @param Product $Product
Expand All @@ -85,7 +86,7 @@ public function index(Request $request, Product $Product)
case 'confirm':
log_info('Product review config confirm');

return $this->render('@ProductReview4/default/confirm.twig', [
return $this->render('ProductReview4/Resource/template/default/confirm.twig', [
'form' => $form->createView(),
'Product' => $Product,
'ProductReview' => $ProductReview,
Expand Down Expand Up @@ -118,7 +119,7 @@ public function index(Request $request, Product $Product)
}
}

return $this->render('@ProductReview4/default/index.twig', [
return $this->render('ProductReview4/Resource/template/default/index.twig', [
'Product' => $Product,
'ProductReview' => $ProductReview,
'form' => $form->createView(),
Expand All @@ -129,7 +130,7 @@ public function index(Request $request, Product $Product)
* Complete.
*
* @Route("/product_review/{id}/complete", name="product_review_complete", requirements={"id" = "\d+"})
* @Template("@ProductReview4/default/complete.twig")
* @Template("ProductReview4/Resource/template/default/complete.twig")
*
* @param $id
*
Expand All @@ -139,4 +140,14 @@ public function complete($id)
{
return ['id' => $id];
}

/**
* ページ管理表示用のダミールーティング.
*
* @Route("/product_review/display", name="product_review_display")
*/
public function display()
{
return new Response();
}
}
77 changes: 64 additions & 13 deletions PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Plugin\ProductReview4;

use Doctrine\ORM\EntityManagerInterface;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\Csv;
use Eccube\Entity\Layout;
use Eccube\Entity\Master\CsvType;
Expand All @@ -24,15 +25,31 @@
use Plugin\ProductReview4\Entity\ProductReviewConfig;
use Plugin\ProductReview4\Entity\ProductReviewStatus;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;

class PluginManager extends AbstractPluginManager
{
/**
* @var array
*/
private $urls = [
'product_review_index' => 'レビューを投稿',
'product_review_complete' => 'レビューを投稿(完了)',
private $pages = [
[
'name' => 'レビューを表示',
'url' => 'product_review_display',
'filename' => 'ProductReview4/Resource/template/default/review',
],
[
'name' => 'レビューを投稿',
'url' => 'product_review_index',
'filename' => 'ProductReview4/Resource/template/default/index',
],
[
'name' => 'レビューを投稿(確認)',
'url' => 'product_review_confirm',
'filename' => 'ProductReview4/Resource/template/default/confirm',
],
[
'name' => 'レビューを投稿(完了)',
'url' => 'product_review_complete',
'filename' => 'ProductReview4/Resource/template/default/complete',
],
];

public function enable(array $meta, ContainerInterface $container)
Expand All @@ -56,23 +73,37 @@ public function enable(array $meta, ContainerInterface $container)
}

// ページを追加
foreach ($this->urls as $url => $name) {
$Page = $container->get(PageRepository::class)->findOneBy(['url' => $url]);
foreach ($this->pages as $pageInfo) {
$Page = $container->get(PageRepository::class)->findOneBy(['url' => $pageInfo['url']]);
if (null === $Page) {
$this->createPage($em, $name, $url);
$this->createPage($em, $pageInfo['name'], $pageInfo['url'], $pageInfo['filename']);
}
}

$this->copyTwigFiles($container);
}

public function disable(array $meta, ContainerInterface $container)
{
$em = $container->get('doctrine.orm.entity_manager');

// ページを削除
foreach ($this->pages as $pageInfo) {
$this->removePage($em, $pageInfo['url']);
}
}

public function uninstall(array $meta, ContainerInterface $container)
{
$em = $container->get('doctrine.orm.entity_manager');

// ページを削除
foreach ($this->urls as $url) {
$this->removePage($em, $url);
foreach ($this->pages as $pageInfo) {
$this->removePage($em, $pageInfo['url']);
}

$this->removeTwigFiles($container);

$Config = $em->find(ProductReviewConfig::class, 1);
if ($Config) {
$CsvType = $Config->getCsvType();
Expand Down Expand Up @@ -149,13 +180,13 @@ protected function createCsvType(EntityManagerInterface $em)
return $CsvType;
}

protected function createPage(EntityManagerInterface $em, $name, $url)
protected function createPage(EntityManagerInterface $em, $name, $url, $filename)
{
$Page = new Page();
$Page->setEditType(Page::EDIT_TYPE_DEFAULT);
$Page->setName($name);
$Page->setUrl($url);
$Page->setFileName('@ProductReview4/default/index');
$Page->setFileName($filename);

// DB登録
$em->persist($Page);
Expand All @@ -171,6 +202,18 @@ protected function createPage(EntityManagerInterface $em, $name, $url)
$em->flush($PageLayout);
}

protected function copyTwigFiles(ContainerInterface $container)
{
$templatePath = $container->getParameter('eccube_theme_front_dir')
.'/ProductReview4/Resource/template/default';
$fs = new Filesystem();
if ($fs->exists($templatePath)) {
return;
}
$fs->mkdir($templatePath);
$fs->mirror(__DIR__.'/Resource/template/default', $templatePath);
}

protected function createCsvData(EntityManagerInterface $em, CsvType $CsvType)
{
$rank = 1;
Expand Down Expand Up @@ -291,6 +334,14 @@ protected function removePage(EntityManagerInterface $em, $url)
$em->flush($Page);
}

protected function removeTwigFiles(ContainerInterface $container)
{
$templatePath = $container->getParameter('eccube_theme_front_dir')
.'/ProductReview4';
$fs = new Filesystem();
$fs->remove($templatePath);
}

protected function removeCsvData(EntityManagerInterface $em, CsvType $CsvType)
{
$CsvData = $em->getRepository(Csv::class)->findBy(['CsvType' => $CsvType]);
Expand Down
2 changes: 1 addition & 1 deletion ProductReviewEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function getSubscribedEvents()
*/
public function detail(TemplateEvent $event)
{
$event->addSnippet('@ProductReview4/default/review.twig');
$event->addSnippet('ProductReview4/Resource/template/default/review.twig');

$Config = $this->productReviewConfigRepository->get();

Expand Down
1 change: 0 additions & 1 deletion Resource/template/default/review.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{#
/*
* This file is part of the ProductReview plugin
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ install:
- echo memory_limit = 512M >> C:\tools\php72\php.ini
- echo APP_ENV=codeception >> .env
- php -r "readfile('http://getcomposer.org/installer');" | php
- php composer.phar selfupdate --1
- php composer.phar install --dev --no-interaction -o

# Don't actually build.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ec-cube/ProductReview4",
"version": "4.0.1",
"version": "4.0.2",
"description": "商品レビュー管理プラグイン",
"type": "eccube-plugin",
"require": {
Expand Down