Skip to content

Commit 9676a6f

Browse files
Merge branch 'b-7.0.x' into b-7.1.x
2 parents 60bfd00 + d2e4429 commit 9676a6f

File tree

11 files changed

+153
-125
lines changed

11 files changed

+153
-125
lines changed

.github/workflows/trigger.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
runs_on: '"ubuntu-latest"'
1414
defaults: 'v4'
1515
plan_folder: '.github/oxid-esales'
16+
1617
secrets:
1718
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
1819
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}

Application/Export/Cli/ExportCommand.php

+12-28
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

@@ -77,44 +70,35 @@ public function export()
7770
0
7871
);
7972
} catch (ExporterException $exception) {
80-
exit($exception->getMessage());
73+
throw new \Exception($exception->getMessage());
8174
}
8275

83-
print("Export completed.\n");
84-
exit(0);
76+
return "Export completed.\n";
8577
}
8678

8779
/**
88-
* @param array $cliArguments
80+
* @param string $cliArguments
8981
*
9082
* @return string
9183
*/
9284
private function getConfigFile($cliArguments)
9385
{
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);
86+
$configFile = Path::join(__DIR__, '../../../config/default_params.php');
87+
if (isset($cliArguments)) {
88+
$configFile = $cliArguments;
89+
if (!file_exists($configFile)) {
90+
throw new \Exception('File does not exist: ' . $configFile . "\n");
10791
}
10892
}
10993

11094
if (!file_exists($configFile)) {
111-
exit('Config file is missing: ' . $configFile . "\n");
95+
throw new \Exception('Config file is missing: ' . $configFile . "\n");
11296
}
11397
return $configFile;
11498
}
11599

116100
/**
117-
* @param array $argv
101+
* @param string $argv
118102
*
119103
* @return array
120104
*/
@@ -125,7 +109,7 @@ private function getConfigurationParameters($argv)
125109
$config = include $configFile;
126110

127111
if (!is_array($config)) {
128-
exit('Config file has wrong format.'."\n");
112+
throw new \Exception('Config file has wrong format.'."\n");
129113
}
130114

131115
return $config;

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616

1717
### Changed
1818
- Convert selenium to codeception tests
19+
- Export command run via `bin/oe-console oe:personalization:export`
1920

2021
## [3.0.0] - 2024-01-19
2122

Command/ExportDataCommand.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
protected function configure()
19+
{
20+
$this
21+
->setName('oe:personalization:export')
22+
->setDescription('Export data')
23+
->addOption('config', null, InputOption::VALUE_OPTIONAL, 'Path to configuration file');
24+
}
25+
26+
protected function execute(InputInterface $input, OutputInterface $output)
27+
{
28+
$configFile = $input->hasOption('config') ? $input->getOption('config') : null;
29+
$exporter = oxNew(ExportCommand::class, $configFile, oxNew(Factory::class));
30+
try {
31+
$message = $exporter->export();
32+
} catch (\Exception $exception) {
33+
$output->writeln('<fg=red>' . $exception->getMessage() . '</>');
34+
return Command::FAILURE;
35+
}
36+
37+
$output->writeln('<fg=green>' . $message . '</>');
38+
39+
return Command::SUCCESS;
40+
}
41+
}

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

Service/ModuleSettings.php

+5
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,9 @@ public function getExportPath(): string
187187
{
188188
return $this->moduleSettingService->getString(self::EXPORT_PATH, Module::MODULE_ID);
189189
}
190+
191+
public function saveExportPath(string $path): void
192+
{
193+
$this->moduleSettingService->saveString(self::EXPORT_PATH, $path, Module::MODULE_ID);
194+
}
190195
}

bin/oe-personalization-data-feed

-39
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/ExportViaAdminTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
use OxidEsales\Eshop\Core\Registry;
1010
use OxidEsales\PersonalizationModule\Application\Controller\Admin\Tab\ExportTabController;
11+
use OxidEsales\PersonalizationModule\Service\ModuleSettings;
12+
use OxidEsales\PersonalizationModule\Traits\ServiceContainer;
1113

1214
class ExportViaAdminTest extends AbstractExportDataInCSV
1315
{
16+
use ServiceContainer;
17+
1418
/**
1519
* @inheritdoc
1620
*/
@@ -22,7 +26,7 @@ protected function setParametersForExport($exportParentProducts, $exportVars, $c
2226
$_POST['blExportVars'] = $exportVars;
2327
$_POST['iStart'] = 1;
2428

25-
Registry::getConfig()->saveShopConfVar('str', 'sOePersonalizationExportPath', $exportPath, 1, 'module:oepersonalization');
29+
$this->getServiceFromContainer(ModuleSettings::class)->saveExportPath($exportPath);
2630
}
2731

2832
protected function runExport()

0 commit comments

Comments
 (0)