From 1a896e26c23780bad5da9ffaba8b67ea486c4240 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Mon, 18 Jul 2022 00:27:49 +0200 Subject: [PATCH 01/20] move configurations to conf class --- src/Application/Model/Configuration.php | 110 +++++++++++++++++++++- src/Application/Model/MessageSender.php | 20 ++-- src/Application/Model/OrderRecipients.php | 26 +---- src/Application/Model/UserRecipients.php | 27 +----- 4 files changed, 119 insertions(+), 64 deletions(-) diff --git a/src/Application/Model/Configuration.php b/src/Application/Model/Configuration.php index 9da0a7c..68c5143 100644 --- a/src/Application/Model/Configuration.php +++ b/src/Application/Model/Configuration.php @@ -16,16 +16,34 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\Application\Model; use Assert\Assert; +use OxidEsales\Eshop\Application\Model\Order; +use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Core\Registry; class Configuration { + const GENERAL_APITOKEN = "d3linkmobility_apitoken"; + const GENERAL_DEBUG = "d3linkmobility_debug"; + + const ORDER_RECFIELDS = "d3linkmobility_smsOrderRecipientsFields"; + const USER_RECFIELDS = "d3linkmobility_smsUserRecipientsFields"; + + const SMS_SENDERNR = "d3linkmobility_smsSenderNumber"; + const SMS_SENDERCOUNTRY = "d3linkmobility_smsSenderCountry"; + + const SENDBY_ORDERED = "d3linkmobility_orderActive"; + const SENDBY_SENDEDNOW = "d3linkmobility_sendedNowActive"; + const SENDBY_CANCELED = "d3linkmobility_cancelOrderActive"; + + const ARGS_CHECKKEYS = "checkKeys"; + const ARGS_CHECKCLASS = "checkClassName"; + /** * @return string */ public function getApiToken(): string { - $token = trim(Registry::getConfig()->getConfigParam('d3linkmobility_apitoken')); + $token = trim(Registry::getConfig()->getConfigParam(self::GENERAL_APITOKEN)); Assert::that($token)->string()->notEmpty(); @@ -37,7 +55,7 @@ class Configuration */ public function getTestMode(): bool { - return (bool) Registry::getConfig()->getConfigParam('d3linkmobility_debug'); + return (bool) Registry::getConfig()->getConfigParam(self::GENERAL_DEBUG); } /** @@ -45,7 +63,7 @@ class Configuration */ public function getSmsSenderNumber() { - $number = trim(Registry::getConfig()->getConfigParam('d3linkmobility_smsSenderNumber')); + $number = trim(Registry::getConfig()->getConfigParam(self::SMS_SENDERNR)); return strlen($number) ? $number : null; } @@ -55,11 +73,95 @@ class Configuration */ public function getSmsSenderCountry(): string { - $country = trim(Registry::getConfig()->getConfigParam('d3linkmobility_smsSenderCountry')); + $country = trim(Registry::getConfig()->getConfigParam(self::SMS_SENDERCOUNTRY)); $country = strlen($country) ? strtoupper($country) : null; Assert::that($country)->nullOr()->string()->length(2); return $country; } + + /** + * @return array + */ + public function getOrderRecipientFields(): array + { + $customFields = Registry::getConfig()->getConfigParam(self::ORDER_RECFIELDS); + + array_walk( + $customFields, + [$this, 'checkFieldExists'], + [self::ARGS_CHECKKEYS => true, self::ARGS_CHECKCLASS => Order::class] + ); + $customFields = array_filter($customFields); + + Assert::that($customFields)->isArray(); + + return $customFields; + } + + /** + * @return array + */ + public function getUserRecipientFields(): array + { + $customFields = Registry::getConfig()->getConfigParam(self::USER_RECFIELDS); + + array_walk( + $customFields, + [$this, 'checkFieldExists'], + [self::ARGS_CHECKKEYS => false, self::ARGS_CHECKCLASS => User::class] + ); + $customFields = array_filter($customFields); + + Assert::that($customFields)->isArray(); + + return $customFields; + } + + /** + * @param $checkPhoneFieldName + * @param $checkCountryFieldName + * @param $args + * @return void + */ + protected function checkFieldExists(&$checkPhoneFieldName, $checkCountryFieldName, $args) + { + $checkCountryFieldName = $args[self::ARGS_CHECKKEYS] ? trim($checkCountryFieldName) : $checkCountryFieldName; + $checkPhoneFieldName = trim($checkPhoneFieldName); + $allFieldNames = oxNew($args[self::ARGS_CHECKCLASS])->getFieldNames(); + + array_walk($allFieldNames, function (&$value) { + $value = strtolower($value); + }); + + $checkPhoneFieldName = in_array(strtolower($checkPhoneFieldName), $allFieldNames) && ( + false === $args[self::ARGS_CHECKKEYS] || + in_array(strtolower($checkCountryFieldName), $allFieldNames) + ) ? $checkPhoneFieldName : null; + } + + /** + * @return bool + */ + public function sendOrderFinishedMessage(): bool + { + return (bool) Registry::getConfig()->getConfigParam(self::SENDBY_ORDERED); + } + + /** + * @return bool + */ + public function sendOrderSendedNowMessage(): bool + { + return (bool) Registry::getConfig()->getConfigParam(self::SENDBY_SENDEDNOW); + } + + /** + * @return bool + */ + public function sendOrderCanceledMessage(): bool + { + return (bool) Registry::getConfig()->getConfigParam(self::SENDBY_CANCELED); + } } diff --git a/src/Application/Model/MessageSender.php b/src/Application/Model/MessageSender.php index 8aa7c18..43bd2ee 100644 --- a/src/Application/Model/MessageSender.php +++ b/src/Application/Model/MessageSender.php @@ -19,7 +19,6 @@ use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use Exception; use OxidEsales\Eshop\Application\Model\Order; -use OxidEsales\Eshop\Core\Registry; class MessageSender { @@ -30,7 +29,9 @@ class MessageSender */ public function sendOrderFinishedMessage(Order $order, $messageBody) { - $this->sendMessageByOrder('d3linkmobility_orderActive', $order, $messageBody); + if ((oxNew(Configuration::class))->sendOrderFinishedMessage()) { + $this->sendMessageByOrder( $order, $messageBody); + } } /** @@ -40,7 +41,9 @@ class MessageSender */ public function sendSendedNowMessage(Order $order, $messageBody) { - $this->sendMessageByOrder('d3linkmobility_sendedNowActive', $order, $messageBody); + if ((oxNew(Configuration::class))->sendOrderSendedNowMessage()) { + $this->sendMessageByOrder($order, $messageBody); + } } /** @@ -50,20 +53,19 @@ class MessageSender */ public function sendCancelOrderMessage(Order $order, $messageBody) { - $this->sendMessageByOrder('d3linkmobility_cancelOrderActive', $order, $messageBody); + if ((oxNew(Configuration::class))->sendOrderCanceledMessage()) { + $this->sendMessageByOrder($order, $messageBody); + } } /** - * @param $configParam * @param Order $order * @param $messageBody * @throws Exception */ - public function sendMessageByOrder($configParam, Order $order, $messageBody) + public function sendMessageByOrder(Order $order, $messageBody) { - if (false === (bool) Registry::getConfig()->getConfigParam($configParam) - || (bool) strlen(trim($messageBody)) === false - ) { + if ((bool) strlen(trim($messageBody)) === false) { return; } diff --git a/src/Application/Model/OrderRecipients.php b/src/Application/Model/OrderRecipients.php index 41e833f..4dc951e 100644 --- a/src/Application/Model/OrderRecipients.php +++ b/src/Application/Model/OrderRecipients.php @@ -58,7 +58,7 @@ class OrderRecipients */ public function getSmsRecipientFields(): array { - $customFields = $this->getSanitizedCustomFields(); + $customFields = (oxNew(Configuration::class))->getOrderRecipientFields(); return count($customFields) ? $customFields : @@ -67,28 +67,4 @@ class OrderRecipients 'oxbillfon' => 'oxbillcountryid' ]; } - - /** - * @return array - */ - public function getSanitizedCustomFields(): array - { - $customFields = (array) Registry::getConfig()->getConfigParam('d3linkmobility_smsOrderRecipientsFields'); - array_walk($customFields, [$this, 'checkFieldExists']); - return array_filter($customFields); - } - - public function checkFieldExists(&$checkPhoneFieldName, $checkCountryFieldName) - { - $checkCountryFieldName = trim($checkCountryFieldName); - $checkPhoneFieldName = trim($checkPhoneFieldName); - $allFieldNames = oxNew(Order::class)->getFieldNames(); - - array_walk($allFieldNames, function (&$value) { - $value = strtolower($value); - }); - - $checkPhoneFieldName = in_array(strtolower($checkPhoneFieldName), $allFieldNames) && - in_array(strtolower($checkCountryFieldName), $allFieldNames) ? $checkPhoneFieldName : null; - } } diff --git a/src/Application/Model/UserRecipients.php b/src/Application/Model/UserRecipients.php index 3d72c0f..5901868 100644 --- a/src/Application/Model/UserRecipients.php +++ b/src/Application/Model/UserRecipients.php @@ -57,7 +57,7 @@ class UserRecipients */ public function getSmsRecipientFields(): array { - $customFields = $this->getSanitizedCustomFields(); + $customFields = (oxNew(Configuration::class))->getUserRecipientFields(); return count($customFields) ? $customFields : @@ -67,29 +67,4 @@ class UserRecipients 'oxprivfon' ]; } - - /** - * @return array - */ - public function getSanitizedCustomFields(): array - { - $customFields = (array) Registry::getConfig()->getConfigParam('d3linkmobility_smsUserRecipientsFields'); - array_walk($customFields, [$this, 'checkFieldExists']); - return array_filter($customFields); - } - - /** - * @param $checkFieldName - */ - public function checkFieldExists(&$checkFieldName) - { - $checkFieldName = trim($checkFieldName); - $allFieldNames = oxNew(User::class)->getFieldNames(); - - array_walk($allFieldNames, function (&$value) { - $value = strtolower($value); - }); - - $checkFieldName = in_array(strtolower($checkFieldName), $allFieldNames) ? $checkFieldName : null; - } } From e159aaa3b0440d6f2bd256ebc8fdd2dd05cec724 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Mon, 18 Jul 2022 13:25:26 +0200 Subject: [PATCH 02/20] catch thrown recipient exceptions in admin controllers --- src/Application/Model/OrderRecipients.php | 19 +++++++++++----- src/Application/Model/UserRecipients.php | 18 ++++++++++----- src/Modules/Core/EmailCore.php | 27 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/Application/Model/OrderRecipients.php b/src/Application/Model/OrderRecipients.php index 4dc951e..04603b9 100644 --- a/src/Application/Model/OrderRecipients.php +++ b/src/Application/Model/OrderRecipients.php @@ -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' )]); } } diff --git a/src/Application/Model/UserRecipients.php b/src/Application/Model/UserRecipients.php index 5901868..6152f6a 100644 --- a/src/Application/Model/UserRecipients.php +++ b/src/Application/Model/UserRecipients.php @@ -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' )]); } } diff --git a/src/Modules/Core/EmailCore.php b/src/Modules/Core/EmailCore.php index 62c4af3..ef87e4f 100644 --- a/src/Modules/Core/EmailCore.php +++ b/src/Modules/Core/EmailCore.php @@ -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 { From 224057b8077883469426abec34c7c0636fe7090e Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 20 Jul 2022 11:57:58 +0200 Subject: [PATCH 03/20] enable Link Mobility php client v2 as dependency variant --- composer.json | 2 +- src/Application/Model/OrderRecipients.php | 4 +++- src/Application/Model/UserRecipients.php | 4 +++- src/Modules/Application/Model/OrderModel.php | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 69b9cc6..7ca2bda 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require": { "php": "^7.0 || ^8.0", "oxid-esales/oxideshop-ce": "6.7 - 6.10", - "d3/linkmobility-php-client": "^1.2.0" + "d3/linkmobility-php-client": "^1.2.0 || ^2.0.0" }, "extra": { "oxideshop": { diff --git a/src/Application/Model/OrderRecipients.php b/src/Application/Model/OrderRecipients.php index 04603b9..788732e 100644 --- a/src/Application/Model/OrderRecipients.php +++ b/src/Application/Model/OrderRecipients.php @@ -57,7 +57,9 @@ class OrderRecipients } } - throw oxNew(noRecipientFoundException::class); + /** @var noRecipientFoundException $exc */ + $exc = oxNew(noRecipientFoundException::class); + throw $exc; } /** diff --git a/src/Application/Model/UserRecipients.php b/src/Application/Model/UserRecipients.php index 6152f6a..c5fbaf6 100644 --- a/src/Application/Model/UserRecipients.php +++ b/src/Application/Model/UserRecipients.php @@ -57,7 +57,9 @@ class UserRecipients } } - throw oxNew(noRecipientFoundException::class); + /** @var noRecipientFoundException $exc */ + $exc = oxNew(noRecipientFoundException::class); + throw $exc; } /** diff --git a/src/Modules/Application/Model/OrderModel.php b/src/Modules/Application/Model/OrderModel.php index f8b2199..b8ff5d5 100644 --- a/src/Modules/Application/Model/OrderModel.php +++ b/src/Modules/Application/Model/OrderModel.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\Modules\Application\Model; +use D3\Linkmobility4OXID\Modules\Core\EmailCore; use OxidEsales\Eshop\Core\Email; class OrderModel extends OrderModel_parent @@ -24,6 +25,7 @@ class OrderModel extends OrderModel_parent parent::cancelOrder(); if ($this->getFieldData('oxstorno') === 1) { + /** @var EmailCore $Email */ $Email = oxNew(Email::class); $Email->d3SendCancelMessage($this); } From 00e54ec4dc5a1ca57b5601b653605e7ccfe6f805 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 27 Jul 2022 08:42:06 +0200 Subject: [PATCH 04/20] add phpstan dependency, cut PHP 7.0 compatibility --- composer.json | 7 ++++++- phpstan.neon | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 7ca2bda..89e858a 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,15 @@ } ], "require": { - "php": "^7.0 || ^8.0", + "php": "^7.1 || ^8.0", "oxid-esales/oxideshop-ce": "6.7 - 6.10", "d3/linkmobility-php-client": "^1.2.0 || ^2.0.0" }, + "require-dev": { + "oxid-esales/oxideshop-ce": "~6.10.0", + "friendsofphp/php-cs-fixer": "^2.19", + "phpstan/phpstan": "^1.8" + }, "extra": { "oxideshop": { "source-directory": "/src", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..045b26d --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + scanFiles: + - src/IntelliSenseHelper.php + paths: + - src + level: 0 + phpVersion: 70100 From 72fcd89823c2343f74c9fba104421506243f4140 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 27 Jul 2022 08:47:20 +0200 Subject: [PATCH 05/20] apply code style rules --- .gitignore | 1 + .php-cs-fixer.php | 2 +- src/Application/Model/Configuration.php | 22 +++++++++---------- src/Application/Model/MessageSender.php | 2 +- .../Model/MessageTypes/AbstractMessage.php | 4 ++-- src/Application/Model/OrderRecipients.php | 12 +++++----- src/Application/Model/UserRecipients.php | 12 +++++----- 7 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..775f18f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.php_cs.cache \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 244806f..e5e32a0 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -6,7 +6,7 @@ $finder = PhpCsFixer\Finder::create() $config = new PhpCsFixer\Config(); return $config->setRules([ - '@PHP70Migration' => true, + '@PHP71Migration' => true, '@PSR12' => true ]) ->setFinder($finder) diff --git a/src/Application/Model/Configuration.php b/src/Application/Model/Configuration.php index 68c5143..e15a52f 100644 --- a/src/Application/Model/Configuration.php +++ b/src/Application/Model/Configuration.php @@ -22,21 +22,21 @@ use OxidEsales\Eshop\Core\Registry; class Configuration { - const GENERAL_APITOKEN = "d3linkmobility_apitoken"; - const GENERAL_DEBUG = "d3linkmobility_debug"; + public const GENERAL_APITOKEN = "d3linkmobility_apitoken"; + public const GENERAL_DEBUG = "d3linkmobility_debug"; - const ORDER_RECFIELDS = "d3linkmobility_smsOrderRecipientsFields"; - const USER_RECFIELDS = "d3linkmobility_smsUserRecipientsFields"; + public const ORDER_RECFIELDS = "d3linkmobility_smsOrderRecipientsFields"; + public const USER_RECFIELDS = "d3linkmobility_smsUserRecipientsFields"; - const SMS_SENDERNR = "d3linkmobility_smsSenderNumber"; - const SMS_SENDERCOUNTRY = "d3linkmobility_smsSenderCountry"; + public const SMS_SENDERNR = "d3linkmobility_smsSenderNumber"; + public const SMS_SENDERCOUNTRY = "d3linkmobility_smsSenderCountry"; - const SENDBY_ORDERED = "d3linkmobility_orderActive"; - const SENDBY_SENDEDNOW = "d3linkmobility_sendedNowActive"; - const SENDBY_CANCELED = "d3linkmobility_cancelOrderActive"; + public const SENDBY_ORDERED = "d3linkmobility_orderActive"; + public const SENDBY_SENDEDNOW = "d3linkmobility_sendedNowActive"; + public const SENDBY_CANCELED = "d3linkmobility_cancelOrderActive"; - const ARGS_CHECKKEYS = "checkKeys"; - const ARGS_CHECKCLASS = "checkClassName"; + public const ARGS_CHECKKEYS = "checkKeys"; + public const ARGS_CHECKCLASS = "checkClassName"; /** * @return string diff --git a/src/Application/Model/MessageSender.php b/src/Application/Model/MessageSender.php index 43bd2ee..7060e7d 100644 --- a/src/Application/Model/MessageSender.php +++ b/src/Application/Model/MessageSender.php @@ -30,7 +30,7 @@ class MessageSender public function sendOrderFinishedMessage(Order $order, $messageBody) { if ((oxNew(Configuration::class))->sendOrderFinishedMessage()) { - $this->sendMessageByOrder( $order, $messageBody); + $this->sendMessageByOrder($order, $messageBody); } } diff --git a/src/Application/Model/MessageTypes/AbstractMessage.php b/src/Application/Model/MessageTypes/AbstractMessage.php index 1bc8c70..b51eca0 100644 --- a/src/Application/Model/MessageTypes/AbstractMessage.php +++ b/src/Application/Model/MessageTypes/AbstractMessage.php @@ -22,7 +22,7 @@ use OxidEsales\Eshop\Application\Model\Remark; abstract class AbstractMessage { - const REMARK_IDENT = 'LINKMOB'; + public const REMARK_IDENT = 'LINKMOB'; protected $message; protected $removeLineBreaks = true; @@ -109,5 +109,5 @@ abstract class AbstractMessage return $this->removeMultipleSpaces ? preg_replace($regexp, ' ', $message) : $message; } - abstract public function getTypeName() : string; + abstract public function getTypeName(): string; } diff --git a/src/Application/Model/OrderRecipients.php b/src/Application/Model/OrderRecipients.php index 788732e..34084c2 100644 --- a/src/Application/Model/OrderRecipients.php +++ b/src/Application/Model/OrderRecipients.php @@ -43,17 +43,17 @@ class OrderRecipients { foreach ($this->getSmsRecipientFields() as $phoneFieldName => $countryIdFieldName) { $content = trim((string) $this->order->getFieldData($phoneFieldName)); - $country = oxNew( Country::class ); + $country = oxNew(Country::class); try { - if ( strlen( $content ) ) { - $country->load( $this->order->getFieldData( $countryIdFieldName ) ); - return oxNew( Recipient::class, $content, $country->getFieldData( 'oxisoalpha2' ) ); + 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' )]); + LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData('oxisoalpha2')]); } catch (RecipientException $e) { - LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData( 'oxisoalpha2' )]); + LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData('oxisoalpha2')]); } } diff --git a/src/Application/Model/UserRecipients.php b/src/Application/Model/UserRecipients.php index c5fbaf6..f6828df 100644 --- a/src/Application/Model/UserRecipients.php +++ b/src/Application/Model/UserRecipients.php @@ -43,17 +43,17 @@ class UserRecipients { foreach ($this->getSmsRecipientFields() as $fieldName) { $content = trim($this->user->getFieldData($fieldName)); - $country = oxNew( Country::class ); + $country = oxNew(Country::class); try { - if ( strlen( $content ) ) { - $country->load( $this->user->getFieldData( 'oxcountryid' ) ); - return oxNew( Recipient::class, $content, $country->getFieldData( 'oxisoalpha2' ) ); + 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' )]); + LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData('oxisoalpha2')]); } catch (RecipientException $e) { - LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData( 'oxisoalpha2' )]); + LoggerHandler::getInstance()->getLogger()->info($e->getMessage(), [$content, $country->getFieldData('oxisoalpha2')]); } } From c36ebf7381207f6aae83532deb2c5d44e924907d Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 27 Jul 2022 08:58:33 +0200 Subject: [PATCH 06/20] fix IntelliSenseHelper --- src/IntelliSenseHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IntelliSenseHelper.php b/src/IntelliSenseHelper.php index b097939..50cf93b 100644 --- a/src/IntelliSenseHelper.php +++ b/src/IntelliSenseHelper.php @@ -13,7 +13,7 @@ declare(strict_types=1); -namespace D3\Linkmobility4OXID\Modules\Aplication\Model { +namespace D3\Linkmobility4OXID\Modules\Application\Model { use OxidEsales\Eshop\Application\Model\Order; From 63ec4670b7669c0a33fe655b4152b5215bae4267 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 27 Jul 2022 09:05:53 +0200 Subject: [PATCH 07/20] make oxNew discoverable for phpstan --- phpstan.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.neon b/phpstan.neon index 045b26d..ebb0513 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,7 @@ parameters: scanFiles: - src/IntelliSenseHelper.php + - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php paths: - src level: 0 From cd2ea141218d2a71e3f2bc719f1833f7a223e2d4 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 27 Jul 2022 09:27:59 +0200 Subject: [PATCH 08/20] fix small issues, improve code --- phpstan.neon | 8 +++-- .../Controller/Admin/AdminOrder.php | 27 +++++++------- .../Controller/Admin/AdminUser.php | 35 +++++++++---------- src/Application/Model/Configuration.php | 29 +++++++++------ .../abortSendingExceptionInterface.php | 2 +- .../Exceptions/successfullySentException.php | 12 ++++--- src/Application/Model/MessageSender.php | 20 ++++++----- .../Model/MessageTypes/AbstractMessage.php | 22 +++++++----- src/Application/Model/MessageTypes/Sms.php | 12 ++++--- src/Application/Model/OrderRecipients.php | 8 +++-- src/Application/Model/RequestFactory.php | 1 + src/Application/Model/UserRecipients.php | 8 +++-- src/Modules/Application/Model/OrderModel.php | 11 ++++-- src/Modules/Core/EmailCore.php | 19 ++++++---- 14 files changed, 129 insertions(+), 85 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index ebb0513..6c8b9a1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,8 +1,10 @@ parameters: scanFiles: - - src/IntelliSenseHelper.php - - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php + - src/IntelliSenseHelper.php + - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php paths: - src - level: 0 + level: 9 phpVersion: 70100 + ignoreErrors: + - '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#' \ No newline at end of file diff --git a/src/Application/Controller/Admin/AdminOrder.php b/src/Application/Controller/Admin/AdminOrder.php index 7f276c1..d9d70c3 100644 --- a/src/Application/Controller/Admin/AdminOrder.php +++ b/src/Application/Controller/Admin/AdminOrder.php @@ -58,24 +58,25 @@ class AdminOrder extends AdminController try { return oxNew(OrderRecipients::class, $this->order)->getSmsRecipient(); } catch (noRecipientFoundException $e) { - Registry::getUtilsView()->addErrorToDisplay( - Registry::getLang()->translateString($e->getMessage()) - ); + /** @var string $message */ + $message = Registry::getLang()->translateString($e->getMessage()); + Registry::getUtilsView()->addErrorToDisplay($message); } return false; } /** + * @return void * @throws Exception */ - public function send() + public function send(): void { $messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody'); if (false === is_string($messageBody) || strlen($messageBody) <= 1) { - Registry::getUtilsView()->addErrorToDisplay( - Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH') - ); + /** @var string $message */ + $message = Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH'); + Registry::getUtilsView()->addErrorToDisplay($message); return; } @@ -85,17 +86,15 @@ class AdminOrder extends AdminController try { $sms = oxNew(Sms::class, $messageBody); if ($sms->sendOrderMessage($order)) { + $smsCount = $sms->getResponse() ? $sms->getResponse()->getSmsCount() : 0; Registry::getUtilsView()->addErrorToDisplay( - oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount()) + oxNew(successfullySentException::class, $smsCount) ); } else { $errorMsg = $sms->getResponse() instanceof ResponseInterface ? $sms->getResponse()->getErrorMessage() : 'no response'; - Registry::getUtilsView()->addErrorToDisplay( - sprintf( - Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), - $errorMsg - ) - ); + /** @var string $format */ + $format = Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'); + Registry::getUtilsView()->addErrorToDisplay(sprintf($format, $errorMsg)); } } catch (noRecipientFoundException $e) { Registry::getUtilsView()->addErrorToDisplay($e); diff --git a/src/Application/Controller/Admin/AdminUser.php b/src/Application/Controller/Admin/AdminUser.php index e4a27b6..3aba0fb 100644 --- a/src/Application/Controller/Admin/AdminUser.php +++ b/src/Application/Controller/Admin/AdminUser.php @@ -57,24 +57,26 @@ class AdminUser extends AdminController try { return oxNew(UserRecipients::class, $this->user)->getSmsRecipient(); } catch (noRecipientFoundException $e) { - Registry::getUtilsView()->addErrorToDisplay( - Registry::getLang()->translateString($e->getMessage()) - ); + /** @var string $message */ + $message = Registry::getLang()->translateString($e->getMessage()); + Registry::getUtilsView()->addErrorToDisplay($message); } return false; } /** + * @return void * @throws Exception */ - public function send() + public function send(): void { + /** @var string $messageBody */ $messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody'); if (strlen($messageBody) <= 1) { - Registry::getUtilsView()->addErrorToDisplay( - Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH') - ); + /** @var string $message */ + $message = Registry::getLang()->translateString('D3LM_EXC_MESSAGE_NO_LENGTH'); + Registry::getUtilsView()->addErrorToDisplay($message); return; } @@ -83,20 +85,15 @@ class AdminUser extends AdminController $sms = oxNew(Sms::class, $messageBody); if ($sms->sendUserAccountMessage($user)) { - Registry::getUtilsView()->addErrorToDisplay( - sprintf( - Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'), - $sms->getResponse()->getSmsCount() - ) - ); + /** @var string $format */ + $format = Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'); + $smsCount = $sms->getResponse() ? $sms->getResponse()->getSmsCount() : 0; + Registry::getUtilsView()->addErrorToDisplay(sprintf($format, $smsCount)); } else { $errorMsg = $sms->getResponse() instanceof ResponseInterface ? $sms->getResponse()->getErrorMessage() : 'no response'; - Registry::getUtilsView()->addErrorToDisplay( - sprintf( - Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), - $errorMsg - ) - ); + /** @var string $format */ + $format = Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'); + Registry::getUtilsView()->addErrorToDisplay(sprintf($format, $errorMsg)); } } } diff --git a/src/Application/Model/Configuration.php b/src/Application/Model/Configuration.php index e15a52f..534d16d 100644 --- a/src/Application/Model/Configuration.php +++ b/src/Application/Model/Configuration.php @@ -43,7 +43,9 @@ class Configuration */ public function getApiToken(): string { - $token = trim(Registry::getConfig()->getConfigParam(self::GENERAL_APITOKEN)); + /** @var string $token */ + $token = Registry::getConfig()->getConfigParam(self::GENERAL_APITOKEN); + $token = trim($token); Assert::that($token)->string()->notEmpty(); @@ -63,7 +65,9 @@ class Configuration */ public function getSmsSenderNumber() { - $number = trim(Registry::getConfig()->getConfigParam(self::SMS_SENDERNR)); + /** @var string $number */ + $number = Registry::getConfig()->getConfigParam(self::SMS_SENDERNR); + $number = trim($number); return strlen($number) ? $number : null; } @@ -71,9 +75,11 @@ class Configuration /** * @return string|null */ - public function getSmsSenderCountry(): string + public function getSmsSenderCountry(): ?string { - $country = trim(Registry::getConfig()->getConfigParam(self::SMS_SENDERCOUNTRY)); + /** @var string $country */ + $country = Registry::getConfig()->getConfigParam(self::SMS_SENDERCOUNTRY); + $country = trim($country); $country = strlen($country) ? strtoupper($country) : null; Assert::that($country)->nullOr()->string()->length(2); @@ -82,10 +88,11 @@ class Configuration } /** - * @return array + * @return string[] */ public function getOrderRecipientFields(): array { + /** @var string[] $customFields */ $customFields = Registry::getConfig()->getConfigParam(self::ORDER_RECFIELDS); array_walk( @@ -101,10 +108,11 @@ class Configuration } /** - * @return array + * @return string[] */ public function getUserRecipientFields(): array { + /** @var string[] $customFields */ $customFields = Registry::getConfig()->getConfigParam(self::USER_RECFIELDS); array_walk( @@ -120,12 +128,13 @@ class Configuration } /** - * @param $checkPhoneFieldName - * @param $checkCountryFieldName - * @param $args + * @template T + * @param string $checkPhoneFieldName + * @param string $checkCountryFieldName + * @param array{checkKeys: bool, checkClassName: class-string} $args * @return void */ - protected function checkFieldExists(&$checkPhoneFieldName, $checkCountryFieldName, $args) + protected function checkFieldExists(string &$checkPhoneFieldName, string $checkCountryFieldName, array $args): void { $checkCountryFieldName = $args[self::ARGS_CHECKKEYS] ? trim($checkCountryFieldName) : $checkCountryFieldName; $checkPhoneFieldName = trim($checkPhoneFieldName); diff --git a/src/Application/Model/Exceptions/abortSendingExceptionInterface.php b/src/Application/Model/Exceptions/abortSendingExceptionInterface.php index 1c3e20d..6c4f2a4 100644 --- a/src/Application/Model/Exceptions/abortSendingExceptionInterface.php +++ b/src/Application/Model/Exceptions/abortSendingExceptionInterface.php @@ -15,6 +15,6 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\Application\Model\Exceptions; -interface abortSendingExceptionInterface +interface abortSendingExceptionInterface extends \Throwable { } diff --git a/src/Application/Model/Exceptions/successfullySentException.php b/src/Application/Model/Exceptions/successfullySentException.php index a219dd8..9a37909 100644 --- a/src/Application/Model/Exceptions/successfullySentException.php +++ b/src/Application/Model/Exceptions/successfullySentException.php @@ -16,19 +16,21 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\Application\Model\Exceptions; use Exception; +use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Registry; -use Throwable; -class successfullySentException extends Exception +class successfullySentException extends StandardException { /** * @param int $messageCount * @param int $code - * @param Throwable|null $previous + * @param Exception|null $previous */ - public function __construct($messageCount = 1, $code = 0, Throwable $previous = null) + public function __construct($messageCount = 1, $code = 0, Exception $previous = null) { - $message = sprintf(Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'), $messageCount); + /** @var string $format */ + $format = Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'); + $message = sprintf($format, $messageCount); parent::__construct($message, $code, $previous); } diff --git a/src/Application/Model/MessageSender.php b/src/Application/Model/MessageSender.php index 7060e7d..6a72eb0 100644 --- a/src/Application/Model/MessageSender.php +++ b/src/Application/Model/MessageSender.php @@ -24,10 +24,11 @@ class MessageSender { /** * @param Order $order - * @param $messageBody + * @param string $messageBody + * @return void * @throws Exception */ - public function sendOrderFinishedMessage(Order $order, $messageBody) + public function sendOrderFinishedMessage(Order $order, string $messageBody): void { if ((oxNew(Configuration::class))->sendOrderFinishedMessage()) { $this->sendMessageByOrder($order, $messageBody); @@ -36,10 +37,11 @@ class MessageSender /** * @param Order $order - * @param $messageBody + * @param string $messageBody + * @return void * @throws Exception */ - public function sendSendedNowMessage(Order $order, $messageBody) + public function sendSendedNowMessage(Order $order, string $messageBody): void { if ((oxNew(Configuration::class))->sendOrderSendedNowMessage()) { $this->sendMessageByOrder($order, $messageBody); @@ -48,10 +50,11 @@ class MessageSender /** * @param Order $order - * @param $messageBody + * @param string $messageBody + * @return void * @throws Exception */ - public function sendCancelOrderMessage(Order $order, $messageBody) + public function sendCancelOrderMessage(Order $order, string $messageBody): void { if ((oxNew(Configuration::class))->sendOrderCanceledMessage()) { $this->sendMessageByOrder($order, $messageBody); @@ -60,10 +63,11 @@ class MessageSender /** * @param Order $order - * @param $messageBody + * @param string $messageBody + * @return void * @throws Exception */ - public function sendMessageByOrder(Order $order, $messageBody) + public function sendMessageByOrder(Order $order, string $messageBody): void { if ((bool) strlen(trim($messageBody)) === false) { return; diff --git a/src/Application/Model/MessageTypes/AbstractMessage.php b/src/Application/Model/MessageTypes/AbstractMessage.php index b51eca0..b8c9f18 100644 --- a/src/Application/Model/MessageTypes/AbstractMessage.php +++ b/src/Application/Model/MessageTypes/AbstractMessage.php @@ -24,11 +24,16 @@ abstract class AbstractMessage { public const REMARK_IDENT = 'LINKMOB'; + /** @var string */ protected $message; + /** @var bool */ protected $removeLineBreaks = true; + /** @var bool */ protected $removeMultipleSpaces = true; + /** @var ResponseInterface */ protected $response; + /** @var Recipient[] */ protected $recipients = []; /** @@ -48,13 +53,14 @@ abstract class AbstractMessage } /** - * @param $userId - * @param $recipients - * @param $message + * @param string $userId + * @param string $recipients + * @param string $message * + * @return void * @throws Exception */ - protected function setRemark($userId, $recipients, $message) + protected function setRemark(string $userId, string $recipients, string $message): void { $remark = oxNew(Remark::class); $remark->assign([ @@ -74,7 +80,7 @@ abstract class AbstractMessage } /** - * @param array $recipients + * @param array $recipients * @return void */ protected function setRecipients(array $recipients) @@ -97,16 +103,16 @@ abstract class AbstractMessage } /** - * @param $message + * @param string $message * * @return string */ - protected function sanitizeMessage($message): string + protected function sanitizeMessage(string $message): string { $message = trim(strip_tags($message)); $message = $this->removeLineBreaks ? str_replace(["\r", "\n"], ' ', $message) : $message; $regexp = '/\s{2,}/m'; - return $this->removeMultipleSpaces ? preg_replace($regexp, ' ', $message) : $message; + return $this->removeMultipleSpaces ? (string) preg_replace($regexp, ' ', $message) : $message; } abstract public function getTypeName(): string; diff --git a/src/Application/Model/MessageTypes/Sms.php b/src/Application/Model/MessageTypes/Sms.php index 0045104..013f494 100644 --- a/src/Application/Model/MessageTypes/Sms.php +++ b/src/Application/Model/MessageTypes/Sms.php @@ -25,6 +25,7 @@ use D3\Linkmobility4OXID\Application\Model\UserRecipients; use D3\LinkmobilityClient\Exceptions\ApiException; use D3\LinkmobilityClient\Request\RequestInterface; use D3\LinkmobilityClient\SMS\SmsRequestInterface; +use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Sender; use Exception; use GuzzleHttp\Exception\GuzzleException; @@ -87,7 +88,7 @@ class Sms extends AbstractMessage } /** - * @param array $recipientsArray + * @param array $recipientsArray * * @return bool */ @@ -126,16 +127,17 @@ class Sms extends AbstractMessage return $response->isSuccessful(); } catch (abortSendingExceptionInterface $e) { Registry::getLogger()->warning($e->getMessage()); - Registry::getUtilsView()->addErrorToDisplay($e); + // Oxid does not accept throwable interface only exceptions according by definition + Registry::getUtilsView()->addErrorToDisplay($e->getMessage()); } catch (GuzzleException $e) { Registry::getLogger()->warning($e->getMessage()); - Registry::getUtilsView()->addErrorToDisplay($e); + Registry::getUtilsView()->addErrorToDisplay($e->getMessage()); } catch (ApiException $e) { Registry::getLogger()->warning($e->getMessage()); - Registry::getUtilsView()->addErrorToDisplay($e); + Registry::getUtilsView()->addErrorToDisplay($e->getMessage()); } catch (InvalidArgumentException $e) { Registry::getLogger()->warning($e->getMessage()); - Registry::getUtilsView()->addErrorToDisplay($e); + Registry::getUtilsView()->addErrorToDisplay($e->getMessage()); } return false; diff --git a/src/Application/Model/OrderRecipients.php b/src/Application/Model/OrderRecipients.php index 34084c2..b77bed2 100644 --- a/src/Application/Model/OrderRecipients.php +++ b/src/Application/Model/OrderRecipients.php @@ -42,12 +42,16 @@ class OrderRecipients public function getSmsRecipient(): Recipient { foreach ($this->getSmsRecipientFields() as $phoneFieldName => $countryIdFieldName) { - $content = trim((string) $this->order->getFieldData($phoneFieldName)); + /** @var string $content */ + $content = $this->order->getFieldData($phoneFieldName) ?: ''; + $content = trim($content); $country = oxNew(Country::class); try { if (strlen($content)) { - $country->load($this->order->getFieldData($countryIdFieldName)); + /** @var string $countryId */ + $countryId = $this->order->getFieldData(trim($countryIdFieldName)); + $country->load($countryId); return oxNew(Recipient::class, $content, $country->getFieldData('oxisoalpha2')); } } catch (NumberParseException $e) { diff --git a/src/Application/Model/RequestFactory.php b/src/Application/Model/RequestFactory.php index 7f0004c..fe47e19 100644 --- a/src/Application/Model/RequestFactory.php +++ b/src/Application/Model/RequestFactory.php @@ -25,6 +25,7 @@ class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory { $configuration = oxNew(Configuration::class); + /** @var SmsRequestInterface $request */ $request = parent::getSmsRequest(); $request->setTestMode($configuration->getTestMode()) ->setSenderAddress( diff --git a/src/Application/Model/UserRecipients.php b/src/Application/Model/UserRecipients.php index f6828df..def0a47 100644 --- a/src/Application/Model/UserRecipients.php +++ b/src/Application/Model/UserRecipients.php @@ -42,12 +42,16 @@ class UserRecipients public function getSmsRecipient(): Recipient { foreach ($this->getSmsRecipientFields() as $fieldName) { - $content = trim($this->user->getFieldData($fieldName)); + /** @var string $content */ + $content = $this->user->getFieldData($fieldName) ?: ''; + $content = trim($content); $country = oxNew(Country::class); try { if (strlen($content)) { - $country->load($this->user->getFieldData('oxcountryid')); + /** @var string $countryId */ + $countryId = $this->user->getFieldData('oxcountryid'); + $country->load($countryId); return oxNew(Recipient::class, $content, $country->getFieldData('oxisoalpha2')); } } catch (NumberParseException $e) { diff --git a/src/Modules/Application/Model/OrderModel.php b/src/Modules/Application/Model/OrderModel.php index b8ff5d5..3e5fc61 100644 --- a/src/Modules/Application/Model/OrderModel.php +++ b/src/Modules/Application/Model/OrderModel.php @@ -17,14 +17,21 @@ namespace D3\Linkmobility4OXID\Modules\Application\Model; use D3\Linkmobility4OXID\Modules\Core\EmailCore; use OxidEsales\Eshop\Core\Email; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class OrderModel extends OrderModel_parent { - public function cancelOrder() + /** + * @return void + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function cancelOrder(): void { parent::cancelOrder(); - if ($this->getFieldData('oxstorno') === 1) { + if ((bool) $this->getFieldData('oxstorno') === true) { /** @var EmailCore $Email */ $Email = oxNew(Email::class); $Email->d3SendCancelMessage($this); diff --git a/src/Modules/Core/EmailCore.php b/src/Modules/Core/EmailCore.php index ef87e4f..58182b7 100644 --- a/src/Modules/Core/EmailCore.php +++ b/src/Modules/Core/EmailCore.php @@ -26,13 +26,16 @@ use Psr\Container\NotFoundExceptionInterface; class EmailCore extends EmailCore_parent { + /** @var string */ protected $d3OrderCustSmsTemplate = 'd3sms_ordercust.tpl'; + /** @var string */ protected $d3OrderSendedNowSmsTemplate = 'd3sms_sendednow.tpl'; + /** @var string */ protected $d3OrderCanceledSmsTemplate = 'd3sms_ordercanceled.tpl'; /** * @param Order $order - * @param null $subject + * @param string $subject * * @return bool * @throws ContainerExceptionInterface @@ -49,7 +52,7 @@ class EmailCore extends EmailCore_parent /** * @param Order $order - * @param null $subject + * @param string $subject * * @return bool * @throws ContainerExceptionInterface @@ -67,11 +70,12 @@ class EmailCore extends EmailCore_parent /** * @param Order $order * + * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws Exception */ - public function d3SendOrderFinishedMessageToUser(Order $order) + public function d3SendOrderFinishedMessageToUser(Order $order): void { $messageSender = oxNew(MessageSender::class); $messageSender->sendOrderFinishedMessage($order, $this->d3GetOrderFinishedSmsMessageBody($order)); @@ -95,11 +99,12 @@ class EmailCore extends EmailCore_parent /** * @param Order $order * + * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws Exception */ - public function d3SendedNowMessage(Order $order) + public function d3SendedNowMessage(Order $order): void { $messageSender = oxNew(MessageSender::class); $messageSender->sendSendedNowMessage($order, $this->d3GetSendedNowSmsMessageBody($order)); @@ -121,13 +126,14 @@ class EmailCore extends EmailCore_parent } /** - * @param $order + * @param Order $order * + * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws Exception */ - public function d3SendCancelMessage($order) + public function d3SendCancelMessage(Order $order): void { $messageSender = oxNew(MessageSender::class); $messageSender->sendCancelOrderMessage($order, $this->d3GetCancelOrderSmsMessageBody($order)); @@ -157,6 +163,7 @@ class EmailCore extends EmailCore_parent */ protected function d3GetTplRenderer(): TemplateRendererInterface { + /** @var TemplateRendererBridgeInterface $bridge */ $bridge = ContainerFactory::getInstance()->getContainer() ->get(TemplateRendererBridgeInterface::class); $bridge->setEngine($this->_getSmarty()); From 9eff4ad29631dd833784ab72bb699496ea36de88 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 28 Jul 2022 10:30:14 +0200 Subject: [PATCH 09/20] improve changelog --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 680c5a4..76761c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ # Changelog +All notable changes to this project will be documented in this file. ---- +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 1.0.0.0 (2022-07-13) +## [Unreleased](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.0.0.0...rel_1.x) +## [1.0.0.0](https://git.d3data.de/D3Private/linkmobility4oxid/releases/tag/1.0.0.0) - 2022-07-13 +### Added - initial implementation Send message on: - Order completion, sending order confirmation message. From a00061a37cd52ff880e7298a602050359a297465 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 28 Jul 2022 10:39:56 +0200 Subject: [PATCH 10/20] adjust version informations --- CHANGELOG.md | 15 ++++++++++++++- src/metadata.php | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76761c9..9845eff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.0.0.0...rel_1.x) +## [Unreleased](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.1.0.0...rel_1.x) + +## [1.1.0.0](https://git.d3data.de/D3Private/linkmobility4oxid/releases/tag/1.1.0.0) - 2022-07-28 +### Added +- phpstan code checks + +### Changed +- improved changelog + +### Fixed +- type in IntelliSenseHelper class name + +### Removed +- PHP 7.0 support ## [1.0.0.0](https://git.d3data.de/D3Private/linkmobility4oxid/releases/tag/1.0.0.0) - 2022-07-13 ### Added diff --git a/src/metadata.php b/src/metadata.php index e3a1efa..e431909 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -34,7 +34,7 @@ $aModule = [ 'de' => 'Anbindung der LINK Mobility API (Nachrichtenversand per SMS) an den Shop', 'en' => 'Connection of the LINK Mobility API ( sending messages via SMS) to the shop', ], - 'version' => '1.0.0.0', + 'version' => '1.1.0.0', 'thumbnail' => 'picture.png', 'author' => 'D³ Data Development (Inh.: Thomas Dartsch)', 'email' => 'support@shopmodule.com', From ff45750c3597b433e015ecabfa4b334b6093a84f Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 28 Jul 2022 10:42:55 +0200 Subject: [PATCH 11/20] fix release link in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9845eff..71312e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.1.0.0...rel_1.x) -## [1.1.0.0](https://git.d3data.de/D3Private/linkmobility4oxid/releases/tag/1.1.0.0) - 2022-07-28 +## [1.1.0.0](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.0.0.0...1.1.0.0) - 2022-07-28 ### Added - phpstan code checks From b8cd9b3b0ddf7b2c78b81e35838db387d8d27fbe Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 8 Sep 2022 15:47:34 +0200 Subject: [PATCH 12/20] add support note --- README.en.md | 6 ++++++ README.md | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/README.en.md b/README.en.md index ef366ca..9698707 100644 --- a/README.en.md +++ b/README.en.md @@ -54,6 +54,12 @@ If you have a suggestion that would make this better, please fork the repo and c - Push to the Branch (git push origin feature/AmazingFeature) - Open a Pull Request +## Support + +If you have any questions about the *messaging service* and its *contracts*, please contact the [LINK Mobility Team](https://www.linkmobility.de/kontakt). + +For *technical inquiries* you will find the contact options in the [composer.json](composer.json). + ## License (status: 2022-07-13) diff --git a/README.md b/README.md index 4eb2aa8..26f6c74 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ Wenn Sie eine Verbesserungsvorschlag haben, legen Sie einen Fork des Repositorie - Übertragen Sie den Branch (git push origin feature/AmazingFeature) - Öffnen Sie einen Pull Request +## Support + +Bei Fragen zum *Messaging Service* und dessen *Verträgen* kontaktieren Sie bitte das [LINK Mobility Team](https://www.linkmobility.de/kontakt). + +Zu *technischen Anfragen* finden Sie die Kontaktmöglichkeiten in der [composer.json](composer.json). + ## Lizenz (Stand: 13.07.2022) From d964824fa15457032d38c14e3a42df73d8500680 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 8 Sep 2022 22:01:19 +0200 Subject: [PATCH 13/20] make installable in OXID 6.5 (CE 6.12) --- README.en.md | 1 + README.md | 1 + composer.json | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.en.md b/README.en.md index 9698707..445cf8a 100644 --- a/README.en.md +++ b/README.en.md @@ -27,6 +27,7 @@ This package requires an OXID eShop installed with Composer in one of the follow - 6.2.4 or above - 6.3.x - 6.4.x +- 6.5.x and its requirements. diff --git a/README.md b/README.md index 26f6c74..d561d7b 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Dieses Paket erfordert einen mit Composer installierten OXID eShop in einer der - 6.2.4 oder höher - 6.3.x - 6.4.x +- 6.5.x und dessen Anforderungen. diff --git a/composer.json b/composer.json index 89e858a..ef14a53 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ ], "require": { "php": "^7.1 || ^8.0", - "oxid-esales/oxideshop-ce": "6.7 - 6.10", + "oxid-esales/oxideshop-ce": "6.7 - 6.12", "d3/linkmobility-php-client": "^1.2.0 || ^2.0.0" }, "require-dev": { From 258961bddc79f1ecced067a9d039b91554a440d7 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 8 Sep 2022 22:11:23 +0200 Subject: [PATCH 14/20] add license information --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index ef14a53..b5a09fc 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,9 @@ "role": "Owner" } ], + "license": [ + "GPL-3.0-or-later" + ], "require": { "php": "^7.1 || ^8.0", "oxid-esales/oxideshop-ce": "6.7 - 6.12", From a38c350245de1304b69dc8b6475ee53223f6b42e Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 29 Sep 2022 09:18:58 +0200 Subject: [PATCH 15/20] adjust README --- CHANGELOG.md | 6 +++++- README.en.md | 2 +- README.md | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71312e6..9430e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.1.0.0...rel_1.x) +## [Unreleased](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.1.0.1...rel_1.x) + +## [1.1.0.1](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.1.0.0...1.1.0.1) - 2022-09-29 +### Changed +- adjust readme ## [1.1.0.0](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.0.0.0...1.1.0.0) - 2022-07-28 ### Added diff --git a/README.en.md b/README.en.md index 445cf8a..dfd19cf 100644 --- a/README.en.md +++ b/README.en.md @@ -1,7 +1,7 @@ [![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md) [![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md) -# Integration of the LINK Mobility Austria service into the OXID eShop +# Integration of the LINK Mobility service into the OXID eShop [LINK Mobility](https://www.linkmobility.de/) provides a service for sending mobile messages (SMS, Whatsapp, RCS, Chatbot, ...). diff --git a/README.md b/README.md index d561d7b..37a9a24 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md) [![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md) -# Integration des LINK Mobility Austria Dienstes in den OXID eShop +# Integration des LINK Mobility Dienstes in den OXID eShop [LINK Mobility](https://www.linkmobility.de/) stellt einen Service zum Versenden von mobilen Nachrichten (SMS, Whatsapp, RCS, Chatbot, ...) zur Verfügung. From 841d2c0879f6a4e86fff1c2986f3094dfc5bf242 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 13 Dec 2022 14:45:56 +0100 Subject: [PATCH 16/20] make installable in OXID 6.5.1 (CE 6.13) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b5a09fc..2d1c799 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "require": { "php": "^7.1 || ^8.0", - "oxid-esales/oxideshop-ce": "6.7 - 6.12", + "oxid-esales/oxideshop-ce": "6.7 - 6.13", "d3/linkmobility-php-client": "^1.2.0 || ^2.0.0" }, "require-dev": { From 07b4f9523dc64b393b00aecc58f4dcd8bb30499f Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 15 Dec 2022 08:38:52 +0100 Subject: [PATCH 17/20] fix error if configuration is missing --- src/Application/Model/Configuration.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Application/Model/Configuration.php b/src/Application/Model/Configuration.php index 534d16d..1e46abb 100644 --- a/src/Application/Model/Configuration.php +++ b/src/Application/Model/Configuration.php @@ -93,7 +93,7 @@ class Configuration public function getOrderRecipientFields(): array { /** @var string[] $customFields */ - $customFields = Registry::getConfig()->getConfigParam(self::ORDER_RECFIELDS); + $customFields = Registry::getConfig()->getConfigParam(self::ORDER_RECFIELDS) ?: []; array_walk( $customFields, @@ -113,7 +113,7 @@ class Configuration public function getUserRecipientFields(): array { /** @var string[] $customFields */ - $customFields = Registry::getConfig()->getConfigParam(self::USER_RECFIELDS); + $customFields = Registry::getConfig()->getConfigParam(self::USER_RECFIELDS) ?: []; array_walk( $customFields, @@ -138,7 +138,7 @@ class Configuration { $checkCountryFieldName = $args[self::ARGS_CHECKKEYS] ? trim($checkCountryFieldName) : $checkCountryFieldName; $checkPhoneFieldName = trim($checkPhoneFieldName); - $allFieldNames = oxNew($args[self::ARGS_CHECKCLASS])->getFieldNames(); + $allFieldNames = oxNew($args[self::ARGS_CHECKCLASS])->getFieldNames() ?: []; array_walk($allFieldNames, function (&$value) { $value = strtolower($value); From e294da36ae7b1ec45db8799f034616381e936a49 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sat, 17 Dec 2022 23:52:49 +0100 Subject: [PATCH 18/20] mark OXID 6.3.0 as excluded in documentation --- README.en.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.en.md b/README.en.md index dfd19cf..09a6aed 100644 --- a/README.en.md +++ b/README.en.md @@ -25,7 +25,7 @@ Message dispatch (currently SMS) can be activated individually for the following This package requires an OXID eShop installed with Composer in one of the following versions: - 6.2.4 or above -- 6.3.x +- 6.3.1 or above - 6.4.x - 6.5.x diff --git a/README.md b/README.md index 37a9a24..6f13f5b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Bei folgenden Aktionen kann der Nachrichtenversand (derzeit SMS) einzeln aktivie Dieses Paket erfordert einen mit Composer installierten OXID eShop in einer der folgenden Versionen: - 6.2.4 oder höher -- 6.3.x +- 6.3.1 oder höher - 6.4.x - 6.5.x From 5faa4ddb13dd4bf53f3af3b16a942d75b13e2229 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sun, 18 Dec 2022 23:45:14 +0100 Subject: [PATCH 19/20] add enum type actions --- src/Setup/Actions.php | 135 ++++++++++++++++++++++++++++++++++++++++++ src/Setup/Events.php | 47 +++++++++++++++ src/metadata.php | 6 +- 3 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 src/Setup/Actions.php create mode 100644 src/Setup/Events.php diff --git a/src/Setup/Actions.php b/src/Setup/Actions.php new file mode 100644 index 0000000..a2c4a95 --- /dev/null +++ b/src/Setup/Actions.php @@ -0,0 +1,135 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\Linkmobility4OXID\Setup; + +use D3\Linkmobility4OXID\Application\Model\MessageTypes\AbstractMessage; +use Doctrine\DBAL\Driver\Exception as DoctrineDriverException; +use Doctrine\DBAL\Exception as DoctrineException; +use Doctrine\DBAL\Query\QueryBuilder; +use OxidEsales\Eshop\Core\DatabaseProvider; +use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; +use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; +use OxidEsales\Eshop\Core\Exception\DatabaseException; +use OxidEsales\Eshop\Core\Registry; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; + +class Actions +{ + /** + * @return void + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function setupDatabase() + { + try { + if (!$this->hasRemarkTypeEnumValue()) { + $this->addRemarkTypeEnumValue(); + } + } catch (DatabaseException|DoctrineDriverException|DoctrineException $e) { + Registry::getLogger()->error($e->getMessage()); + Registry::getUtilsView()->addErrorToDisplay($e); + } + } + + /** + * @return bool + * @throws ContainerExceptionInterface + * @throws DoctrineDriverException + * @throws DoctrineException + * @throws NotFoundExceptionInterface + */ + protected function hasRemarkTypeEnumValue(): bool + { + $fieldType = $this->getRemarkTypeFieldType(); + + $patternEnumCheck = '/^\b(enum)\b/mi'; + if (!preg_match($patternEnumCheck, $fieldType)) { + throw oxNew(DatabaseException::class, 'remark type field has not the expected enum type'); + } + + $patternValueCheck = '/\b('.preg_quote(AbstractMessage::REMARK_IDENT).')\b/mi'; + + return (bool) preg_match($patternValueCheck, $fieldType); + } + + /** + * @return string + * @throws DoctrineDriverException + * @throws DoctrineException + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + protected function getRemarkTypeFieldType(): string + { + /** @var QueryBuilder $qb */ + $qb = ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + $qb->select('column_type') + ->from('INFORMATION_SCHEMA.COLUMNS') + ->where( + $qb->expr()->and( + $qb->expr()->eq( + 'table_schema', + $qb->createNamedParameter(Registry::getConfig()->getConfigParam('dbName')) + ), + $qb->expr()->eq( + 'table_name', + $qb->createNamedParameter('oxremark') + ), + $qb->expr()->eq( + 'COLUMN_NAME', + $qb->createNamedParameter('oxtype') + ) + ) + ); + + return (string) $qb->execute()->fetchOne(); + } + + /** + * @return void + * @throws DoctrineDriverException + * @throws DoctrineException + * @throws DatabaseConnectionException + * @throws DatabaseErrorException + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + protected function addRemarkTypeEnumValue() + { + $valuePattern = '/(?<=enum\().*(?=\))/i'; + preg_match($valuePattern, $this->getRemarkTypeFieldType(), $matches); + + $items = array_unique( + array_merge( + str_getcsv($matches[0], ',', "'"), + [AbstractMessage::REMARK_IDENT] + ) + ); + + $db = DatabaseProvider::getDb(); + + $query = 'ALTER TABLE '.$db->quoteIdentifier('oxremark'). + ' CHANGE '.$db->quoteIdentifier('OXTYPE'). ' '.$db->quoteIdentifier('OXTYPE') . + ' enum('.implode(',', $db->quoteArray($items)).')'. + ' COLLATE '.$db->quote('utf8_general_ci').' NOT NULL DEFAULT '.$db->quote('r'); + + $db->execute($query); + } +} \ No newline at end of file diff --git a/src/Setup/Events.php b/src/Setup/Events.php new file mode 100644 index 0000000..fd29ee9 --- /dev/null +++ b/src/Setup/Events.php @@ -0,0 +1,47 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +// @codeCoverageIgnoreStart + +namespace D3\Linkmobility4OXID\Setup; + +use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; +use D3\ModCfg\Application\Model\Install\d3install; +use Doctrine\DBAL\DBALException; +use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; +use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; +use OxidEsales\Eshop\Core\Exception\StandardException; +use OxidEsales\Eshop\Core\Exception\SystemComponentException; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; + +class Events +{ + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public static function onActivate() + { + /** @var Actions $actions */ + $actions = oxNew(Actions::class); + $actions->setupDatabase(); + } + + public static function onDeactivate() + { + } +} +// @codeCoverageIgnoreEnd diff --git a/src/metadata.php b/src/metadata.php index e431909..3e53c9d 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -17,6 +17,7 @@ use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; use D3\Linkmobility4OXID\Modules\Application\Model\OrderModel; use D3\Linkmobility4OXID\Modules\Core\EmailCore; +use D3\Linkmobility4OXID\Setup\Events; use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Core\Email; @@ -54,7 +55,10 @@ $aModule = [ 'd3sms_sendednow.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/sendednow.tpl', 'd3sms_ordercanceled.tpl' => 'd3/linkmobility/Application/views/tpl/SMS/ordercanceled.tpl', ], - 'events' => [], + 'events' => [ + 'onActivate' => Events::class.'::onActivate', + 'onDeactivate' => Events::class.'::onDeactivate', + ], 'blocks' => [ [ 'template' => 'order_remark.tpl', From 54a2a721cb529cb9770eecaebcf13a3c2fd27ff5 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Mon, 19 Dec 2022 10:59:38 +0100 Subject: [PATCH 20/20] perform a views regenerating --- src/Setup/Actions.php | 12 ++++++++++++ src/Setup/Events.php | 1 + 2 files changed, 13 insertions(+) diff --git a/src/Setup/Actions.php b/src/Setup/Actions.php index a2c4a95..f565eea 100644 --- a/src/Setup/Actions.php +++ b/src/Setup/Actions.php @@ -20,6 +20,7 @@ use Doctrine\DBAL\Driver\Exception as DoctrineDriverException; use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Query\QueryBuilder; use OxidEsales\Eshop\Core\DatabaseProvider; +use OxidEsales\Eshop\Core\DbMetaDataHandler; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseException; @@ -48,6 +49,17 @@ class Actions } } + + + /** + * Regenerate views for changed tables + */ + public function regenerateViews() + { + $oDbMetaDataHandler = oxNew(DbMetaDataHandler::class); + $oDbMetaDataHandler->updateViews(); + } + /** * @return bool * @throws ContainerExceptionInterface diff --git a/src/Setup/Events.php b/src/Setup/Events.php index fd29ee9..9cc4892 100644 --- a/src/Setup/Events.php +++ b/src/Setup/Events.php @@ -38,6 +38,7 @@ class Events /** @var Actions $actions */ $actions = oxNew(Actions::class); $actions->setupDatabase(); + $actions->regenerateViews(); } public static function onDeactivate()