diff --git a/app/DoctrineMigrations/Version20210401120000.php b/app/DoctrineMigrations/Version20210401120000.php new file mode 100644 index 00000000000..5ee1e85f2ad --- /dev/null +++ b/app/DoctrineMigrations/Version20210401120000.php @@ -0,0 +1,36 @@ +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 + } +} diff --git a/src/Eccube/Controller/SitemapController.php b/src/Eccube/Controller/SitemapController.php index 1fafebeb8dd..d5f32ff88c5 100644 --- a/src/Eccube/Controller/SitemapController.php +++ b/src/Eccube/Controller/SitemapController.php @@ -13,11 +13,13 @@ namespace Eccube\Controller; -use Eccube\Repository\ProductRepository; +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 { @@ -36,22 +38,24 @@ class SitemapController extends AbstractController */ private $pageRepository; + /** + * @var RouterInterface + */ + private $router; + /** * SitemapController constructor. - * - * @param ProductRepository $productRepository - * @param CategoryRepository $categoryRepository - * @param PageRepository $pageRepository */ public function __construct( ProductRepository $productRepository, CategoryRepository $categoryRepository, - PageRepository $pageRepository - ) - { + PageRepository $pageRepository, + RouterInterface $router + ) { $this->productRepository = $productRepository; - $this->categoryRepository= $categoryRepository; + $this->categoryRepository = $categoryRepository; $this->pageRepository = $pageRepository; + $this->router = $router; } /** @@ -63,21 +67,22 @@ public function index() { $qb = $this->pageRepository->createQueryBuilder('p'); $Page = $qb->select('p') - ->where("(p.meta_robots not like '%noindex%' or p.meta_robots not like '%none%' or p.meta_robots IS NULL)") + ->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") + ->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"]); + $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 + 'Category' => $Category, + 'Product' => $Product, + 'Page' => $Page, ], 'sitemap_index.xml.twig' ); @@ -90,8 +95,9 @@ public function index() */ public function category() { - $Categories = $this->categoryRepository->getList(null,true); - return $this->outputXml(["Categories"=>$Categories]); + $Categories = $this->categoryRepository->getList(null, true); + + return $this->outputXml(['Categories' => $Categories]); } /** @@ -103,8 +109,9 @@ public function category() */ public function product() { - $Products = $this->productRepository->findBy(["Status"=>1],["update_date"=>"DESC"]); - return $this->outputXml(["Products"=>$Products]); + $Products = $this->productRepository->findBy(['Status' => 1], ['update_date' => 'DESC']); + + return $this->outputXml(['Products' => $Products]); } /** @@ -116,18 +123,29 @@ public function product() */ public function page() { - $Pages = $this->pageRepository->getPageList("(p.meta_robots not like '%noindex%' or p.meta_robots not like '%none%' or p.meta_robots IS NULL)"); - return $this->outputXml(["Pages"=>$Pages]); + $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 + * @param string $template_name + * * @return Response */ - private function outputXml(Array $data, $template_name = 'sitemap.xml.twig') + private function outputXml(array $data, $template_name = 'sitemap.xml.twig') { $response = new Response(); $response->headers->set('Content-Type', 'application/xml'); //Content-Typeを設定 diff --git a/src/Eccube/Resource/doctrine/import_csv/en/dtb_page.csv b/src/Eccube/Resource/doctrine/import_csv/en/dtb_page.csv index 6614b1f00c8..f047fd17a3a 100644 --- a/src/Eccube/Resource/doctrine/import_csv/en/dtb_page.csv +++ b/src/Eccube/Resource/doctrine/import_csv/en/dtb_page.csv @@ -26,7 +26,7 @@ id,page_name,url,file_name,edit_type,author,description,keyword,create_date,upda 18,Registration (Form),entry,Entry/index,2,,,,2017-03-07 10:14:52,2017-03-07 10:14:52,,,page, 20,Registration (Thank-you),entry_complete,Entry/complete,2,,,,2017-03-07 10:14:52,2017-03-07 10:14:52,,,page, 21,Shipping & Returns,help_tradelaw,Help/tradelaw,2,,,,2017-03-07 10:14:52,2017-03-07 10:14:52,,,page, -22,Regular Customer Registration (Thank-you),entry_activate,Entry/activate,2,,,,2017-03-07 10:14:52,2017-03-07 10:14:52,,,page, +22,Regular Customer Registration (Thank-you),entry_activate,Entry/activate,2,,,,2017-03-07 10:14:52,2017-03-07 10:14:52,"noindex",,page, 24,Shopping / Delivery Address,shopping_shipping,Shopping/shipping,2,,,,2017-03-07 10:14:52,2017-03-07 10:14:52,noindex,,page, 28,Shopping / Thank you for your order,shopping_complete,Shopping/complete,2,,,,2017-03-07 10:14:52,2017-03-07 10:14:52,noindex,,page, 29,Privacy Policy,help_privacy,Help/privacy,2,,,,2017-03-07 10:14:52,2017-03-07 10:14:52,,,page, diff --git a/src/Eccube/Resource/doctrine/import_csv/ja/dtb_page.csv b/src/Eccube/Resource/doctrine/import_csv/ja/dtb_page.csv index 51fa4c5302d..c6985d7202c 100644 --- a/src/Eccube/Resource/doctrine/import_csv/ja/dtb_page.csv +++ b/src/Eccube/Resource/doctrine/import_csv/ja/dtb_page.csv @@ -26,7 +26,7 @@ id,page_name,url,file_name,edit_type,author,description,keyword,create_date,upda "18","会員登録(入力ページ)","entry","Entry/index","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52",,,"page", "20","会員登録(完了ページ)","entry_complete","Entry/complete","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52",,,"page", "21","特定商取引に関する法律に基づく表記","help_tradelaw","Help/tradelaw","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52",,,"page", -"22","本会員登録(完了ページ)","entry_activate","Entry/activate","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52",,,"page", +"22","本会員登録(完了ページ)","entry_activate","Entry/activate","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52","noindex",,"page", "24","商品購入/お届け先の指定","shopping_shipping","Shopping/shipping","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52","noindex",,"page", "28","商品購入/ご注文完了","shopping_complete","Shopping/complete","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52","noindex",,"page", "29","プライバシーポリシー","help_privacy","Help/privacy","2",,,,"2017-03-07 10:14:52","2017-03-07 10:14:52",,,"page",