refactoring

This commit is contained in:
2024-07-03 09:32:01 +02:00
parent f183c61c57
commit 346a189881
7 changed files with 112 additions and 65 deletions

View File

@ -2,21 +2,23 @@
namespace D3\Devhelper\Application\Controller; namespace D3\Devhelper\Application\Controller;
use D3\Devhelper\Application\Model\Exception\UnauthorisedException;
use D3\Devhelper\Modules\Application\Controller as ModuleController; use D3\Devhelper\Modules\Application\Controller as ModuleController;
use D3\Devhelper\Modules\Core as ModuleCore; use D3\Devhelper\Modules\Core as ModuleCore;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use Exception; use Exception;
use GuzzleHttp\Psr7\ServerRequest; use GuzzleHttp\Psr7\ServerRequest;
use OxidEsales\Eshop\Application\Controller\FrontendController; use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Controller\ThankYouController; use OxidEsales\Eshop\Application\Controller\ThankYouController;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Email; use OxidEsales\Eshop\Core\Email;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\UserException; use OxidEsales\Eshop\Core\Exception\UserException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService; use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* This Software is the property of Data Development and is protected * This Software is the property of Data Development and is protected
@ -84,19 +86,21 @@ class d3dev extends FrontendController
} }
/** /**
* @throws DatabaseConnectionException * @throws ContainerExceptionInterface
* @throws DatabaseErrorException * @throws NotFoundExceptionInterface
* @throws DBALDriverException
*/ */
public function showOrderMailContent() public function showOrderMailContent(): void
{ {
try {
header( 'Content-type: text/html; charset=' . Registry::getLang()->translateString( 'charset' ) ); header( 'Content-type: text/html; charset=' . Registry::getLang()->translateString( 'charset' ) );
/** @var ModuleSettingService $moduleSettingService */ /** @var ModuleSettingService $moduleSettingService */
$moduleSettingService = ContainerFactory::getInstance()->getContainer()->get( ModuleSettingServiceInterface::class ); $moduleSettingService = ContainerFactory::getInstance()->getContainer()->get( ModuleSettingServiceInterface::class );
if ( Registry::getConfig()->getActiveShop()->isProductiveMode() if ( Registry::getConfig()->getActiveShop()->isProductiveMode() ||
|| ! $moduleSettingService->getBoolean( ModuleCore\d3_dev_conf::OPTION_SHOWMAILSINBROWSER, 'd3dev' ) ! $moduleSettingService->getBoolean( ModuleCore\d3_dev_conf::OPTION_SHOWMAILSINBROWSER, 'd3dev' )
) { ) {
Registry::getUtils()->redirect(Registry::getConfig()->getShopUrl().'index.php?cl=start'); throw oxNew(UnauthorisedException::class);
} }
$sTpl = Registry::getRequest()->getRequestEscapedParameter( 'type' ); $sTpl = Registry::getRequest()->getRequestEscapedParameter( 'type' );
@ -108,6 +112,16 @@ class d3dev extends FrontendController
/** @var ModuleCore\d3_dev_oxemail $oEmail */ /** @var ModuleCore\d3_dev_oxemail $oEmail */
$oEmail = oxNew( Email::class ); $oEmail = oxNew( Email::class );
echo $oEmail->d3GetOrderMailContent( $oOrder, $sTpl ); echo $oEmail->d3GetOrderMailContent( $oOrder, $sTpl );
http_response_code( 200 );
} catch (UnauthorisedException $exception) {
echo $exception->getMessage();
http_response_code(401);
} catch (Exception $exception) {
echo $exception->getMessage();
http_response_code(400);
} finally {
Registry::getConfig()->pageClose();
die(); die();
} }
} }
}

View File

