1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2019 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
-
7
6
declare (strict_types=1 );
8
7
9
8
namespace Magento \PageBuilder \Model ;
14
13
use Magento \Framework \Exception \CouldNotSaveException ;
15
14
use Magento \Framework \Exception \NoSuchEntityException ;
16
15
use Magento \Framework \Filesystem ;
16
+ use Magento \Framework \Image \Factory ;
17
17
use Magento \PageBuilder \Api \Data \TemplateInterface ;
18
18
use Magento \PageBuilder \Api \Data \TemplateSearchResultsInterfaceFactory ;
19
19
use Magento \PageBuilder \Api \TemplateRepositoryInterface ;
@@ -71,6 +71,7 @@ class TemplateRepository implements TemplateRepositoryInterface
71
71
* @param CollectionProcessorInterface $collectionProcessor
72
72
* @param Filesystem $filesystem
73
73
* @param Database $mediaStorage
74
+ * @param Factory $imageFactory
74
75
*/
75
76
public function __construct (
76
77
ResourceTemplate $ resource ,
@@ -79,7 +80,8 @@ public function __construct(
79
80
TemplateSearchResultsInterfaceFactory $ searchResultsFactory ,
80
81
CollectionProcessorInterface $ collectionProcessor ,
81
82
Filesystem $ filesystem ,
82
- Database $ mediaStorage
83
+ Database $ mediaStorage ,
84
+ private readonly Factory $ imageFactory
83
85
) {
84
86
$ this ->resource = $ resource ;
85
87
$ this ->templateFactory = $ templateFactory ;
@@ -152,10 +154,15 @@ public function delete(TemplateInterface $template) : bool
152
154
$ previewImage = $ template ->getPreviewImage ();
153
155
$ previewThumbImage = $ templateModel ->getPreviewThumbnailImage ();
154
156
157
+ $ this ->imageFactory ->create ($ mediaDir ->getAbsolutePath ().$ previewImage );
158
+
155
159
// Remove the preview image from the media directory
156
160
if ($ mediaDir ->isExist ($ previewImage )) {
157
161
$ mediaDir ->delete ($ previewImage );
158
162
}
163
+
164
+ $ this ->imageFactory ->create ($ mediaDir ->getAbsolutePath ().$ previewThumbImage );
165
+
159
166
if ($ mediaDir ->isExist ($ previewThumbImage )) {
160
167
$ mediaDir ->delete ($ previewThumbImage );
161
168
}
0 commit comments