@@ -76,7 +76,7 @@ private function getMediaDirectory()
76
76
private function getBaseDirectory ()
77
77
{
78
78
if (!isset ($ this ->baseDirectory )) {
79
- $ this ->baseDirectory = $ this ->filesystem ->getDirectoryRead (DirectoryList::PUB );
79
+ $ this ->baseDirectory = $ this ->filesystem ->getDirectoryRead (DirectoryList::ROOT );
80
80
}
81
81
82
82
return $ this ->baseDirectory ;
@@ -135,7 +135,7 @@ private function getFilePath($fileName)
135
135
{
136
136
$ filePath = ltrim ($ fileName , '/ ' );
137
137
138
- $ mediaDirectoryRelativeSubpath = $ this ->getMediaDirectoryPathRelativeToBaseDirectoryPath ();
138
+ $ mediaDirectoryRelativeSubpath = $ this ->getMediaDirectoryPathRelativeToBaseDirectoryPath ($ filePath );
139
139
$ isFileNameBeginsWithMediaDirectoryPath = $ this ->isBeginsWithMediaDirectoryPath ($ fileName );
140
140
141
141
// 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)
160
160
{
161
161
$ filePath = ltrim ($ fileName , '/ ' );
162
162
163
- $ mediaDirectoryRelativeSubpath = $ this ->getMediaDirectoryPathRelativeToBaseDirectoryPath ();
163
+ $ mediaDirectoryRelativeSubpath = $ this ->getMediaDirectoryPathRelativeToBaseDirectoryPath ($ filePath );
164
164
$ isFileNameBeginsWithMediaDirectoryPath = strpos ($ filePath , $ mediaDirectoryRelativeSubpath ) === 0 ;
165
165
166
166
return $ isFileNameBeginsWithMediaDirectoryPath ;
@@ -169,14 +169,20 @@ public function isBeginsWithMediaDirectoryPath($fileName)
169
169
/**
170
170
* Get media directory subpath relative to base directory path
171
171
*
172
+ * @param string $filePath
172
173
* @return string
173
174
*/
174
- private function getMediaDirectoryPathRelativeToBaseDirectoryPath ()
175
+ private function getMediaDirectoryPathRelativeToBaseDirectoryPath (string $ filePath = '' )
175
176
{
176
177
$ baseDirectoryPath = $ this ->getBaseDirectory ()->getAbsolutePath ();
177
178
$ mediaDirectoryPath = $ this ->getMediaDirectory ()->getAbsolutePath ();
178
179
179
180
$ 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
+ }
180
186
181
187
return $ mediaDirectoryRelativeSubpath ;
182
188
}
0 commit comments