@ -0,0 +1,14 @@
<?php
namespace D3\Devhelper\Application\Model\Exception;
use Exception;
use OxidEsales\Eshop\Core\Exception\StandardException;
class NoOrderFoundException extends StandardException
{
public function __construct( $sMessage = "no order found", $iCode = 0, Exception $previous = null )
{
parent::__construct( $sMessage, $iCode, $previous );
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace D3\Devhelper\Application\Model\Exception;
use OxidEsales\Eshop\Core\Exception\StandardException;
class UnauthorisedException extends StandardException
{
public function __construct( $sMessage = "unauthorised, disable productive and activate option", $iCode = 0, Exception $previous = null )
{
parent::__construct( $sMessage, $iCode, $previous );
}
}

View File

@ -3,8 +3,12 @@
namespace D3\Devhelper\Modules\Application\Controller; namespace D3\Devhelper\Modules\Application\Controller;
// .../?cl=thankyou[&d3orderid=23] // .../?cl=thankyou[&d3orderid=23]
use D3\Devhelper\Application\Model\Exception\NoOrderFoundException;
use D3\Devhelper\Application\Model\Exception\UnauthorisedException;
use D3\Devhelper\Modules\Application\Model\d3_dev_oxorder; use D3\Devhelper\Modules\Application\Model\d3_dev_oxorder;
use D3\Devhelper\Modules\Core\d3_dev_conf; use D3\Devhelper\Modules\Core\d3_dev_conf;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use Doctrine\DBAL\Exception as DBALException;
use Exception; use Exception;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
@ -12,7 +16,8 @@ use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\UserException; use OxidEsales\Eshop\Core\Exception\UserException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use oxOrder; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* This Software is the property of Data Development and is protected * This Software is the property of Data Development and is protected
@ -42,7 +47,7 @@ class d3_dev_thankyou extends d3_dev_thankyou_parent
parent::init(); parent::init();
if (Registry::getRequest()->getRequestEscapedParameter("d3dev") if (Registry::getRequest()->getRequestEscapedParameter("d3dev")
&& false == (bool) Registry::getConfig()->getActiveShop()->isProductiveMode() && !Registry::getConfig()->getActiveShop()->isProductiveMode()
&& Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_PREVENTDELBASKET) && Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_PREVENTDELBASKET)
) { ) {
Registry::getSession()->setVariable( 'sess_challenge', $sSessChallenge ); Registry::getSession()->setVariable( 'sess_challenge', $sSessChallenge );
@ -60,9 +65,9 @@ class d3_dev_thankyou extends d3_dev_thankyou_parent
*/ */
public function d3DevCanShowThankyou() public function d3DevCanShowThankyou()
{ {
return Registry::getRequest()->getRequestEscapedParameter("d3dev") return Registry::getRequest()->getRequestEscapedParameter("d3dev") &&
&& false == (bool) Registry::getConfig()->getActiveShop()->isProductiveMode() !Registry::getConfig()->getActiveShop()->isProductiveMode() &&
&& Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_SHOWTHANKYOU); Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_SHOWTHANKYOU);
} }
/** /**
@ -128,7 +133,7 @@ class d3_dev_thankyou extends d3_dev_thankyou_parent
} }
/** /**
* @return bool|d3_dev_oxorder|oxOrder * @return bool|d3_dev_oxorder|Order
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DatabaseErrorException * @throws DatabaseErrorException
*/ */
@ -155,14 +160,19 @@ class d3_dev_thankyou extends d3_dev_thankyou_parent
} }
/** /**
* @return bool|d3_dev_oxorder * @return d3_dev_oxorder
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DatabaseErrorException * @throws DatabaseErrorException
* @throws NoOrderFoundException
* @throws DBALDriverException
* @throws DBALException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function d3GetLastOrder() public function d3GetLastOrder(): d3_dev_oxorder
{ {
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) { if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
return false; throw oxNew(UnauthorisedException::class);
} }
/** @var d3_dev_oxorder $oOrder */ /** @var d3_dev_oxorder $oOrder */

View File

