Skip to content

Commit 37a9929

Browse files
committed
Resolve A "500 (Internal Server Error)" appears in Developer Console if Delete the image that is added to Page Content issue25893
1 parent 57a2aad commit 37a9929

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
8+
declare(strict_types=1);
9+
710
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg;
811

912
use Magento\Backend\App\Action;
@@ -13,6 +16,8 @@
1316

1417
/**
1518
* Process template text for wysiwyg editor.
19+
*
20+
* Class Directive
1621
*/
1722
class Directive extends Action implements HttpGetActionInterface
1823
{
@@ -73,10 +78,14 @@ public function execute()
7378
/** @var Config $config */
7479
$config = $this->_objectManager->get(Config::class);
7580
$imagePath = $config->getSkinImagePlaceholderPath();
76-
$image->open($imagePath);
77-
$resultRaw->setHeader('Content-Type', $image->getMimeType());
78-
$resultRaw->setContents($image->getImage());
79-
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
81+
try {
82+
$image->open($imagePath);
83+
$resultRaw->setHeader('Content-Type', $image->getMimeType());
84+
$resultRaw->setContents($image->getImage());
85+
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
86+
} catch (\Exception $e) {
87+
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
88+
}
8089
}
8190
return $resultRaw;
8291
}

app/code/Magento/Cms/Test/Unit/Controller/Adminhtml/Wysiwyg/DirectiveTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,33 @@ protected function prepareExecuteTest()
274274
->method('create')
275275
->willReturn($this->imageAdapterMock);
276276
}
277+
278+
/**
279+
* Test Execute With Deleted Image
280+
*
281+
* @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute
282+
*/
283+
public function testExecuteWithDeletedImage()
284+
{
285+
$exception = new \Exception('epic fail');
286+
$placeholderPath = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
287+
$this->prepareExecuteTest();
288+
289+
$this->imageAdapterMock->expects($this->at(0))
290+
->method('open')
291+
->with(self::IMAGE_PATH)
292+
->willThrowException($exception);
293+
$this->wysiwygConfigMock->expects($this->once())
294+
->method('getSkinImagePlaceholderPath')
295+
->willReturn($placeholderPath);
296+
$this->imageAdapterMock->expects($this->at(1))
297+
->method('open')
298+
->willThrowException($exception);
299+
300+
$this->loggerMock->expects($this->once())
301+
->method('critical')
302+
->with($exception);
303+
304+
$this->wysiwygDirective->execute();
305+
}
277306
}

0 commit comments

Comments
 (0)