8
8
9
9
namespace Magento \MediaGallery \Plugin \Wysiwyg \Images ;
10
10
11
- use Magento \Framework \Exception \CouldNotDeleteException ;
12
- use Magento \MediaGalleryApi \Model \Asset \Command \DeleteByDirectoryPathInterface ;
13
- use Magento \MediaGalleryApi \Model \Asset \Command \GetByPathInterface ;
14
- use Magento \MediaGalleryApi \Model \Asset \Command \DeleteByPathInterface ;
11
+ use Magento \MediaGalleryApi \Api \DeleteAssetsByPathsInterface ;
15
12
use Magento \Cms \Model \Wysiwyg \Images \Storage as StorageSubject ;
16
13
use Magento \Framework \App \Filesystem \DirectoryList ;
17
14
use Magento \Framework \Filesystem ;
18
15
use Psr \Log \LoggerInterface ;
19
- use Magento \Framework \Exception \ValidatorException ;
20
16
21
17
/**
22
18
* Ensures that metadata is removed from the database when a file is deleted and it is an image
23
19
*/
24
20
class Storage
25
21
{
26
22
/**
27
- * @var GetByPathInterface
28
- */
29
- private $ getMediaAssetByPath ;
30
-
31
- /**
32
- * @var DeleteByPathInterface
23
+ * @var DeleteAssetsByPathsInterface
33
24
*/
34
25
private $ deleteMediaAssetByPath ;
35
26
36
- /**
37
- * @var DeleteByDirectoryPathInterface
38
- */
39
- private $ deleteMediaAssetByDirectoryPath ;
40
-
41
27
/**
42
28
* @var Filesystem
43
29
*/
@@ -51,22 +37,16 @@ class Storage
51
37
/**
52
38
* Storage constructor.
53
39
*
54
- * @param GetByPathInterface $getMediaAssetByPath
55
- * @param DeleteByPathInterface $deleteMediaAssetByPath
56
- * @param DeleteByDirectoryPathInterface $deleteByDirectoryPath
40
+ * @param DeleteAssetsByPathsInterface $deleteMediaAssetByPath
57
41
* @param Filesystem $filesystem
58
42
* @param LoggerInterface $logger
59
43
*/
60
44
public function __construct (
61
- GetByPathInterface $ getMediaAssetByPath ,
62
- DeleteByPathInterface $ deleteMediaAssetByPath ,
63
- DeleteByDirectoryPathInterface $ deleteByDirectoryPath ,
45
+ DeleteAssetsByPathsInterface $ deleteMediaAssetByPath ,
64
46
Filesystem $ filesystem ,
65
47
LoggerInterface $ logger
66
48
) {
67
- $ this ->getMediaAssetByPath = $ getMediaAssetByPath ;
68
49
$ this ->deleteMediaAssetByPath = $ deleteMediaAssetByPath ;
69
- $ this ->deleteMediaAssetByDirectoryPath = $ deleteByDirectoryPath ;
70
50
$ this ->filesystem = $ filesystem ;
71
51
$ this ->logger = $ logger ;
72
52
}
@@ -94,7 +74,7 @@ public function afterDeleteFile(StorageSubject $subject, StorageSubject $result,
94
74
}
95
75
96
76
try {
97
- $ this ->deleteMediaAssetByPath ->execute ($ relativePath );
77
+ $ this ->deleteMediaAssetByPath ->execute ([ $ relativePath] );
98
78
} catch (\Exception $ exception ) {
99
79
$ this ->logger ->critical ($ exception );
100
80
}
@@ -120,8 +100,12 @@ public function afterDeleteDirectory(StorageSubject $subject, $result, $path)
120
100
}
121
101
122
102
try {
123
- $ this ->deleteMediaAssetByDirectoryPath ->execute ($ this ->getMediaDirectoryRelativePath ($ path ));
124
- } catch (ValidatorException $ exception ) {
103
+ $ this ->deleteMediaAssetByPath ->execute (
104
+ [
105
+ $ this ->filesystem ->getDirectoryRead (DirectoryList::MEDIA )->getRelativePath ($ path )
106
+ ]
107
+ );
108
+ } catch (\Exception $ exception ) {
125
109
$ this ->logger ->critical ($ exception );
126
110
}
127
111
@@ -136,6 +120,8 @@ public function afterDeleteDirectory(StorageSubject $subject, $result, $path)
136
120
*/
137
121
private function getMediaDirectoryRelativePath (string $ path ): string
138
122
{
139
- return $ this ->filesystem ->getDirectoryRead (DirectoryList::MEDIA )->getRelativePath ($ path );
123
+ $ relativePath = $ this ->filesystem ->getDirectoryRead (DirectoryList::MEDIA )->getRelativePath ($ path );
124
+
125
+ return ($ relativePath && false === strpos ($ relativePath , '/ ' )) ? '/ ' . $ relativePath : $ relativePath ;
140
126
}
141
127
}
0 commit comments