@ -29,7 +29,7 @@ class d3_dev_oxbasket extends d3_dev_oxbasket_parent
public function deleteBasket() public function deleteBasket()
{ {
if ( Registry::getConfig()->getActiveShop()->isProductiveMode() if ( Registry::getConfig()->getActiveShop()->isProductiveMode()
|| false == Registry::getConfig()->getConfigParam(d3_dev_conf::OPTION_PREVENTDELBASKET) || ! Registry::getConfig()->getConfigParam( d3_dev_conf::OPTION_PREVENTDELBASKET )
) { ) {
parent::deleteBasket(); parent::deleteBasket();
} }

View File

@ -17,6 +17,9 @@
namespace D3\Devhelper\Modules\Application\Model; namespace D3\Devhelper\Modules\Application\Model;
use D3\Devhelper\Application\Model\Exception\NoOrderFoundException;
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use oxarticleinputexception; use oxarticleinputexception;
use OxidEsales\Eshop\Application\Model\Basket; use OxidEsales\Eshop\Application\Model\Basket;
@ -24,11 +27,14 @@ use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Voucher; use OxidEsales\Eshop\Application\Model\Voucher;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\SystemComponentException;
use OxidEsales\Eshop\Core\Model\ListModel; use OxidEsales\Eshop\Core\Model\ListModel;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use oxnoarticleexception; use oxnoarticleexception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class d3_dev_oxorder extends d3_dev_oxorder_parent class d3_dev_oxorder extends d3_dev_oxorder_parent
{ {
@ -53,10 +59,13 @@ class d3_dev_oxorder extends d3_dev_oxorder_parent
} }
/** /**
* @return string * @return false|string
* @throws DatabaseConnectionException * @throws ContainerExceptionInterface
* @throws DBALException
* @throws DBALDriverException
* @throws NotFoundExceptionInterface
*/ */
public function d3getLastOrderId() public function d3getLastOrderId(): false|string
{ {
/** @var QueryBuilder $qb */ /** @var QueryBuilder $qb */
$qb = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); $qb = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
@ -64,7 +73,7 @@ class d3_dev_oxorder extends d3_dev_oxorder_parent
->from((oxNew(Order::class))->getViewName()) ->from((oxNew(Order::class))->getViewName())
->where( ->where(
$qb->expr()->and( $qb->expr()->and(
$qb->expr()->eq( $qb->expr()->neq(
'oxuserid', 'oxuserid',
$qb->createNamedParameter('') $qb->createNamedParameter('')
), ),
@ -91,13 +100,22 @@ class d3_dev_oxorder extends d3_dev_oxorder_parent
} }
/** /**
* @throws ContainerExceptionInterface
* @throws DBALDriverException
* @throws DBALException
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DatabaseErrorException * @throws DatabaseErrorException
* @throws NoOrderFoundException
* @throws NotFoundExceptionInterface
*/ */
public function d3getLastOrder() public function d3getLastOrder(): void
{ {
$this->load($this->d3getLastOrderId()); if ($orderId = $this->d3getLastOrderId()) {
$this->load($orderId);
$this->_d3AddVouchers(); $this->_d3AddVouchers();
} else {
throw new NoOrderFoundException();
}
} }
/** /**

View File

@ -17,6 +17,7 @@
namespace D3\Devhelper\Modules\Core; namespace D3\Devhelper\Modules\Core;
use D3\Devhelper\Application\Model\Exception\UnauthorisedException;
use D3\Devhelper\Modules\Application\Model as ModuleModel; use D3\Devhelper\Modules\Application\Model as ModuleModel;
use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
@ -34,7 +35,7 @@ class d3_dev_oxemail extends d3_dev_oxemail_parent
public function d3GetOrderMailContent($oOrder, $sType) public function d3GetOrderMailContent($oOrder, $sType)
{ {
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) { if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
return ''; throw oxNew(UnauthorisedException::class);
} }
switch (strtolower($sType)) { switch (strtolower($sType)) {
@ -129,29 +130,6 @@ class d3_dev_oxemail extends d3_dev_oxemail_parent
return $aCc; return $aCc;
} }
/**
* @return bool
* @throws StandardException
*/
protected function _sendMail()
{
if (Registry::getConfig()->getActiveShop()->isProductiveMode()) {
return parent::_sendMail();
}
$this->d3clearRecipients();
$this->d3clearReplies();
$this->d3clearReplyTo();
$this->d3clearCC();
$this->d3clearBCC();
if (count($this->getRecipient())) {
return parent::_sendMail();
}
return true;
}
/** /**
* @return bool * @return bool
* @throws StandardException * @throws StandardException