Skip to content

Commit

Permalink
Fixed error message for import (#898)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcop1 authored Oct 21, 2024
1 parent b71636a commit 9f4a052
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 17 additions & 13 deletions src/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,19 +576,23 @@ public function exportConfiguration(Request $request, ExportService $exportServi
*/
public function importConfiguration(Request $request, ImportService $importService): JsonResponse
{
$this->checkPermission(self::CONFIG_NAME);
$json = file_get_contents($_FILES['Filedata']['tmp_name']);
$configuration = $importService->importConfigurationJson($json);

$response = $this->jsonResponse([
'success' => true,
'type' => $configuration->getType(),
'name' => $configuration->getName(),
]);
// set content-type to text/html, otherwise (when application/json is sent) chrome will complain in
// Ext.form.Action.Submit and mark the submission as failed
$response->headers->set('Content-Type', 'text/html');
try {
$this->checkPermission(self::CONFIG_NAME);
$json = file_get_contents($_FILES['Filedata']['tmp_name']);
$configuration = $importService->importConfigurationJson($json);

return $response;
$response = $this->jsonResponse([
'success' => true,
'type' => $configuration->getType(),
'name' => $configuration->getName(),
]);
// set content-type to text/html, otherwise (when application/json is sent) chrome will complain in
// Ext.form.Action.Submit and mark the submission as failed
$response->headers->set('Content-Type', 'text/html');

return $response;
} catch (\Exception $e) {
return $this->jsonResponse(['success' => false, 'message' => $e->getMessage()]);
}
}
}
6 changes: 4 additions & 2 deletions src/Resources/public/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ pimcore.plugin.datahub.config = Class.create({
this.refreshTree();

}.bind(this),
function () {
Ext.MessageBox.alert(t("error"), t("error"));
function (response) {
response = response.response;
const data = Ext.decode(response.responseText);
Ext.MessageBox.alert(t("error"), data.message);
}
);
}.bind(this)
Expand Down

0 comments on commit 9f4a052

Please sign in to comment.