Skip to content

Commit 081274a

Browse files
MC-29874: [Magento Cloud] Unable to delete CSV files from Export Grid
1 parent 3009388 commit 081274a

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

app/code/Magento/ImportExport/Ui/Component/Columns/ExportGridActions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public function prepareDataSource(array $dataSource)
5656
$name = $this->getData('name');
5757
if (isset($item['file_name'])) {
5858
$item[$name]['view'] = [
59-
'href' => $this->urlBuilder->getUrl(Download::URL, ['filename' => $item['file_name']]),
59+
'href' => $this->urlBuilder->getUrl(Download::URL, ['_query' => ['filename' => $item['file_name']]]),
6060
'label' => __('Download')
6161
];
6262
$item[$name]['delete'] = [
63-
'href' => $this->urlBuilder->getUrl(Delete::URL, ['filename' => $item['file_name']]),
63+
'href' => $this->urlBuilder->getUrl(Delete::URL, ['_query' => ['filename' => $item['file_name']]]),
6464
'label' => __('Delete'),
6565
'confirm' => [
6666
'title' => __('Delete'),

app/code/Magento/ImportExport/Ui/DataProvider/ExportFileDataProvider.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function getData()
100100
}
101101
$result = [];
102102
foreach ($files as $file) {
103-
$result['items'][]['file_name'] = $this->fileIO->getPathInfo($file)['basename'];
103+
$result['items'][]['file_name'] = $this->getPathToExportFile($this->fileIO->getPathInfo($file));
104104
}
105105

106106
$pageSize = (int) $this->request->getParam('paging')['pageSize'];
@@ -112,6 +112,31 @@ public function getData()
112112
return $result;
113113
}
114114

115+
/**
116+
* Return relative export file path after "var/export"
117+
*
118+
* @param mixed $file
119+
* @return string
120+
*/
121+
private function getPathToExportFile($file): string
122+
{
123+
$directory = $this->fileSystem->getDirectoryRead(DirectoryList::VAR_DIR);
124+
$delimiter = '/';
125+
$cutPath = explode(
126+
$delimiter,
127+
$directory->getAbsolutePath() . 'export'
128+
);
129+
$filePath = explode(
130+
$delimiter,
131+
$file['dirname']
132+
);
133+
134+
return ltrim(
135+
implode($delimiter, array_diff($filePath, $cutPath)) . $delimiter . $file['basename'],
136+
$delimiter
137+
);
138+
}
139+
115140
/**
116141
* Get files from directory path, sort them by date modified and return sorted array of full path to files
117142
*
@@ -127,8 +152,10 @@ private function getExportFiles(string $directoryPath): array
127152
return [];
128153
}
129154
foreach ($files as $filePath) {
130-
//phpcs:ignore Magento2.Functions.DiscouragedFunction
131-
$sortedFiles[filemtime($filePath)] = $filePath;
155+
if ($this->file->isFile($filePath)) {
156+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
157+
$sortedFiles[filemtime($filePath)] = $filePath;
158+
}
132159
}
133160
//sort array elements using key value
134161
krsort($sortedFiles);

0 commit comments

Comments
 (0)