set remark information in error case too

This commit is contained in:
Daniel Seifert 2022-08-07 21:53:01 +02:00
parent ea388af268
commit 42cf5721ce
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
3 changed files with 53 additions and 43 deletions

View File

@ -19,9 +19,13 @@ use D3\Linkmobility4Ordermanager\Application\Model\d3linkmobility_ordermanager_s
use D3\Linkmobility4Ordermanager\Application\Model\Exceptions\emptyMesageException; use D3\Linkmobility4Ordermanager\Application\Model\Exceptions\emptyMesageException;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception; use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ParameterNotFoundException;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use D3\Ordermanager\Application\Model\Actions\d3ordermanager_action_abstract; use D3\Ordermanager\Application\Model\Actions\d3ordermanager_action_abstract;
use D3\Ordermanager\Application\Model\d3ordermanager_conf; use D3\Ordermanager\Application\Model\d3ordermanager_conf;
use D3\Ordermanager\Application\Model\Exceptions\d3ActionRequirementAbstract;
use D3\Ordermanager\Application\Model\Exceptions\d3ordermanager_actionException;
use DebugBar\DebugBarException;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Model\Content; use OxidEsales\Eshop\Application\Model\Content;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
@ -64,8 +68,7 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
} elseif ($this->hasRequiredValuesCmsSource(false)) { } elseif ($this->hasRequiredValuesCmsSource(false)) {
return 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDCMS'; return 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDCMS';
} else { } else {
return 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_UNDEFINED';
return 'foo';
} }
} }
@ -73,49 +76,51 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
* @throws DBALException * @throws DBALException
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DatabaseErrorException * @throws DatabaseErrorException
* @throws DatabaseException
* @throws StandardException * @throws StandardException
* @throws d3ParameterNotFoundException
* @throws d3ActionRequirementAbstract
* @throws d3ordermanager_actionException
* @throws DebugBarException
* @throws d3ShopCompatibilityAdapterException * @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception * @throws d3_cfg_mod_exception
*/ */
public function startAction() public function startAction()
{ {
if (false == $this->isExecutable()) { if (false === $this->isExecutable()) {
return; return;
} }
$this->throwUnvalidConfigurationException(); $this->throwUnvalidConfigurationException();
startProfile(__METHOD__); startProfile(__METHOD__);
/** @var Language $oLang */ /** @var Language $oLang */
$oLang = oxNew(Language::class); $oLang = oxNew(Language::class);
$this->getManager()->getRemarkHandler()->addNote( $this->getManager()->getRemarkHandler()->addNote(
sprintf( sprintf(
$oLang->translateString('D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE', null, true), $oLang->translateString('D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE', null, true),
$this->getRecipientDescription() $this->getRecipientDescription()
) )
); );
$this->startExecution(); $this->startExecution();
stopProfile(__METHOD__); stopProfile(__METHOD__);
} }
/** /**
* @return bool * @return string
*/ */
public function getRecipientDescription(): string public function getRecipientDescription(): string
{ {
$aEditedValues = $this->getManager()->getEditedValues();
$aMailDesc = []; $aMailDesc = [];
$aEditedValues ? ($this->getManager()->getValue('blLinkMobilityMessageToCustomer') ? $aMailDesc[] = 'Customer' : '');
($aEditedValues['blLinkMobilityMessageToCustomer'] ? $aMailDesc[] = 'Customer' : '') : ($this->getManager()->getValue('blLinkMobilityMessageToCustom') ?
($this->getManager()->getValue('blLinkMobilityMessageToCustomer') ? $aMailDesc[] = 'Customer' : ''); $aMailDesc[] = 'Custom: ' . $this->getManager()->getValue('sLinkMobilityMessageToCustomAddress') :
$aEditedValues ? ''
($aEditedValues['blLinkMobilityMessageToCustom'] ? $aMailDesc[] = 'Custom: ' . $aEditedValues['sLinkMobilityMessageToCustomAddress'] : '') : );
($this->getManager()->getValue('blLinkMobilityMessageToCustom') ?
$aMailDesc[] = 'Custom: ' . $this->getManager()->getValue('sLinkMobilityMessageToCustomAddress') :
''
);
return implode(', ', $aMailDesc); return implode(', ', $aMailDesc);
} }
@ -147,21 +152,6 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
return $blExpected ? $return : false === $return; return $blExpected ? $return : false === $return;
} }
/**
* @param bool $blExpected
*
* @return bool
*/
protected function hasRequiredValuesNoSource(bool $blExpected): bool
{
$source = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromSource' );
$return = strlen(trim($source)) &&
in_array(trim($source), [self::SOURCE_CMS, self::SOURCE_TEMPLATE]);
return $blExpected ? $return : false === $return;
}
/** /**
* @param bool $blExpected * @param bool $blExpected
* *
@ -252,17 +242,22 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
{ {
try { try {
if ($this->canExecuteMethod() && $this->hasRequiredValues()) { if ($this->canExecuteMethod() && $this->hasRequiredValues()) {
dumpvar(__METHOD__ . __LINE__ . PHP_EOL);
$this->getSendClass()->sendOrderManagerSms($this->getManager(), $this->getItem()); $this->getSendClass()->sendOrderManagerSms($this->getManager(), $this->getItem());
} }
} catch (emptyMesageException $e) { } catch (emptyMesageException $e) {
Registry::getLogger()->error($e->getMessage()); Registry::getLogger()->error($e->getMessage());
$this->getManager()->getRemarkHandler()->addNote(
Registry::getLang()->translateString('D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_EMPTYMESSAGE', null, true)
);
} catch (noRecipientFoundException $e) { } catch (noRecipientFoundException $e) {
Registry::getLogger()->info( Registry::getLogger()->info(
$this->getManager()->getFieldData('oxtitle')." => ". $this->getManager()->getFieldData('oxtitle')." => ".
$this->getItem()->getFieldData('oxordernr').": ". $this->getItem()->getFieldData('oxordernr').": ".
$e->getMessage() $e->getMessage()
); );
$this->getManager()->getRemarkHandler()->addNote(
Registry::getLang()->translateString('D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_NORECIPIENT', null, true)
);
} }
} }
@ -271,10 +266,7 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract
*/ */
public function getSendClass(): d3linkmobility_ordermanager_sender public function getSendClass(): d3linkmobility_ordermanager_sender
{ {
/** @var d3linkmobility_ordermanager_sender $mailer */ return oxNew(d3linkmobility_ordermanager_sender::class);
$sender = oxNew(d3linkmobility_ordermanager_sender::class);
return $sender;
} }
/** /**

View File

@ -34,6 +34,7 @@ use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Core\Email; use OxidEsales\Eshop\Core\Email;
use OxidEsales\Eshop\Core\Exception\ArticleException; use OxidEsales\Eshop\Core\Exception\ArticleException;
use OxidEsales\Eshop\Core\Exception\ArticleInputException; use OxidEsales\Eshop\Core\Exception\ArticleInputException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Controller\BaseController; use OxidEsales\EshopCommunity\Core\Controller\BaseController;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
@ -63,10 +64,7 @@ class d3linkmobility_ordermanager_sender
{ {
$this->setManager($manager); $this->setManager($manager);
$this->setItem($item); $this->setItem($item);
dumpvar(__METHOD__.__LINE__.PHP_EOL);
dumpvar($this->getMessageBody());
dumpvar($this->getRecipients());
die();
$sms = oxNew(Sms::class, $this->getMessageBody()); $sms = oxNew(Sms::class, $this->getMessageBody());
$sms->sendCustomRecipientMessage($this->getRecipients()); $sms->sendCustomRecipientMessage($this->getRecipients());
} }
@ -144,7 +142,7 @@ die();
* @throws d3ParameterNotFoundException * @throws d3ParameterNotFoundException
* @throws emptyMesageException * @throws emptyMesageException
*/ */
protected function _d3GenerateOrderManagerMessageContent(TemplateEngineInterface $templateEngine) protected function _d3GenerateOrderManagerMessageContent(TemplateEngineInterface $templateEngine): string
{ {
$iOrderLangId = $this->getManager()->getCurrentItem()->getFieldData('oxlang'); $iOrderLangId = $this->getManager()->getCurrentItem()->getFieldData('oxlang');
$oLang = Registry::getLang(); $oLang = Registry::getLang();
@ -212,7 +210,8 @@ die();
/** /**
* @return array * @return array
* @throws noRecipientFoundException * @throws StandardException
* @throws d3ParameterNotFoundException
*/ */
protected function getRecipients(): array protected function getRecipients(): array
{ {
@ -220,7 +219,11 @@ die();
if ((bool) $this->getManager()->getValue('blLinkMobilityMessageToCustomer')) { if ((bool) $this->getManager()->getValue('blLinkMobilityMessageToCustomer')) {
try { try {
$recipients[] = (oxNew(OrderRecipients::class, $this->getItem()))->getSmsRecipient(); $recipients[] = (oxNew(OrderRecipients::class, $this->getItem()))->getSmsRecipient();
} catch (noRecipientFoundException $e) {} } catch (noRecipientFoundException $e) {
$this->getManager()->getRemarkHandler()->addNote(
Registry::getLang()->translateString('D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_NORECIPIENT', null, true)
);
}
} }
if ((bool) $this->getManager()->getValue('blLinkMobilityMessageToCustom') && if ((bool) $this->getManager()->getValue('blLinkMobilityMessageToCustom') &&
strlen(trim($this->getManager()->getValue('sLinkMobilityMessageToCustomAddress'))) strlen(trim($this->getManager()->getValue('sLinkMobilityMessageToCustomAddress')))
@ -230,6 +233,17 @@ die();
$recipients[] = oxNew(Recipient::class, $phoneNumber, $countryId); $recipients[] = oxNew(Recipient::class, $phoneNumber, $countryId);
} catch (RecipientException $e) { } catch (RecipientException $e) {
Registry::getLogger()->info($e->getMessage(), [$phoneNumber, $countryId]); Registry::getLogger()->info($e->getMessage(), [$phoneNumber, $countryId]);
$this->getManager()->getRemarkHandler()->addNote(
sprintf(
Registry::getLang()->translateString(
'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_RECIPIENTERROR',
null,
true
),
$phoneNumber,
$countryId
)
);
} }
} }
} }

View File

@ -47,8 +47,12 @@ $aLang = array(
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDSOURCE' => 'keine gültige Inhaltsquelle gesetzt', 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDSOURCE' => 'keine gültige Inhaltsquelle gesetzt',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDTPL' => 'keine gültigen Templatedaten gesetzt', 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDTPL' => 'keine gültigen Templatedaten gesetzt',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDCMS' => 'kein gültiger CMS-Eintrag gesetzt', 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDCMS' => 'kein gültiger CMS-Eintrag gesetzt',
'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_UNDEFINED' => 'unbekannter Fehler',
'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE' => 'sende LinkMobility Nachricht an %s', 'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE' => 'sende SMS via LinkMobility an %s',
'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_EMPTYMESSAGE' => 'SMS wurde wegen leerer Nachricht nicht gesendet',
'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_NORECIPIENT' => 'SMS wurde wegen fehlender Empfänger nicht gesendet',
'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_RECIPIENTERROR' => 'SMS Empfänger %1$s (%2$s) konnte nicht verwendet werden',
); );
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd