cleanup code

This commit is contained in:
Daniel Seifert 2024-12-03 14:12:24 +01:00
parent ffeda6e691
commit 9965278a2c
7 changed files with 22 additions and 196 deletions

View File

@ -1,169 +0,0 @@
<?php
/**
* This file is part of O3-Shop TinyMCE editor module.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
*
* @copyright Copyright (c) 2022 Marat Bedoev, bestlife AG
* @copyright Copyright (c) 2023 O3-Shop (https://www.o3-shop.com)
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
*/
declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\Setup;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Console\CommandsProvider\ServicesCommandsProvider;
use OxidEsales\EshopCommunity\Internal\Framework\Console\Executor;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface;
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\DataObject\ModuleConfiguration\Template;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration\TemplateBlock;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleConfigurationNotFoundException;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Bridge\TemplateBlockModuleSettingHandlerBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Handler\TemplateBlockModuleSettingHandler;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
class Actions
{
/**
* apply updated class extensions to yaml files
*
* @return void
* @throws ModuleConfigurationNotFoundException
*/
public function installApplyNewConfiguration()
{
/** @var ShopConfigurationDaoBridgeInterface $shopConfiguration */
$shopConfiguration = ContainerFactory::getInstance()->getContainer()->get(ShopConfigurationDaoBridgeInterface::class);
$beforeHash = md5(serialize($shopConfiguration->get()->getModuleConfiguration('o3-tinymce-editor')));
$executor = $this->getCommandExecutor();
$add = php_sapi_name() == 'cli' ? 'source/' : (isAdmin() ? '../' : '');
$input = new ArrayInput([
'command' => 'oe:module:install-configuration',
'module-source-path' => $add.'modules/o3-shop/tinymce-editor/'
]);
$executor->execute($input);
$changedConfiguration =
md5(serialize($shopConfiguration->get()->getModuleConfiguration('o3-tinymce-editor'))) !== $beforeHash;
if ($changedConfiguration) {
/** @var ModuleConfigurationDaoBridgeInterface $mas */
$mas = ContainerFactory::getInstance()->getContainer()->get(ModuleConfigurationDaoBridgeInterface::class);
/** @var TemplateBlockModuleSettingHandler $tbsh */
$tbsh = ContainerFactory::getInstance()->getContainer()->get(TemplateBlockModuleSettingHandlerBridgeInterface::class);
$tbsh->handleOnModuleDeactivation($mas->get('o3-tinymce-editor'), Registry::getConfig()->getShopId());
$tbsh->handleOnModuleActivation($mas->get('o3-tinymce-editor'), Registry::getConfig()->getShopId());
}
}
/**
* clear cache
*/
public function clearCache(): void
{
try {
$oUtils = Registry::getUtils();
$oUtils->resetTemplateCache($this->getModuleTemplates());
$oUtils->resetLanguageCache();
} catch (ContainerExceptionInterface|NotFoundExceptionInterface|ModuleConfigurationNotFoundException $e) {
Registry::getLogger()->error($e->getMessage(), [$this]);
Registry::getUtilsView()->addErrorToDisplay($e->getMessage());
}
}
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ModuleConfigurationNotFoundException
*/
protected function getModuleTemplates(): array
{
$container = $this->getDIContainer();
$shopConfiguration = $container->get(ShopConfigurationDaoBridgeInterface::class)->get();
$moduleConfiguration = $shopConfiguration->getModuleConfiguration('o3-tinymce-editor');
return array_unique(
array_merge(
$this->getModuleTemplatesFromTemplates($moduleConfiguration),
$this->getModuleTemplatesFromBlocks($moduleConfiguration)
)
);
}
/**
* @param ModuleConfiguration $moduleConfiguration
*
* @return array
*/
protected function getModuleTemplatesFromTemplates(ModuleConfiguration $moduleConfiguration): array
{
/** @var $template Template */
return array_map(
function ($template) {
return $template->getTemplateKey();
},
$moduleConfiguration->getTemplates()
);
}
/**
* @param ModuleConfiguration $moduleConfiguration
*
* @return array
*/
protected function getModuleTemplatesFromBlocks(ModuleConfiguration $moduleConfiguration): array
{
/** @var $templateBlock TemplateBlock */
return array_map(
function ($templateBlock) {
return basename($templateBlock->getShopTemplatePath());
},
$moduleConfiguration->getTemplateBlocks()
);
}
/**
* @return ContainerInterface|null
*/
protected function getDIContainer(): ?ContainerInterface
{
return ContainerFactory::getInstance()->getContainer();
}
/**
* @return Executor
*/
protected function getCommandExecutor(): Executor
{
$servicesCommandsProvider = new ServicesCommandsProvider(ContainerFactory::getInstance()->getContainer());
$application = new Application();
$application->setAutoExit(false);
return new Executor($application, $servicesCommandsProvider);
}
}

