move message content to CMS items

This commit is contained in:
Daniel Seifert 2023-01-14 22:08:47 +01:00
parent ae8e04c23c
commit 4632fe1df7
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
6 changed files with 387 additions and 53 deletions

View File

@ -1,7 +1,3 @@
[{assign var="shop" value=$oEmailView->getShop()}]
Hallo [{$order->getFieldData('oxbillfname')}] [{$order->getFieldData('oxbilllname')}],
vielen Dank für Ihre Bestellung. Wir haben diese unter der Bestellnummer [{$order->oxorder__oxordernr->value}] angelegt und werden diese schnellstmöglich bearbeiten.
Ihr Team von [{$shop->getFieldData('oxname')}].
[{oxcontent ident="d3linkmobilityfinishedorder"}]

View File

@ -1,8 +1,3 @@
[{assign var="shop" value=$oEmailView->getShop()}]
Hallo [{$order->getFieldData('oxbillfname')}] [{$order->getFieldData('oxbilllname')}],
Ihre Bestellung [{$order->oxorder__oxordernr->value}] wurde storniert.
Ihr Team von [{$shop->getFieldData('oxname')}].
[{oxcontent ident="d3linkmobilityordercanceled"}]

View File

@ -1,7 +1,3 @@
[{assign var="shop" value=$oEmailView->getShop()}]
Hallo [{$order->getFieldData('oxbillfname')}] [{$order->getFieldData('oxbilllname')}],
Ihre Bestellung [{$order->oxorder__oxordernr->value}] wurde eben versendet. [{if $order->getFieldData('oxtrackcode')}]Der Trackingcode dazu ist: [{$order->getFieldData('oxtrackcode')}].[{/if}]
Ihr Team von [{$shop->getFieldData('oxname')}].
[{oxcontent ident="d3linkmobilityordersendednow"}]

View File

