Compare commits

...

6 Commits

8 changed files with 220 additions and 9 deletions

View File

@ -4,7 +4,19 @@ 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.1...rel_1.x)
## [Unreleased](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.1.1.0...rel_1.x)
## [1.1.1.0](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.1.0.1...1.1.1.0) - 2023-01-01
### Added
- make installable in OXID 6.5.1 (CE 6.13)
- add linkmobility to remark types in installation triggers
- regenerate database views in installation process
### Changed
- adjust requirements
### Fixed
- fix error if configuration is missing
## [1.1.0.1](https://git.d3data.de/D3Private/linkmobility4oxid/compare/1.1.0.0...1.1.0.1) - 2022-09-29
### Changed

View File

@ -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

View File

@ -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

View File

@ -22,7 +22,7 @@
],
"require": {
"php": "^7.1 || ^8.0",
"oxid-esales/oxideshop-ce": "6.7 - 6.12",
"oxid-esales/oxideshop-ce": "~6.7.0 || ~6.9.0 || 6.10 - 6.13",
"d3/linkmobility-php-client": "^1.2.0 || ^2.0.0"
},
"require-dev": {

View File

@ -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);

147
src/Setup/Actions.php Normal file
View File

@ -0,0 +1,147 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @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\DbMetaDataHandler;
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);
}
}
/**
* Regenerate views for changed tables
*/
public function regenerateViews()
{
$oDbMetaDataHandler = oxNew(DbMetaDataHandler::class);
$oDbMetaDataHandler->updateViews();
}
/**
* @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);
}
}

48
src/Setup/Events.php Normal file
View File

@ -0,0 +1,48 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @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();
$actions->regenerateViews();
}
public static function onDeactivate()
{
}
}
// @codeCoverageIgnoreEnd

View File

@ -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;
@ -34,7 +35,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.1.0.0',
'version' => '1.1.1.0',
'thumbnail' => 'picture.png',
'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
@ -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',