@@ -20,6 +20,7 @@ class DeleteAssetsByPaths implements DeleteAssetsByPathsInterface
20
20
{
21
21
private const TABLE_MEDIA_GALLERY_ASSET = 'media_gallery_asset ' ;
22
22
private const MEDIA_GALLERY_ASSET_PATH = 'path ' ;
23
+ private const MEDIA_GALLERY_ASSET_ID = 'id ' ;
23
24
24
25
/**
25
26
* @var ResourceConnection
@@ -78,13 +79,39 @@ public function execute(array $paths): void
78
79
* Delete assets from database based on the first part (beginning) of the path
79
80
*
80
81
* @param string $path
82
+ * @throws \Zend_Db_Statement_Exception
81
83
*/
82
84
private function deleteAssetsByDirectoryPath (string $ path ): void
85
+ {
86
+ /** @var AdapterInterface $connection */
87
+ $ connection = $ this ->resourceConnection ->getConnection ();
88
+
89
+ $ select = $ connection ->select ()
90
+ ->from ($ this ->resourceConnection ->getTableName (self ::TABLE_MEDIA_GALLERY_ASSET ))
91
+ ->where (self ::MEDIA_GALLERY_ASSET_PATH . ' LIKE ? ' , $ path . '% ' );
92
+
93
+ $ assets = $ connection ->query ($ select )->fetchAll ();
94
+
95
+ // Filter out assets with mixed case that doesn't match the paths
96
+ foreach ($ assets as $ asset ) {
97
+ if (str_starts_with ($ asset [self ::MEDIA_GALLERY_ASSET_PATH ], $ path )) {
98
+ $ this ->deleteAssetById ((int )$ asset [self ::MEDIA_GALLERY_ASSET_ID ]);
99
+ }
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Delete assets from database by asset id
105
+ *
106
+ * @param int $id
107
+ * @return void
108
+ */
109
+ private function deleteAssetById (int $ id ): void
83
110
{
84
111
/** @var AdapterInterface $connection */
85
112
$ connection = $ this ->resourceConnection ->getConnection ();
86
113
$ tableName = $ this ->resourceConnection ->getTableName (self ::TABLE_MEDIA_GALLERY_ASSET );
87
- $ connection ->delete ($ tableName , [self ::MEDIA_GALLERY_ASSET_PATH . ' LIKE ? ' => $ path . ' % ' ]);
114
+ $ connection ->delete ($ tableName , [self ::MEDIA_GALLERY_ASSET_ID . ' = ? ' => $ id ]);
88
115
}
89
116
90
117
/**
0 commit comments