@ -17,19 +17,19 @@ namespace D3\Linkmobility4OXID\Setup;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\AbstractMessage;
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Statement;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Content;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
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\StandardException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\UtilsView;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactory;
@ -106,7 +106,6 @@ class Actions
{
/** @var QueryBuilderFactory $queryBuilderFactory */
$queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class);
/** @var QueryBuilder $qb */
$qb = $queryBuilderFactory->create();
$qb->select('column_type')
->from('INFORMATION_SCHEMA.COLUMNS')
@ -114,7 +113,7 @@ class Actions
$qb->expr()->and(
$qb->expr()->eq(
'table_schema',
$qb->createNamedParameter(Registry::getConfig()->getConfigParam('dbName'))
$qb->createNamedParameter($this->getConfig()->getConfigParam('dbName'))
),
$qb->expr()->eq(
'table_name',
@ -146,8 +145,7 @@ class Actions
{
$items = $this->getUniqueFieldTypes();
/** @var Database $db */
$db = d3GetOxidDIC()->get('d3ox.linkmobility.'.DatabaseInterface::class.'.assoc');
$db = $this->getDb();
$query = 'ALTER TABLE '.$db->quoteIdentifier('oxremark').
' CHANGE '.$db->quoteIdentifier('OXTYPE'). ' '.$db->quoteIdentifier('OXTYPE') .
@ -175,11 +173,172 @@ class Actions
);
}
/**
* @return void
* @throws DoctrineDriverException
* @throws DoctrineException
*/
public function checkCmsItems()
{
foreach(
[
'd3linkmobilityordercanceled' => 'addCms1Item',
'd3linkmobilityfinishedorder' => 'addCms2Item',
'd3linkmobilityordersendednow' => 'addCms3Item'
] as $checkIdent => $methodName
) {
if ($this->cmsMissing($checkIdent)) {
call_user_func([$this, $methodName]);
}
}
}
/**
* @param $checkIdent
* @return bool
* @throws DoctrineDriverException
* @throws DoctrineException
*/
protected function cmsMissing($checkIdent): bool
{
/** @var QueryBuilder $qb */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
$qb->select('count(oxid)')
->from(oxNew(Content::class)->getViewName())
->where(
$qb->expr()->and(
$qb->expr()->eq(
'oxloadid',
$qb->createNamedParameter($checkIdent)
),
$qb->expr()->eq(
'oxshopid',
$qb->createNamedParameter($this->getConfig()->getShopId())
)
)
)
->getFirstResult();
/** @var Statement $statement */
$statement = $qb->execute();
return !$statement->fetchOne();
}
/**
* @return void
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
protected function addCms1Item()
{
/** @var QueryBuilder $qb */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
$qb->insert('oxcontents')
->values([
'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))',
'oxloadid' => $qb->createNamedParameter('d3linkmobilityordercanceled'),
'oxshopid' => $qb->createNamedParameter($this->getConfig()->getShopId()),
'oxsnippet' => $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxtype' => $qb->createNamedParameter(0, ParameterType::INTEGER),
'oxactive' => $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxactive_1'=> $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxposition'=> $qb->createNamedParameter(''),
'oxtitle' => $qb->createNamedParameter('Linkmobility: Bestellung storniert'),
'oxcontent' => $qb->createNamedParameter('Hallo [{$order->getFieldData(\'oxbillfname\')}] [{$order->getFieldData(\'oxbilllname\')}],'.PHP_EOL.PHP_EOL.'Ihre Bestellung [{$order->getFieldData(\'oxordernr\')}] wurde storniert.'.PHP_EOL.PHP_EOL.'Ihr Team von [{$shop->getFieldData(\'oxname\')}].'),
'oxtitle_1' => $qb->createNamedParameter('Linkmobility: order canceled'),
'oxcontent_1'=> $qb->createNamedParameter('Hello [{$order->getFieldData(\'oxbillfname\')}] [{$order->getFieldData(\'oxbilllname\')}],'.PHP_EOL.PHP_EOL.'Your order [{$order->getFieldData(\'oxordernr\')}] has been cancelled.'.PHP_EOL.PHP_EOL.'Your team at [{$shop->getFieldData(\'oxname\')}].'),
'oxcatid' => $qb->createNamedParameter('943a9ba3050e78b443c16e043ae60ef3'),
'oxfolder' => $qb->createNamedParameter('')
]);
$qb->execute();
}
/**
* @return void
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
protected function addCms2Item()
{
/** @var QueryBuilder $qb */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
$qb->insert('oxcontents')
->values([
'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))',
'oxloadid' => $qb->createNamedParameter('d3linkmobilityfinishedorder'),
'oxshopid' => $qb->createNamedParameter($this->getConfig()->getShopId()),
'oxsnippet' => $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxtype' => $qb->createNamedParameter(0, ParameterType::INTEGER),
'oxactive' => $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxactive_1'=> $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxposition'=> $qb->createNamedParameter(''),
'oxtitle' => $qb->createNamedParameter('Linkmobility: Bestellung eingegangen'),
'oxcontent' => $qb->createNamedParameter('Hallo [{$order->getFieldData(\'oxbillfname\')}] [{$order->getFieldData(\'oxbilllname\')}],'.PHP_EOL.PHP_EOL.'vielen Dank für Ihre Bestellung. Wir haben diese unter der Bestellnummer [{$order->getFieldData(\'oxordernr\')}] angelegt und werden diese schnellstmöglich bearbeiten.'.PHP_EOL.PHP_EOL.'Ihr Team von [{$shop->getFieldData(\'oxname\')}].'),
'oxtitle_1' => $qb->createNamedParameter('Linkmobility: order recieved'),
'oxcontent_1'=> $qb->createNamedParameter('Hello [{$order->getFieldData(\'oxbillfname\')}] [{$order->getFieldData(\'oxbilllname\')}],'.PHP_EOL.PHP_EOL.'Thank you for your order. We have saved it under the order number [{$order->getFieldData(\'oxordernr\')}] and will process it as soon as possible.'.PHP_EOL.PHP_EOL.'Your team at [{$shop->getFieldData(\'oxname\')}].'),
'oxcatid' => $qb->createNamedParameter('943a9ba3050e78b443c16e043ae60ef3'),
'oxfolder' => $qb->createNamedParameter('')
]);
$qb->execute();
}
/**
* @return void
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
*/
protected function addCms3Item()
{
/** @var QueryBuilder $qb */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
$qb->insert('oxcontents')
->values([
'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))',
'oxloadid' => $qb->createNamedParameter('d3linkmobilityordersendednow'),
'oxshopid' => $qb->createNamedParameter($this->getConfig()->getShopId()),
'oxsnippet' => $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxtype' => $qb->createNamedParameter(0, ParameterType::INTEGER),
'oxactive' => $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxactive_1'=> $qb->createNamedParameter(1, ParameterType::INTEGER),
'oxposition'=> $qb->createNamedParameter(''),
'oxtitle' => $qb->createNamedParameter('Linkmobility: Bestellung versendet'),
'oxcontent' => $qb->createNamedParameter('Hallo [{$order->getFieldData(\'oxbillfname\')}] [{$order->getFieldData(\'oxbilllname\')}],'.PHP_EOL.PHP_EOL.'Ihre Bestellung [{$order->getFieldData(\'oxordernr\')}] wurde eben versendet. [{if $order->getFieldData(\'oxtrackcode\')}]Der Trackingcode dazu ist: [{$order->getFieldData(\'oxtrackcode\')}].[{/if}]'.PHP_EOL.PHP_EOL.'Ihr Team von [{$shop->getFieldData(\'oxname\')}].'),
'oxtitle_1' => $qb->createNamedParameter('Linkmobility: order shipped'),
'oxcontent_1'=> $qb->createNamedParameter('Hello [{$order->getFieldData(\'oxbillfname\')}] [{$order->getFieldData(\'oxbilllname\')}],'.PHP_EOL.PHP_EOL.'Your order [{$order->getFieldData(\'oxordernr\')}] has just been shipped. [{if $order->getFieldData(\'oxtrackcode\')}]The tracking code for this is: [{$order->getFieldData(\'oxtrackcode\')}].[{/if}]'.PHP_EOL.PHP_EOL.'Your team at [{$shop->getFieldData(\'oxname\')}].'),
'oxcatid' => $qb->createNamedParameter('943a9ba3050e78b443c16e043ae60ef3'),
'oxfolder' => $qb->createNamedParameter('')
]);
$qb->execute();
}
/**
* @return ContainerInterface
*/
public function getContainer(): ContainerInterface
protected function getContainer(): ContainerInterface
{
return ContainerFactory::getInstance()->getContainer();
}
/**
* @return Database
*/
protected function getDb(): Database
{
/** @var Database $db */
$db = d3GetOxidDIC()->get('d3ox.linkmobility.'.DatabaseInterface::class.'.assoc');
return $db;
}
/**
* @return Config
*/
protected function getConfig(): Config
{
/** @var Config $config */
$config = d3GetOxidDIC()->get('d3ox.linkmobility.'.Config::class);
return $config;
}
}

