Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 31f1f09

Browse files
committedJun 4, 2024·
OXDEV-8388 Fix export command
1 parent a255872 commit 31f1f09

File tree

6 files changed

+61
-71
lines changed

6 files changed

+61
-71
lines changed
 

‎Application/Export/Cli/ExportCommand.php

+8-23
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ class ExportCommand
2424
*/
2525
private $config;
2626

27-
/**
28-
* @var string
29-
*/
30-
private $eShopSourcePath;
31-
3227
/**
3328
* @var Exporter
3429
*/
@@ -37,12 +32,10 @@ class ExportCommand
3732
/**
3833
* @param array $cliArguments
3934
* @param Factory $factory
40-
* @param string $eShopSourcePath
4135
*/
42-
public function __construct($cliArguments, $factory, string $eShopSourcePath)
36+
public function __construct($cliArguments, $factory)
4337
{
4438
Registry::getConfig()->setAdminMode(true);
45-
$this->eShopSourcePath = $eShopSourcePath;
4639
$this->config = $this->getConfigurationParameters($cliArguments);
4740
Registry::getConfig()->setShopId($this->config['shopId']);
4841

@@ -85,25 +78,17 @@ public function export()
8578
}
8679

8780
/**
88-
* @param array $cliArguments
81+
* @param string $cliArguments
8982
*
9083
* @return string
9184
*/
9285
private function getConfigFile($cliArguments)
9386
{
94-
$configFile = Path::join($this->eShopSourcePath, 'modules/oe/personalization/config/default_params.php');
95-
array_shift($cliArguments);
96-
if (isset($cliArguments[0])) {
97-
if ($cliArguments[0] === '--config') {
98-
$configFile = (isset($cliArguments[1])) ? $cliArguments[1] : '';
99-
if (!file_exists($configFile)) {
100-
exit('File does not exist: ' . $configFile . "\n");
101-
}
102-
} else {
103-
$message = 'Unknown command: ' . $cliArguments[0] .
104-
'. If you want to override the configuration file for the export, please, use the "--config" command' .
105-
"\n";
106-
exit($message);
87+
$configFile = Path::join(__DIR__, '../../../config/default_params.php');
88+
if (isset($cliArguments)) {
89+
$configFile = $cliArguments;
90+
if (!file_exists($configFile)) {
91+
exit('File does not exist: ' . $configFile . "\n");
10792
}
10893
}
10994

@@ -114,7 +99,7 @@ private function getConfigFile($cliArguments)
11499
}
115100

116101
/**
117-
* @param array $argv
102+
* @param string $argv
118103
*
119104
* @return array
120105
*/

‎Command/ExportDataCommand.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © OXID eSales AG. All rights reserved.
4+
* See LICENSE file for license details.
5+
*/
6+
7+
namespace OxidEsales\PersonalizationModule\Command;
8+
9+
use OxidEsales\PersonalizationModule\Application\Export\Cli\ExportCommand;
10+
use OxidEsales\PersonalizationModule\Application\Factory;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Input\InputOption;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
class ExportDataCommand extends Command
17+
{
18+
19+
protected function configure()
20+
{
21+
$this
22+
->setName('oe:personalization:export')
23+
->setDescription('Export data')
24+
->addOption('config', null, InputOption::VALUE_OPTIONAL, 'Path to configuration file');
25+
}
26+
27+
protected function execute(InputInterface $input, OutputInterface $output)
28+
{
29+
$configFile = $input->hasOption('config') ? $input->getOption('config') : null;
30+
$exporter = oxNew(ExportCommand::class, $configFile, oxNew(Factory::class));
31+
$exporter->export();
32+
33+
return Command::SUCCESS;
34+
}
35+
}

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ There are 2 ways of exporting data:
8181

8282
To export data via CLI execute command:
8383
```bash
84-
vendor/bin/oe-personalization-data-feed
84+
bin/oe-console oe:personalization:export
8585
```
8686
or if there is a need to customize configuration parameters:
8787
```bash
88-
vendor/bin/oe-personalization-data-feed --config /path/to/your/config/file.php
88+
bin/oe-console oe:personalization:export --config /path/to/your/config/file.php
8989
```
9090

9191
## Bugs and Issues

‎bin/oe-personalization-data-feed

-38
This file was deleted.

‎services.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ services:
1212
OxidEsales\PersonalizationModule\Twig\Extensions\Tracker:
1313
decorates: OxidEsales\Twig\Extensions\InsertTrackerExtension
1414
decoration_on_invalid: ignore
15-
arguments: ['@.inner']
15+
arguments: ['@.inner']
16+
17+
oxid_esales.personalization.command.export_data:
18+
class: OxidEsales\PersonalizationModule\Command\ExportDataCommand
19+
tags:
20+
- { name: 'console.command', command: 'oe:personalization:export' }

‎tests/Integration/Application/ExportViaCmdTest.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace OxidEsales\PersonalizationModule\Tests\Integration\Application;
88

99
use OxidEsales\Eshop\Core\Registry;
10+
use OxidEsales\PersonalizationModule\Command\ExportDataCommand;
11+
use Symfony\Component\Console\Tester\CommandTester;
1012

1113
class ExportViaCmdTest extends AbstractExportDataInCSV
1214
{
@@ -57,14 +59,15 @@ protected function setParametersForExport($exportParentProducts, $exportVars, $c
5759

5860
protected function runExport($configFile = null)
5961
{
60-
$addArguments = ($this->configFile ) ? ' --config ' . escapeshellarg($this->configFile) : '';
61-
$feedFile = VENDOR_PATH. '/bin/oe-personalization-data-feed';
62-
exec($this->phpBin . ' ' . escapeshellarg($feedFile) . $addArguments, $returnOutput);
63-
$isFound = false;
64-
if (array_search('Export completed.', $returnOutput) !== false) {
65-
$isFound = true;
62+
$command = new ExportDataCommand();
63+
$commandTester = new CommandTester($command);
64+
$commandTester->execute(['--config' => $configFile]);
65+
$exportDir = Registry::getConfig()->getConfigParam('sShopDir') . $this->exportPath;
66+
$success = false;
67+
if (file_exists($exportDir.'/products.csv') && file_exists($exportDir.'/categories.csv')) {
68+
$success = true;
6669
}
67-
$this->assertTrue($isFound);
70+
$this->assertTrue($success);
6871
}
6972

7073
public function testIfWrongCommandWillBeUsed()

0 commit comments

Comments
 (0)
Please sign in to comment.