catch thrown recipient exceptions in admin controllers

Cette révision appartient à :
Daniel Seifert 2022-07-18 13:25:26 +02:00
Parent 1a896e26c2
révision e159aaa3b0
Signé par: DanielS
ID de la clé GPG: 8A7C4C6ED1915C6F
3 fichiers modifiés avec 53 ajouts et 11 suppressions

Voir le fichier

@ -16,10 +16,12 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Model;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\LinkmobilityClient\Exceptions\RecipientException;
use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\ValueObject\Recipient;
use libphonenumber\NumberParseException;
use OxidEsales\Eshop\Application\Model\Country;
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\Registry;
class OrderRecipients
{
@ -41,12 +43,17 @@ class OrderRecipients
{
foreach ($this->getSmsRecipientFields() as $phoneFieldName => $countryIdFieldName) {
$content = trim((string) $this->order->getFieldData($phoneFieldName));
$country = oxNew( Country::class );
if (strlen($content)) {
$country = oxNew(Country::class);
$country->load($this->order->getFieldData($countryIdFieldName));
return oxNew(Recipient::class, $content, $country->getFieldData('oxisoalpha2'));
try {
if ( strlen( $content ) ) {
$country->load( $this->order->getFieldData( $countryIdFieldName ) );
return oxNew( Recipient::class, $content, $country->getFieldData( 'oxisoalpha2' ) );
}
} catch (NumberParseException $e) {
LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData( 'oxisoalpha2' )]);
} catch (RecipientException $e) {
LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData( 'oxisoalpha2' )]);
}
}

Voir le fichier

@ -16,10 +16,12 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Model;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\LinkmobilityClient\Exceptions\RecipientException;
use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\ValueObject\Recipient;
use libphonenumber\NumberParseException;
use OxidEsales\Eshop\Application\Model\Country;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
class UserRecipients
{
@ -41,11 +43,17 @@ class UserRecipients
{
foreach ($this->getSmsRecipientFields() as $fieldName) {
$content = trim($this->user->getFieldData($fieldName));
if (strlen($content)) {
$country = oxNew(Country::class);
$country->load($this->user->getFieldData('oxcountryid'));
$country = oxNew( Country::class );
return oxNew(Recipient::class, $content, $country->getFieldData('oxisoalpha2'));
try {
if ( strlen( $content ) ) {
$country->load( $this->user->getFieldData( 'oxcountryid' ) );
return oxNew( Recipient::class, $content, $country->getFieldData( 'oxisoalpha2' ) );
}
} catch (NumberParseException $e) {
LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData( 'oxisoalpha2' )]);
} catch (RecipientException $e) {
LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData( 'oxisoalpha2' )]);
}
}

Voir le fichier

@ -21,6 +21,8 @@ use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class EmailCore extends EmailCore_parent
{
@ -33,6 +35,8 @@ class EmailCore extends EmailCore_parent
* @param null $subject
*
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function sendOrderEmailToUser($order, $subject = null)
{
@ -48,6 +52,8 @@ class EmailCore extends EmailCore_parent
* @param null $subject
*
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function sendSendedNowMail($order, $subject = null)
{
@ -60,6 +66,10 @@ class EmailCore extends EmailCore_parent
/**
* @param Order $order
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function d3SendOrderFinishedMessageToUser(Order $order)
{
@ -71,6 +81,8 @@ class EmailCore extends EmailCore_parent
* @param Order $order
*
* @return string
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function d3GetOrderFinishedSmsMessageBody(Order $order): string
{
@ -83,6 +95,8 @@ class EmailCore extends EmailCore_parent
/**
* @param Order $order
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function d3SendedNowMessage(Order $order)
@ -95,6 +109,8 @@ class EmailCore extends EmailCore_parent
* @param Order $order
*
* @return string
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function d3GetSendedNowSmsMessageBody(Order $order): string
{
@ -104,6 +120,13 @@ class EmailCore extends EmailCore_parent
return $renderer->renderTemplate($this->d3OrderSendedNowSmsTemplate, $this->getViewData());
}
/**
* @param $order
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws Exception
*/
public function d3SendCancelMessage($order)
{
$messageSender = oxNew(MessageSender::class);
@ -114,6 +137,8 @@ class EmailCore extends EmailCore_parent
* @param Order $order
*
* @return string
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function d3GetCancelOrderSmsMessageBody(Order $order): string
{
@ -127,6 +152,8 @@ class EmailCore extends EmailCore_parent
* Templating instance getter
*
* @return TemplateRendererInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function d3GetTplRenderer(): TemplateRendererInterface
{