Skip to content

Commit

Permalink
Merge branch 'b-7.0.x' into b-7.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
angel-dimitrov committed Jun 7, 2024
2 parents 60bfd00 + d2e4429 commit 9676a6f
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 125 deletions.
1 change: 1 addition & 0 deletions .github/workflows/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs_on: '"ubuntu-latest"'
defaults: 'v4'
plan_folder: '.github/oxid-esales'

secrets:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
Expand Down
40 changes: 12 additions & 28 deletions Application/Export/Cli/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ class ExportCommand
*/
private $config;

/**
* @var string
*/
private $eShopSourcePath;

/**
* @var Exporter
*/
Expand All @@ -37,12 +32,10 @@ class ExportCommand
/**
* @param array $cliArguments
* @param Factory $factory
* @param string $eShopSourcePath
*/
public function __construct($cliArguments, $factory, string $eShopSourcePath)
public function __construct($cliArguments, $factory)
{
Registry::getConfig()->setAdminMode(true);
$this->eShopSourcePath = $eShopSourcePath;
$this->config = $this->getConfigurationParameters($cliArguments);
Registry::getConfig()->setShopId($this->config['shopId']);

Expand Down Expand Up @@ -77,44 +70,35 @@ public function export()
0
);
} catch (ExporterException $exception) {
exit($exception->getMessage());
throw new \Exception($exception->getMessage());
}

print("Export completed.\n");
exit(0);
return "Export completed.\n";
}

/**
* @param array $cliArguments
* @param string $cliArguments
*
* @return string
*/
private function getConfigFile($cliArguments)
{
$configFile = Path::join($this->eShopSourcePath, 'modules/oe/personalization/config/default_params.php');
array_shift($cliArguments);
if (isset($cliArguments[0])) {
if ($cliArguments[0] === '--config') {
$configFile = (isset($cliArguments[1])) ? $cliArguments[1] : '';
if (!file_exists($configFile)) {
exit('File does not exist: ' . $configFile . "\n");
}
} else {
$message = 'Unknown command: ' . $cliArguments[0] .
'. If you want to override the configuration file for the export, please, use the "--config" command' .
"\n";
exit($message);
$configFile = Path::join(__DIR__, '../../../config/default_params.php');
if (isset($cliArguments)) {
$configFile = $cliArguments;
if (!file_exists($configFile)) {
throw new \Exception('File does not exist: ' . $configFile . "\n");
}
}

if (!file_exists($configFile)) {
exit('Config file is missing: ' . $configFile . "\n");
throw new \Exception('Config file is missing: ' . $configFile . "\n");
}
return $configFile;
}

/**
* @param array $argv
* @param string $argv
*
* @return array
*/
Expand All @@ -125,7 +109,7 @@ private function getConfigurationParameters($argv)
$config = include $configFile;

if (!is_array($config)) {
exit('Config file has wrong format.'."\n");
throw new \Exception('Config file has wrong format.'."\n");
}

return $config;
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

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

## [3.0.0] - 2024-01-19

Expand Down
41 changes: 41 additions & 0 deletions Command/ExportDataCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidEsales\PersonalizationModule\Command;

use OxidEsales\PersonalizationModule\Application\Export\Cli\ExportCommand;
use OxidEsales\PersonalizationModule\Application\Factory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ExportDataCommand extends Command
{
protected function configure()
{
$this
->setName('oe:personalization:export')
->setDescription('Export data')
->addOption('config', null, InputOption::VALUE_OPTIONAL, 'Path to configuration file');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$configFile = $input->hasOption('config') ? $input->getOption('config') : null;
$exporter = oxNew(ExportCommand::class, $configFile, oxNew(Factory::class));
try {
$message = $exporter->export();
} catch (\Exception $exception) {
$output->writeln('<fg=red>' . $exception->getMessage() . '</>');
return Command::FAILURE;
}

$output->writeln('<fg=green>' . $message . '</>');

return Command::SUCCESS;
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ There are 2 ways of exporting data:

To export data via CLI execute command:
```bash
vendor/bin/oe-personalization-data-feed
bin/oe-console oe:personalization:export
```
or if there is a need to customize configuration parameters:
```bash
vendor/bin/oe-personalization-data-feed --config /path/to/your/config/file.php
bin/oe-console oe:personalization:export --config /path/to/your/config/file.php
```

## Bugs and Issues
Expand Down
5 changes: 5 additions & 0 deletions Service/ModuleSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,9 @@ public function getExportPath(): string
{
return $this->moduleSettingService->getString(self::EXPORT_PATH, Module::MODULE_ID);
}

public function saveExportPath(string $path): void
{
$this->moduleSettingService->saveString(self::EXPORT_PATH, $path, Module::MODULE_ID);
}
}
39 changes: 0 additions & 39 deletions bin/oe-personalization-data-feed

This file was deleted.

7 changes: 6 additions & 1 deletion services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ services:
OxidEsales\PersonalizationModule\Twig\Extensions\Tracker:
decorates: OxidEsales\Twig\Extensions\InsertTrackerExtension
decoration_on_invalid: ignore
arguments: ['@.inner']
arguments: ['@.inner']

oxid_esales.personalization.command.export_data:
class: OxidEsales\PersonalizationModule\Command\ExportDataCommand
tags:
- { name: 'console.command', command: 'oe:personalization:export' }
6 changes: 5 additions & 1 deletion tests/Integration/Application/ExportViaAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

use OxidEsales\Eshop\Core\Registry;
use OxidEsales\PersonalizationModule\Application\Controller\Admin\Tab\ExportTabController;
use OxidEsales\PersonalizationModule\Service\ModuleSettings;
use OxidEsales\PersonalizationModule\Traits\ServiceContainer;

class ExportViaAdminTest extends AbstractExportDataInCSV
{
use ServiceContainer;

/**
* @inheritdoc
*/
Expand All @@ -22,7 +26,7 @@ protected function setParametersForExport($exportParentProducts, $exportVars, $c
$_POST['blExportVars'] = $exportVars;
$_POST['iStart'] = 1;

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

protected function runExport()
Expand Down
Loading

0 comments on commit 9676a6f

Please sign in to comment.