2022-12-10 23:55:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace D3\Webauthn\Setup;
|
|
|
|
|
2022-12-11 23:12:17 +01:00
|
|
|
use D3\TestingTools\Production\IsMockable;
|
2022-12-10 23:55:53 +01:00
|
|
|
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
|
|
|
|
use Exception;
|
2023-02-10 00:52:44 +01:00
|
|
|
use OxidEsales\DoctrineMigrationWrapper\MigrationsBuilder;
|
2022-12-11 23:12:17 +01:00
|
|
|
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
|
|
|
use OxidEsales\Eshop\Core\Config;
|
2022-12-10 23:55:53 +01:00
|
|
|
use OxidEsales\Eshop\Core\DbMetaDataHandler;
|
2022-12-11 23:12:17 +01:00
|
|
|
use OxidEsales\Eshop\Core\SeoEncoder;
|
|
|
|
use OxidEsales\Eshop\Core\Utils;
|
2022-12-10 23:55:53 +01:00
|
|
|
use OxidEsales\Eshop\Core\UtilsView;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
2022-12-11 23:12:17 +01:00
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
|
|
|
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleConfigurationNotFoundException;
|
2022-12-10 23:55:53 +01:00
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
2022-12-11 23:12:17 +01:00
|
|
|
use Psr\Container\ContainerInterface;
|
2022-12-10 23:55:53 +01:00
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
2023-01-21 13:50:18 +01:00
|
|
|
use Psr\Log\LoggerInterface;
|
2022-12-10 23:55:53 +01:00
|
|
|
|
|
|
|
class Actions
|
|
|
|
{
|
2023-01-28 23:41:39 +01:00
|
|
|
use IsMockable;
|
2023-01-27 08:49:09 +01:00
|
|
|
|
2022-12-11 23:12:17 +01:00
|
|
|
public $seo_de = 'sicherheitsschluessel';
|
|
|
|
public $seo_en = 'en/key-authentication';
|
|
|
|
public $stdClassName = 'd3_account_webauthn';
|
|
|
|
|
2023-02-16 23:52:20 +01:00
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2023-02-10 00:52:44 +01:00
|
|
|
public function runModuleMigrations()
|
2022-12-10 23:55:53 +01:00
|
|
|
{
|
2023-02-10 00:52:44 +01:00
|
|
|
/** @var MigrationsBuilder $migrationsBuilder */
|
|
|
|
$migrationsBuilder = d3GetOxidDIC()->get('d3ox.webauthn.'.MigrationsBuilder::class);
|
|
|
|
$migrations = $migrationsBuilder->build();
|
|
|
|
$migrations->execute('migrations:migrate', 'd3webauthn');
|
2022-12-10 23:55:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Regenerate views for changed tables
|
2023-02-16 23:52:20 +01:00
|
|
|
* @throws Exception
|
2022-12-10 23:55:53 +01:00
|
|
|
*/
|
|
|
|
public function regenerateViews()
|
|
|
|
{
|
2023-01-21 13:50:18 +01:00
|
|
|
$oDbMetaDataHandler = d3GetOxidDIC()->get('d3ox.webauthn.'.DbMetaDataHandler::class);
|
2022-12-10 23:55:53 +01:00
|
|
|
$oDbMetaDataHandler->updateViews();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clear cache
|
2023-02-16 23:52:20 +01:00
|
|
|
* @throws Exception
|
2022-12-10 23:55:53 +01:00
|
|
|
*/
|
|
|
|
public function clearCache()
|
|
|
|
{
|
2022-12-11 23:12:17 +01:00
|
|
|
try {
|
2023-01-21 13:50:18 +01:00
|
|
|
$oUtils = d3GetOxidDIC()->get('d3ox.webauthn.'.Utils::class);
|
2022-12-13 22:24:33 +01:00
|
|
|
$oUtils->resetTemplateCache($this->getModuleTemplates());
|
2022-12-11 23:12:17 +01:00
|
|
|
$oUtils->resetLanguageCache();
|
|
|
|
} catch (ContainerExceptionInterface|NotFoundExceptionInterface|ModuleConfigurationNotFoundException $e) {
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->error($e->getMessage(), [$this]);
|
|
|
|
d3GetOxidDIC()->get('d3ox.webauthn.'.UtilsView::class)->addErrorToDisplay($e->getMessage());
|
2022-12-10 23:55:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-11 23:12:17 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
* @throws ModuleConfigurationNotFoundException
|
|
|
|
*/
|
|
|
|
protected function getModuleTemplates(): array
|
|
|
|
{
|
|
|
|
$container = $this->getDIContainer();
|
|
|
|
$shopConfiguration = $container->get(ShopConfigurationDaoBridgeInterface::class)->get();
|
|
|
|
$moduleConfiguration = $shopConfiguration->getModuleConfiguration('d3webauthn');
|
|
|
|
|
|
|
|
return array_unique(array_merge(
|
|
|
|
$this->getModuleTemplatesFromTemplates($moduleConfiguration),
|
|
|
|
$this->getModuleTemplatesFromBlocks($moduleConfiguration)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ModuleConfiguration $moduleConfiguration
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getModuleTemplatesFromTemplates(ModuleConfiguration $moduleConfiguration): array
|
|
|
|
{
|
|
|
|
/** @var $template ModuleConfiguration\Template */
|
|
|
|
return array_map(
|
2022-12-13 22:24:33 +01:00
|
|
|
function ($template) {
|
2022-12-11 23:12:17 +01:00
|
|
|
return $template->getTemplateKey();
|
|
|
|
},
|
|
|
|
$moduleConfiguration->getTemplates()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ModuleConfiguration $moduleConfiguration
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getModuleTemplatesFromBlocks(ModuleConfiguration $moduleConfiguration): array
|
|
|
|
{
|
|
|
|
/** @var $templateBlock ModuleConfiguration\TemplateBlock */
|
|
|
|
return array_map(
|
2022-12-13 22:24:33 +01:00
|
|
|
function ($templateBlock) {
|
2022-12-11 23:12:17 +01:00
|
|
|
return basename($templateBlock->getShopTemplatePath());
|
|
|
|
},
|
|
|
|
$moduleConfiguration->getTemplateBlocks()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-10 23:55:53 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
2023-02-16 23:52:20 +01:00
|
|
|
* @throws Exception
|
2022-12-10 23:55:53 +01:00
|
|
|
*/
|
|
|
|
public function seoUrl()
|
|
|
|
{
|
|
|
|
try {
|
2022-12-11 23:12:17 +01:00
|
|
|
if (!$this->hasSeoUrl()) {
|
|
|
|
$this->createSeoUrl();
|
2022-12-10 23:55:53 +01:00
|
|
|
}
|
|
|
|
} catch (Exception|NotFoundExceptionInterface|DoctrineDriverException|ContainerExceptionInterface $e) {
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->get('d3ox.webauthn.'.LoggerInterface::class)->error($e->getMessage(), [$this]);
|
|
|
|
d3GetOxidDIC()->get('d3ox.webauthn.'.UtilsView::class)
|
2022-12-11 23:12:17 +01:00
|
|
|
->addErrorToDisplay('error wile creating SEO URLs: '.$e->getMessage());
|
2022-12-10 23:55:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
2023-02-16 23:52:20 +01:00
|
|
|
* @throws Exception
|
2022-12-10 23:55:53 +01:00
|
|
|
*/
|
|
|
|
public function hasSeoUrl(): bool
|
|
|
|
{
|
2023-02-16 23:52:20 +01:00
|
|
|
/** @var SeoEncoder $seoEncoder */
|
2023-01-21 13:50:18 +01:00
|
|
|
$seoEncoder = d3GetOxidDIC()->get('d3ox.webauthn.'.SeoEncoder::class);
|
2022-12-11 23:12:17 +01:00
|
|
|
$seoUrl = $seoEncoder->getStaticUrl(
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->get('d3ox.webauthn.'.FrontendController::class)->getViewConfig()->getSelfLink() .
|
2022-12-11 23:12:17 +01:00
|
|
|
"cl=".$this->stdClassName
|
|
|
|
);
|
|
|
|
|
|
|
|
return (bool) strlen($seoUrl);
|
2022-12-10 23:55:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
2023-02-16 23:52:20 +01:00
|
|
|
* @throws Exception
|
2022-12-10 23:55:53 +01:00
|
|
|
*/
|
|
|
|
public function createSeoUrl()
|
|
|
|
{
|
2023-01-21 13:50:18 +01:00
|
|
|
$seoEncoder = d3GetOxidDIC()->get('d3ox.webauthn.'.SeoEncoder::class);
|
2022-12-11 23:12:17 +01:00
|
|
|
$seoEncoder->addSeoEntry(
|
|
|
|
'ff57646b47249ee33c6b672741ac371a',
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->get('d3ox.webauthn.'.Config::class)->getShopId(),
|
2022-12-11 23:12:17 +01:00
|
|
|
0,
|
|
|
|
'index.php?cl='.$this->stdClassName,
|
|
|
|
$this->seo_de,
|
|
|
|
'static',
|
2022-12-12 23:41:07 +01:00
|
|
|
false
|
2022-12-11 23:12:17 +01:00
|
|
|
);
|
|
|
|
$seoEncoder->addSeoEntry(
|
|
|
|
'ff57646b47249ee33c6b672741ac371a',
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->get('d3ox.webauthn.'.Config::class)->getShopId(),
|
2022-12-11 23:12:17 +01:00
|
|
|
1,
|
|
|
|
'index.php?cl='.$this->stdClassName,
|
|
|
|
$this->seo_en,
|
|
|
|
'static',
|
2022-12-12 23:41:07 +01:00
|
|
|
false
|
2022-12-11 23:12:17 +01:00
|
|
|
);
|
|
|
|
}
|
2022-12-10 23:55:53 +01:00
|
|
|
|
2022-12-11 23:12:17 +01:00
|
|
|
/**
|
|
|
|
* @return ContainerInterface|null
|
|
|
|
*/
|
|
|
|
protected function getDIContainer(): ?ContainerInterface
|
|
|
|
{
|
|
|
|
return ContainerFactory::getInstance()->getContainer();
|
2022-12-10 23:55:53 +01:00
|
|
|
}
|
2022-12-13 22:24:33 +01:00
|
|
|
}
|