Skip to content

Commit

Permalink
Added delimiter configuration to the process.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuba Płaskonka committed Mar 10, 2020
1 parent a967781 commit 8c95edf
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/ScheduledExportBundle/Command/ScheduledExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ protected function configure()
'',
InputOption::VALUE_OPTIONAL,
'Export only changes from last export'
);
)
->addOption(
'delimiter',
'',
InputOption::VALUE_OPTIONAL,
'Set your own delimiter'
)
;
}

/**
Expand All @@ -103,7 +110,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
(string) $input->getOption("filename"),
(string) $input->getOption("timestamp"),
(string) $input->getOption("only-changes"),
(string) $input->getOption("format")
(string) $input->getOption("format"),
(string) $input->getOption("delimiter")
);

$export->export();
Expand Down
21 changes: 18 additions & 3 deletions src/ScheduledExportBundle/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class Export
{
const SETTINGS = '{"enableInheritance":true,"delimiter":";"}';
const SETTINGS = '{"enableInheritance":true,"delimiter":"%delimiter%"}';

const WS_NAME = 'Last_Scheduled_Export_Date';

Expand All @@ -40,6 +40,7 @@ class Export
private $timestampFormat;
private $importStartTimestamp;
private $container;
private $delimiter;

/** @var bool $onlyChanges */
private $onlyChanges;
Expand Down Expand Up @@ -68,7 +69,8 @@ public function __construct(
string $fileName = null,
string $timestamp = "0",
string $onlyChanges = "0",
string $timestampFormat = ""
string $timestampFormat = "",
string $delimiter = null
) {
$this->setTimestamp($timestamp);
$this->setGridConfig($gridConfig);
Expand All @@ -79,6 +81,7 @@ public function __construct(
$this->setTimestampFormat($timestampFormat);
$this->setFilename(\Pimcore\File::getValidFilename($fileName));
$this->setContainer($container);
$this->setDelimiter($delimiter);
}

public function getExportSetting() : WebsiteSetting
Expand Down Expand Up @@ -156,6 +159,18 @@ public function setAssetFolder($assetFolder): void
$this->assetFolder = $assetFolder;
}

/**
* @param string|null $delimiter
* @return void
*/
public function setDelimiter($delimiter): void
{
if (!$delimiter) {
$delimiter = ";";
}
$this->delimiter = $delimiter;
}

/**
* @param string|null $condition
* @return void
Expand Down Expand Up @@ -238,7 +253,7 @@ protected function prepareRequest(): Request

$request->request->set('fileHandle', $this->fileName);
$request->request->set('ids', $this->prepareObjectIds());
$request->request->set('settings', self::SETTINGS);
$request->request->set('settings', str_replace("%delimiter%", $this->delimiter, self::SETTINGS));
$request->request->set('classId', $this->gridConfig->classId);
$request->request->set('initial', '1');
$request->request->set('fields', $this->prepareFields());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('asset_folder', TextType::class)
->add('asset_filename', TextType::class)
->add('condition', TextType::class)
->add('delimiter', TextType::class)
->add('add_timestamp', CheckboxType::class)
->add('timestamp', TextType::class)
->add('only_changes', CheckboxType::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ public function run(ExecutableInterface $executable, ?array $params = null)
$settings = $executable->getSettings();

$command = sprintf(
'scheduled-export:start -g %s -f %s -a %s --filename %s -t %s --format %s -c %s --only-changes %s',
'scheduled-export:start -g %s -f %s -a %s --filename %s'
. ' -t %s --format %s -c %s --only-changes %s --delimiter %s',
escapeshellarg($settings['grid_config']),
escapeshellarg($settings['objects_folder']),
escapeshellarg($settings['asset_folder']),
escapeshellarg($settings['asset_filename']),
escapeshellarg($settings['add_timestamp']),
escapeshellarg($settings['timestamp']),
escapeshellarg($settings['condition']),
escapeshellarg($settings['only_changes'])
escapeshellarg($settings['only_changes']),
escapeshellarg($settings['delimiter'])
);

$command = PIMCORE_PROJECT_ROOT . "/bin/console " . $command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ document.addEventListener('processmanager.ready', function() {
name: 'asset_filename',
value: this.data.settings.asset_filename,
emptyText: t('scheduledexport_asset_filename_example')
}, {
xtype: 'textfield',
fieldLabel: t('scheduledexport_delimiter'),
name: 'delimiter',
value: this.data.settings.delimiter,
emptyText: t('scheduledexport_delimiter_example')
}, {
xtype: 'textfield',
fieldLabel: t('scheduledexport_condition'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ scheduledexport_asset_filename: "Export filename:"
scheduledexport_add_timestamp: "Append timestamp to the filename"
scheduledexport_only_changes: "Export only changes from last export"
scheduledexport_timestamp: "Timestamp format (<a href='https://www.php.net/manual/en/function.strftime.php' target='_blank'>more info</a>)"
scheduledexport_timestamp_example: "-%s"
scheduledexport_timestamp_example: "-%s"
scheduledexport_delimiter_example: ";"
scheduledexport_delimiter: "Delimiter"

0 comments on commit 8c95edf

Please sign in to comment.