-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Selector for JSON Payload #437
base: 1.x
Are you sure you want to change the base?
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,14 @@ | |
|
||
namespace Pimcore\Bundle\DataImporterBundle\DataSource\Interpreter; | ||
|
||
use JmesPath\Env as JmesPath; | ||
use Pimcore\Bundle\DataImporterBundle\PimcoreDataImporterBundle; | ||
use Pimcore\Bundle\DataImporterBundle\Preview\Model\PreviewData; | ||
|
||
class JsonFileInterpreter extends AbstractInterpreter | ||
{ | ||
protected string $path; | ||
|
||
/** | ||
* @var array|null | ||
*/ | ||
|
@@ -32,13 +35,17 @@ class JsonFileInterpreter extends AbstractInterpreter | |
|
||
protected function loadData(string $path): array | ||
{ | ||
if ($this->cachedFilePath === $path && !empty($this->cachedContent)) { | ||
if ($this->cachedFilePath !== $path || empty($this->cachedContent)) { | ||
$content = file_get_contents($path); | ||
|
||
return json_decode($this->prepareContent($content), true); | ||
$data = json_decode($this->prepareContent($content), true); | ||
} else { | ||
return $this->cachedContent; | ||
$data = $this->cachedContent; | ||
} | ||
|
||
if (!empty($this->path)) { | ||
return $this->getValueFromPath($data); | ||
} | ||
return $data; | ||
} | ||
|
||
protected function doInterpretFileAndCallProcessRow(string $path): void | ||
|
@@ -52,7 +59,7 @@ protected function doInterpretFileAndCallProcessRow(string $path): void | |
|
||
public function setSettings(array $settings): void | ||
{ | ||
//nothing to do | ||
$this->path = $settings['path']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to do any validation here that the path passed in is a valid JmesPath? |
||
} | ||
|
||
/** | ||
|
@@ -132,4 +139,12 @@ public function previewData(string $path, int $recordNumber = 0, array $mappedCo | |
|
||
return new PreviewData($columns, $previewData, $readRecordNumber, $mappedColumns); | ||
} | ||
|
||
/** | ||
* Returns a value from the specified path in a nested array `$data`. | ||
*/ | ||
private function getValueFromPath(array $data): mixed | ||
{ | ||
return JmesPath::search($this->path, $data); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,12 @@ pimcore.plugin.pimcoreDataImporterBundle.configuration.components.interpreter.js | |
}, | ||
border: false, | ||
items: [ | ||
{ | ||
xtype: 'textfield', | ||
fieldLabel: t('plugin_pimcore_datahub_data_importer_configpanel_json_path'), | ||
name: this.dataNamePrefix + 'path', | ||
value: this.data.path || '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do I need anything else here, such as:
|
||
} | ||
] | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ plugin_pimcore_datahub_data_importer_configpanel_csv_escape: Escape | |
plugin_pimcore_datahub_data_importer_configpanel_xlsx_sheet: Sheet | ||
plugin_pimcore_datahub_data_importer_configpanel_xml_xpath: XPath | ||
plugin_pimcore_datahub_data_importer_configpanel_xml_schema: Schema | ||
plugin_pimcore_datahub_data_importer_configpanel_json_path: Path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have seen the name "path" and "expression" used. do we have a preference? |
||
plugin_pimcore_datahub_data_importer_configpanel_import_settings: Import Settings | ||
plugin_pimcore_datahub_data_importer_configpanel_import_preview: Import Preview | ||
plugin_pimcore_datahub_data_importer_configpanel_preview_data_clone: Copy preview data from data source for preview. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe this logic was wrong before. See fix for Xml: #438