View File

@ -23,20 +23,14 @@ declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\Setup;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleConfigurationNotFoundException;
class Events
{
/**
* Execute action on activate event
* @return void
* @throws ModuleConfigurationNotFoundException
*/
public static function onActivate(): void
{
$actions = oxNew(Actions::class);
$actions->installApplyNewConfiguration();
$actions->clearCache();
}
/**
@ -44,7 +38,5 @@ class Events
*/
public static function onDeactivate(): void
{
$actions = oxNew(Actions::class);
$actions->clearCache();
}
}

View File

@ -36,7 +36,6 @@ use O3\TinyMCE\Application\Core\TinyMCE\Options\InitInstanceCallback;
use O3\TinyMCE\Application\Core\TinyMCE\Options\Language;
use O3\TinyMCE\Application\Core\TinyMCE\Options\LicenseKey;
use O3\TinyMCE\Application\Core\TinyMCE\Options\MaxHeight;
use O3\TinyMCE\Application\Core\TinyMCE\Options\MaxWidth;
use O3\TinyMCE\Application\Core\TinyMCE\Options\Menubar;
use O3\TinyMCE\Application\Core\TinyMCE\Options\MinHeight;
use O3\TinyMCE\Application\Core\TinyMCE\Options\OptionInterface;

View File

@ -23,11 +23,9 @@ declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\TinyMCE;
use OxidEsales\Eshop\Application\Model\Content;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\FileException;
use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\Model\BaseModel;
use OxidEsales\Eshop\Core\Registry;
class Loader
@ -86,9 +84,9 @@ class Loader
// D3 disabled, because isPlain method doesn't exist in OXID eShop
return false;
/** @var BaseModel|Content $oEditObject */
$oEditObject = $this->getShopConfig()->getActiveView()->getViewDataElement("edit");
return $oEditObject instanceof Content && $oEditObject->isPlain();
// /** @var BaseModel|Content $oEditObject */
// $oEditObject = $this->getShopConfig()->getActiveView()->getViewDataElement("edit");
// return $oEditObject instanceof Content && $oEditObject->isPlain();
}
/**

View File

@ -23,8 +23,6 @@ declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
use O3\TinyMCE\Application\Core\TinyMCE\PluginList;
use O3\TinyMCE\Application\Core\TinyMCE\Plugins\PluginInterface;
use O3\TinyMCE\Application\Core\TinyMCE\Utils;
class InitInstanceCallback extends AbstractOption

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace O3\TinyMCE\Application\Core\TinyMCE\Options;
use OxidEsales\EshopCommunity\Core\Exception\LanguageNotFoundException;
class Language extends AbstractOption
{
protected string $key = 'language';
@ -36,17 +38,22 @@ class Language extends AbstractOption
$oLang = $this->loader->getLanguage();
$aLang = [
"cs" => "cs",
"da" => "da",
"de" => "de",
"es" => "es_419",
"fr" => "fr_FR",
"it" => "it_IT",
"nl" => "nl",
"ru" => "ru",
];
return $aLang[ $oLang->getLanguageAbbr((int) $oLang->getTplLanguage()) ] ?? "en";
try {
$aLang = [
"cs" => "cs",
"da" => "da",
"de" => "de",
"es" => "es_419",
"fr" => "fr_FR",
"it" => "it_IT",
"nl" => "nl",
"ru" => "ru",
];
return $aLang[ $oLang->getLanguageAbbr( (int) $oLang->getTplLanguage() ) ] ?? "en";
} catch (LanguageNotFoundException) {
return "en";
}
}
public function isQuoted(): bool

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
function checkAccess(string $action): void
{
unset($action);
if ($_COOKIE['filemanagerkey'] !== md5($_SERVER['DOCUMENT_ROOT'].$_COOKIE['admin_sid'])) {
die('Access Denied!!');
}