get('doctrine')->getManager(); $this->createConfig($em); // twigファイルを追加 $this->copyTwigFiles($container); // ページ登録 $this->createPages($em); } /** * 設定の登録. * * @param EntityManagerInterface $em */ protected function createConfig(EntityManagerInterface $em) { $PasskeysAuthConfig = $em->find(PasskeysAuthConfig::class, 1); if ($PasskeysAuthConfig) { return; } // 初期値を保存 $PasskeysAuthConfig = new PasskeysAuthConfig(); $em->persist($PasskeysAuthConfig); $em->flush(); } /** * Twigファイルの登録 * * @param ContainerInterface $container */ protected function copyTwigFiles(ContainerInterface $container) { // テンプレートファイルコピー $templatePath = $container->getParameter('eccube_theme_front_dir') . '/Passkeys/Resource/template/default'; $fs = new Filesystem(); if ($fs->exists($templatePath)) { return; } $fs->mkdir($templatePath); $fs->mirror(__DIR__ . '/Resource/template/default', $templatePath); } /** * ページ情報の登録 * * @param EntityManagerInterface $em */ protected function createPages(EntityManagerInterface $em) { foreach ($this->pages as $p) { log_info('pk:createPages:'.$p[0]); $hasPage = $em->getRepository(Page::class)->count(['url' => $p[0]]) > 0; if (!$hasPage) { /** @var Page $Page */ $Page = $em->getRepository(Page::class)->newPage(); $Page->setEditType(Page::EDIT_TYPE_DEFAULT); $Page->setUrl($p[0]); $Page->setName($p[1]); $Page->setFileName($p[2]); $Page->setMetaRobots('noindex'); $em->persist($Page); $em->flush(); $Layout = $em->getRepository(Layout::class)->find(Layout::DEFAULT_LAYOUT_UNDERLAYER_PAGE); $PageLayout = new PageLayout(); $PageLayout->setPage($Page) ->setPageId($Page->getId()) ->setLayout($Layout) ->setLayoutId($Layout->getId()) ->setSortNo(0); $em->persist($PageLayout); $em->flush(); } } } /** * @param array $meta * @param ContainerInterface $container */ public function disable(array $meta, ContainerInterface $container) { $em = $container->get('doctrine')->getManager(); // twigファイルを削除 $this->removeTwigFiles($container); // ページ削除 $this->removePages($em); } /** * Twigファイルの削除 * * @param ContainerInterface $container */ protected function removeTwigFiles(ContainerInterface $container) { $templatePath = $container->getParameter('eccube_theme_front_dir') . '/Passkeys'; $fs = new Filesystem(); $fs->remove($templatePath); } /** * ページ情報の削除 * * @param EntityManagerInterface $em */ protected function removePages(EntityManagerInterface $em) { foreach ($this->pages as $p) { $Page = $em->getRepository(Page::class)->findOneBy(['url' => $p[0]]); if ($Page !== null) { $Layout = $em->getRepository(Layout::class)->find(Layout::DEFAULT_LAYOUT_UNDERLAYER_PAGE); $PageLayout = $em->getRepository(PageLayout::class)->findOneBy(['Page' => $Page, 'Layout' => $Layout]); $em->remove($PageLayout); $em->remove($Page); $em->flush(); } } } /** * @param array $meta * @param ContainerInterface $container */ public function uninstall(array $meta, ContainerInterface $container) { $em = $container->get('doctrine')->getManager(); // twigファイルを削除 $this->removeTwigFiles($container); // ページ削除 $this->removePages($em); } }