View File

@ -38,6 +38,7 @@ class Events
/** @var Actions $actions */
$actions = d3GetOxidDIC()->get(Actions::class);
$actions->setupDatabase();
$actions->checkCmsItems();
$actions->regenerateViews();
}

View File

@ -18,12 +18,11 @@ namespace D3\Linkmobility4OXID\tests\unit\Setup;
use D3\Linkmobility4OXID\Setup\Actions;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\TestingTools\Development\CanAccessRestricted;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Statement;
use Monolog\Logger;
use OxidEsales\Eshop\Application\Model\Article;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
use OxidEsales\Eshop\Core\DbMetaDataHandler;
@ -179,31 +178,7 @@ class ActionsTest extends LMUnitTestCase
->getMock();
$resultStatementMock->method('fetchOne')->willReturn('returnFixture');
/** @var ExpressionBuilder|MockObject $expressionBuilderMock */
$expressionBuilderMock = $this->getMockBuilder(ExpressionBuilder::class)
->disableOriginalConstructor()
->getMock();
/** @var QueryBuilder|MockObject $queryBuilderMock */
$queryBuilderMock = $this->getMockBuilder(QueryBuilder::class)
->disableOriginalConstructor()
->onlyMethods(['execute', 'expr'])
->getMock();
$queryBuilderMock->method('execute')->willReturn($resultStatementMock);
$queryBuilderMock->method('expr')->willReturn($expressionBuilderMock);
/** @var QueryBuilderFactory|MockObject $queryBuilderFactoryMock */
$queryBuilderFactoryMock = $this->getMockBuilder(QueryBuilderFactory::class)
->disableOriginalConstructor()
->onlyMethods(['create'])
->getMock();
$queryBuilderFactoryMock->method('create')->willReturn($queryBuilderMock);
/** @var Container|MockObject $containerMock */
$containerMock = $this->getMockBuilder(Container::class)
->onlyMethods(['get'])
->getMock();
$containerMock->method('get')->willReturn($queryBuilderFactoryMock);
$containerMock = $this->getQueryBuilderResultMock($resultStatementMock);
/** @var Actions|MockObject $sut */
$sut = $this->getMockBuilder(Actions::class)
@ -236,13 +211,13 @@ class ActionsTest extends LMUnitTestCase
$databaseMock->method('quoteIdentifier')->willReturn('foo');
$databaseMock->method('quoteArray')->willReturn('foo');
$databaseMock->method('quote')->willReturn('foo');
d3GetOxidDIC()->set('d3ox.linkmobility.'.DatabaseInterface::class.'.assoc', $databaseMock);
/** @var Actions|MockObject $sut */
$sut = $this->getMockBuilder(Actions::class)
->onlyMethods(['getUniqueFieldTypes'])
->onlyMethods(['getUniqueFieldTypes', 'getDb'])
->getMock();
$sut->method('getUniqueFieldTypes')->willReturn(['foobar', 'LINKMOB', 'barfoo']);
$sut->method('getDb')->willReturn($databaseMock);
$this->callMethod(
$sut,
@ -277,6 +252,143 @@ class ActionsTest extends LMUnitTestCase
);
}
/**
* @test
* @param $missing
* @return void
* @throws ReflectionException
* @dataProvider canCheckCmsItemsDataProvider
* @covers \D3\Linkmobility4OXID\Setup\Actions::checkCmsItems
*/
public function canCheckCmsItems($missing)
{
/** @var Actions|MockObject $sut */
$sut = $this->getMockBuilder(Actions::class)
->onlyMethods(['cmsMissing', 'addCms1Item', 'addCms2Item', 'addCms3Item'])
->getMock();
$sut->expects($this->exactly(3))->method('cmsMissing')->willReturn($missing);
$sut->expects($this->exactly((int) $missing))->method('addCms1Item');
$sut->expects($this->exactly((int) $missing))->method('addCms2Item');
$sut->expects($this->exactly((int) $missing))->method('addCms3Item');
$this->callMethod(
$sut,
'checkCmsItems'
);
}
/**
* @return array
*/
public function canCheckCmsItemsDataProvider(): array
{
return [
'CMS missing' => [true],
'CMS exists' => [false],
];
}
/**
* @test
* @return void
* @throws ReflectionException
* @dataProvider canCmsMissingDataProvider
* @covers \D3\Linkmobility4OXID\Setup\Actions::cmsMissing
*/
public function canCmsMissing($itemCount, $expected)
{
/** @var Statement|MockObject $resultStatementMock */
$resultStatementMock = $this->getMockBuilder(Statement::class)
->disableOriginalConstructor()
->onlyMethods(['fetchOne'])
->getMock();
$resultStatementMock->expects($this->once())->method('fetchOne')->willReturn($itemCount);
$containerMock = $this->getQueryBuilderResultMock($resultStatementMock);
/** @var Actions|MockObject $sut */
$sut = $this->getMockBuilder(Actions::class)
->onlyMethods(['getContainer'])
->getMock();
$sut->method('getContainer')->willReturn($containerMock);
$this->assertSame(
$expected,
$this->callMethod(
$sut,
'cmsMissing',
['checkIdent']
)
);
}
/**
* @return array[]
*/
public function canCmsMissingDataProvider(): array
{
return [
'found one' => [1, false],
'found none' => [0, true]
];
}
/**
* @test
* @param $method
* @return void
* @throws ReflectionException
* @dataProvider canAddCmsItemDataProvider
* @covers \D3\Linkmobility4OXID\Setup\Actions::addCms1Item
* @covers \D3\Linkmobility4OXID\Setup\Actions::addCms2Item
* @covers \D3\Linkmobility4OXID\Setup\Actions::addCms3Item
*/
public function canAddCmsItem($method)
{
/** @var QueryBuilder|MockObject $queryBuilderMock */
$queryBuilderMock = $this->getMockBuilder(QueryBuilder::class)
->disableOriginalConstructor()
->onlyMethods(['execute', 'expr'])
->getMock();
$queryBuilderMock->expects($this->once())->method('execute');
/** @var QueryBuilderFactory|MockObject $queryBuilderFactoryMock */
$queryBuilderFactoryMock = $this->getMockBuilder(QueryBuilderFactory::class)
->disableOriginalConstructor()
->onlyMethods(['create'])
->getMock();
$queryBuilderFactoryMock->method('create')->willReturn($queryBuilderMock);
/** @var Container|MockObject $containerMock */
$containerMock = $this->getMockBuilder(Container::class)
->onlyMethods(['get'])
->getMock();
$containerMock->method('get')->willReturn($queryBuilderFactoryMock);
/** @var Actions|MockObject $sut */
$sut = $this->getMockBuilder(Actions::class)
->onlyMethods(['getContainer'])
->getMock();
$sut->method('getContainer')->willReturn($containerMock);
$this->callMethod(
$sut,
$method
);
}
/**
* @return string[]
*/
public function canAddCmsItemDataProvider(): array
{
return [
['addCms1Item'],
['addCms2Item'],
['addCms3Item'],
];
}
/**
* @test
* @return void
@ -296,4 +408,79 @@ class ActionsTest extends LMUnitTestCase
)
);
}
/**
* @param MockObject $resultStatementMock
* @return MockObject|Container
*/
protected function getQueryBuilderResultMock(MockObject $resultStatementMock)
{
/** @var ExpressionBuilder|MockObject $expressionBuilderMock */
$expressionBuilderMock = $this->getMockBuilder(ExpressionBuilder::class)
->disableOriginalConstructor()
->getMock();
/** @var QueryBuilder|MockObject $queryBuilderMock */
$queryBuilderMock = $this->getMockBuilder(QueryBuilder::class)
->disableOriginalConstructor()
->onlyMethods(['execute', 'expr'])
->getMock();
$queryBuilderMock->method('execute')->willReturn($resultStatementMock);
$queryBuilderMock->method('expr')->willReturn($expressionBuilderMock);
/** @var QueryBuilderFactory|MockObject $queryBuilderFactoryMock */
$queryBuilderFactoryMock = $this->getMockBuilder(QueryBuilderFactory::class)
->disableOriginalConstructor()
->onlyMethods(['create'])
->getMock();
$queryBuilderFactoryMock->method('create')->willReturn($queryBuilderMock);
/** @var Container|MockObject $containerMock */
$containerMock = $this->getMockBuilder(Container::class)
->onlyMethods(['get'])
->getMock();
$containerMock->method('get')->willReturn($queryBuilderFactoryMock);
return $containerMock;
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Setup\Actions::getDb
*/
public function canGetDb()
{
/** @var Actions $sut */
$sut = oxNew(Actions::class);
$this->assertInstanceOf(
DatabaseInterface::class,
$this->callMethod(
$sut,
'getDb'
)
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Setup\Actions::getConfig
*/
public function canGetConfig()
{
/** @var Actions $sut */
$sut = oxNew(Actions::class);
$this->assertInstanceOf(
Config::class,
$this->callMethod(
$sut,
'getConfig'
)
);
}
}