Skip to content

Commit 17ed8d4

Browse files
committed
Revert change from Root to Pub, trim pub directory if filePath not begins with it
1 parent 619475d commit 17ed8d4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

app/code/Magento/Catalog/Model/Category/FileInfo.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private function getMediaDirectory()
7676
private function getBaseDirectory()
7777
{
7878
if (!isset($this->baseDirectory)) {
79-
$this->baseDirectory = $this->filesystem->getDirectoryRead(DirectoryList::PUB);
79+
$this->baseDirectory = $this->filesystem->getDirectoryRead(DirectoryList::ROOT);
8080
}
8181

8282
return $this->baseDirectory;
@@ -135,7 +135,7 @@ private function getFilePath($fileName)
135135
{
136136
$filePath = ltrim($fileName, '/');
137137

138-
$mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath();
138+
$mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath($filePath);
139139
$isFileNameBeginsWithMediaDirectoryPath = $this->isBeginsWithMediaDirectoryPath($fileName);
140140

141141
// if the file is not using a relative path, it resides in the catalog/category media directory
@@ -160,7 +160,7 @@ public function isBeginsWithMediaDirectoryPath($fileName)
160160
{
161161
$filePath = ltrim($fileName, '/');
162162

163-
$mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath();
163+
$mediaDirectoryRelativeSubpath = $this->getMediaDirectoryPathRelativeToBaseDirectoryPath($filePath);
164164
$isFileNameBeginsWithMediaDirectoryPath = strpos($filePath, $mediaDirectoryRelativeSubpath) === 0;
165165

166166
return $isFileNameBeginsWithMediaDirectoryPath;
@@ -169,14 +169,20 @@ public function isBeginsWithMediaDirectoryPath($fileName)
169169
/**
170170
* Get media directory subpath relative to base directory path
171171
*
172+
* @param string $filePath
172173
* @return string
173174
*/
174-
private function getMediaDirectoryPathRelativeToBaseDirectoryPath()
175+
private function getMediaDirectoryPathRelativeToBaseDirectoryPath(string $filePath = '')
175176
{
176177
$baseDirectoryPath = $this->getBaseDirectory()->getAbsolutePath();
177178
$mediaDirectoryPath = $this->getMediaDirectory()->getAbsolutePath();
178179

179180
$mediaDirectoryRelativeSubpath = substr($mediaDirectoryPath, strlen($baseDirectoryPath));
181+
$pubDirectory = 'pub/';
182+
183+
if (strpos($mediaDirectoryRelativeSubpath, $pubDirectory) === 0 && strpos($filePath, $pubDirectory) !== 0) {
184+
$mediaDirectoryRelativeSubpath = substr($mediaDirectoryRelativeSubpath, strlen($pubDirectory));
185+
}
180186

181187
return $mediaDirectoryRelativeSubpath;
182188
}

app/code/Magento/Catalog/Test/Unit/Model/Category/FileInfoTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function setUp()
5757

5858
$this->filesystem->expects($this->any())
5959
->method('getDirectoryRead')
60-
->with(DirectoryList::PUB)
60+
->with(DirectoryList::ROOT)
6161
->willReturn($this->baseDirectory);
6262

6363
$this->mime = $this->getMockBuilder(Mime::class)

0 commit comments

Comments
 (0)