Skip to content

Commit 3f1099e

Browse files
committed
Merge remote-tracking branch 'mainline/2.4.1-develop' into 2.4.1-develop
2 parents 4e085c7 + a6c0df0 commit 3f1099e

File tree

7 files changed

+134
-41
lines changed

7 files changed

+134
-41
lines changed

app/code/Magento/Email/view/adminhtml/templates/template/edit.phtml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
use Magento\Framework\App\TemplateTypesInterface;
88

9+
// phpcs:disable Generic.Files.LineLength.TooLong
10+
911
/** @var $block \Magento\Email\Block\Adminhtml\Template\Edit */
1012
?>
11-
<?php if (!$block->getEditMode()) : ?>
13+
<?php if (!$block->getEditMode()): ?>
1214
<form action="<?= $block->escapeUrl($block->getLoadUrl()) ?>" method="post" id="email_template_load_form">
1315
<?= $block->getBlockHtml('formkey') ?>
1416
<fieldset class="admin__fieldset form-inline">
@@ -17,14 +19,14 @@ use Magento\Framework\App\TemplateTypesInterface;
1719
<label class="admin__field-label" for="template_select"><span><?= $block->escapeHtml(__('Template')) ?></span></label>
1820
<div class="admin__field-control">
1921
<select id="template_select" name="code" class="admin__control-select required-entry">
20-
<?php foreach ($block->getTemplateOptions() as $group => $options) : ?>
21-
<?php if ($group) : ?>
22+
<?php foreach ($block->getTemplateOptions() as $group => $options): ?>
23+
<?php if ($group): ?>
2224
<optgroup label="<?= $block->escapeHtmlAttr($group) ?>">
2325
<?php endif; ?>
24-
<?php foreach ($options as $option) : ?>
26+
<?php foreach ($options as $option): ?>
2527
<option value="<?= $block->escapeHtmlAttr($option['value']) ?>"<?= /* @noEscape */ $block->getOrigTemplateCode() == $option['value'] ? ' selected="selected"' : '' ?>><?= $block->escapeHtml($option['label']) ?></option>
2628
<?php endforeach; ?>
27-
<?php if ($group) : ?>
29+
<?php if ($group): ?>
2830
</optgroup>
2931
<?php endif; ?>
3032
<?php endforeach; ?>
@@ -114,6 +116,8 @@ require([
114116
},
115117

116118
stripTags: function () {
119+
var self = this;
120+
117121
confirm({
118122
content: "<?= $block->escapeJs($block->escapeHtml(__('Are you sure you want to strip tags?'))) ?>",
119123
actions: {
@@ -125,7 +129,7 @@ require([
125129
).stripTags().strip();
126130
$('convert_button_back').show();
127131
$('field_template_styles').hide();
128-
this.typeChange = true;
132+
self.typeChange = true;
129133
return false;
130134
}
131135
}

dev/tests/integration/testsuite/Magento/Framework/Mail/TransportBuilderTest.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use Magento\Email\Model\BackendTemplate;
1111
use Magento\Email\Model\Template;
12+
use Magento\Framework\App\TemplateTypesInterface;
13+
use Magento\Framework\Exception\LocalizedException;
1214
use Magento\Framework\Mail\Template\TransportBuilder;
1315
use Magento\Framework\ObjectManagerInterface;
1416
use Magento\TestFramework\Helper\Bootstrap;
@@ -47,11 +49,26 @@ protected function setUp(): void
4749
*
4850
* @param string|array $email
4951
* @dataProvider emailDataProvider
50-
* @throws \Magento\Framework\Exception\LocalizedException
52+
* @throws LocalizedException
5153
*/
5254
public function testAddToEmail($email)
5355
{
54-
$templateId = $this->template->load('email_exception_fixture', 'template_code')->getId();
56+
$template = $this->template->load('email_exception_fixture', 'template_code');
57+
$templateId = $template->getId();
58+
59+
switch ($template->getType()) {
60+
case TemplateTypesInterface::TYPE_TEXT:
61+
$templateType = MimeInterface::TYPE_TEXT;
62+
break;
63+
64+
case TemplateTypesInterface::TYPE_HTML:
65+
$templateType = MimeInterface::TYPE_HTML;
66+
break;
67+
68+
default:
69+
$templateType = '';
70+
$this->fail('Unsupported Mime Type');
71+
}
5572

5673
$this->builder->setTemplateModel(BackendTemplate::class);
5774

@@ -62,9 +79,11 @@ public function testAddToEmail($email)
6279
$this->builder->addTo($email);
6380

6481
/** @var EmailMessage $emailMessage */
65-
$emailMessage = $this->builder->getTransport();
82+
$emailMessage = $this->builder->getTransport()->getMessage();
83+
84+
$this->assertStringContainsStringIgnoringCase($templateType, $emailMessage->getHeaders()['Content-Type']);
6685

67-
$addresses = $emailMessage->getMessage()->getTo();
86+
$addresses = $emailMessage->getTo();
6887

6988
$emails = [];
7089
/** @var Address $toAddress */

lib/internal/Magento/Framework/Cache/Backend/Redis.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,25 @@ public function load($id, $doNotTestCacheValidity = false)
7373
public function save($data, $id, $tags = [], $specificLifetime = false)
7474
{
7575
try {
76-
parent::save($data, $id, $tags, $specificLifetime);
76+
$result = parent::save($data, $id, $tags, $specificLifetime);
7777
} catch (\Throwable $exception) {
78-
return false;
78+
$result = false;
7979
}
8080

81-
return true;
81+
return $result;
82+
}
83+
84+
/**
85+
* @inheritDoc
86+
*/
87+
public function remove($id)
88+
{
89+
try {
90+
$result = parent::remove($id);
91+
} catch (\Throwable $exception) {
92+
$result = false;
93+
}
94+
95+
return $result;
8296
}
8397
}

lib/internal/Magento/Framework/Code/Reader/ClassReader.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
/**
99
* Class ClassReader
10-
*
11-
* @package Magento\Framework\Code\Reader
1210
*/
1311
class ClassReader implements ClassReaderInterface
1412
{
@@ -39,7 +37,11 @@ public function getConstructor($className)
3937
$parameter->isVariadic(),
4038
];
4139
} catch (\ReflectionException $e) {
42-
$message = $e->getMessage();
40+
$message = sprintf(
41+
'Impossible to process constructor argument %s of %s class',
42+
$parameter->__toString(),
43+
$className
44+
);
4345
throw new \ReflectionException($message, 0, $e);
4446
}
4547
}

lib/internal/Magento/Framework/Code/Test/Unit/Reader/ClassReaderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ public function testGetParents()
6060
);
6161
}
6262

63+
/**
64+
* Check that while processing nonexistent argument of constructor exception message contains original class name
65+
*/
66+
public function testGetConstructorWithNonexistentDependency()
67+
{
68+
$testClass = new class {
69+
private $arg;
70+
71+
// phpstan:ignore
72+
public function __construct(?\NonexistentDependency $arg = null)
73+
{
74+
$this->arg = $arg;
75+
}
76+
};
77+
78+
$className = get_class($testClass);
79+
$this->expectException(\ReflectionException::class);
80+
$this->expectExceptionMessage($className);
81+
$this->model->getConstructor($className);
82+
}
83+
6384
/**
6485
* Data provider
6586
*

lib/internal/Magento/Framework/File/Uploader.php

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
namespace Magento\Framework\File;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Exception\FileSystemException;
11+
use Magento\Framework\Filesystem\DriverInterface;
12+
use Magento\Framework\Filesystem\DriverPool;
1013
use Magento\Framework\Validation\ValidationException;
1114

1215
/**
@@ -143,15 +146,13 @@ class Uploader
143146

144147
/**
145148
* Maximum Image Width resolution in pixels. For image resizing on client side
146-
* @deprecated
147-
* @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxWidth()
149+
* @deprecated @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxWidth()
148150
*/
149151
const MAX_IMAGE_WIDTH = 1920;
150152

151153
/**
152154
* Maximum Image Height resolution in pixels. For image resizing on client side
153-
* @deprecated
154-
* @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxHeight()
155+
* @deprecated @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxHeight()
155156
*/
156157
const MAX_IMAGE_HEIGHT = 1200;
157158

@@ -168,21 +169,32 @@ class Uploader
168169
*/
169170
private $directoryList;
170171

172+
/**
173+
* @var DriverPool|null
174+
*/
175+
private $driverPool;
176+
177+
/**
178+
* @var DriverInterface|null
179+
*/
180+
private $fileDriver;
181+
171182
/**
172183
* Init upload
173184
*
174185
* @param string|array $fileId
175186
* @param \Magento\Framework\File\Mime|null $fileMime
176187
* @param DirectoryList|null $directoryList
188+
* @param DriverPool|null $driverPool
177189
* @throws \DomainException
178190
*/
179191
public function __construct(
180192
$fileId,
181193
Mime $fileMime = null,
182-
DirectoryList $directoryList = null
194+
DirectoryList $directoryList = null,
195+
DriverPool $driverPool = null
183196
) {
184-
$this->directoryList= $directoryList ?: \Magento\Framework\App\ObjectManager::getInstance()
185-
->get(DirectoryList::class);
197+
$this->directoryList= $directoryList ?: ObjectManager::getInstance()->get(DirectoryList::class);
186198

187199
$this->_setUploadFileId($fileId);
188200
if (!file_exists($this->_file['tmp_name'])) {
@@ -191,7 +203,8 @@ public function __construct(
191203
} else {
192204
$this->_fileExists = true;
193205
}
194-
$this->fileMime = $fileMime ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Mime::class);
206+
$this->fileMime = $fileMime ?: ObjectManager::getInstance()->get(Mime::class);
207+
$this->driverPool = $driverPool;
195208
}
196209

197210
/**
@@ -229,7 +242,7 @@ public function save($destinationFolder, $newFileName = null)
229242
$this->setAllowCreateFolders(true);
230243
$this->_dispretionPath = static::getDispersionPath($fileName);
231244
$destinationFile .= $this->_dispretionPath;
232-
$this->_createDestinationFolder($destinationFile);
245+
$this->createDestinationFolder($destinationFile);
233246
}
234247

235248
if ($this->_allowRenameFiles) {
@@ -274,13 +287,11 @@ public function save($destinationFolder, $newFileName = null)
274287
* @return void
275288
* @throws FileSystemException
276289
*/
277-
private function validateDestination($destinationFolder)
290+
private function validateDestination(string $destinationFolder): void
278291
{
279292
if ($this->_allowCreateFolders) {
280-
$this->_createDestinationFolder($destinationFolder);
281-
}
282-
283-
if (!is_writable($destinationFolder)) {
293+
$this->createDestinationFolder($destinationFolder);
294+
} elseif (!$this->getFileDriver()->isWritable($destinationFolder)) {
284295
throw new FileSystemException(__('Destination folder is not writable or does not exists.'));
285296
}
286297
}
@@ -654,7 +665,7 @@ private function validateFileId(array $fileId): void
654665
* @return \Magento\Framework\File\Uploader
655666
* @throws FileSystemException
656667
*/
657-
private function _createDestinationFolder($destinationFolder)
668+
private function createDestinationFolder(string $destinationFolder)
658669
{
659670
if (!$destinationFolder) {
660671
return $this;
@@ -664,11 +675,13 @@ private function _createDestinationFolder($destinationFolder)
664675
$destinationFolder = substr($destinationFolder, 0, -1);
665676
}
666677

667-
if (!(@is_dir($destinationFolder)
668-
|| @mkdir($destinationFolder, 0777, true)
669-
)) {
670-
throw new FileSystemException(__('Unable to create directory %1.', $destinationFolder));
678+
if (!$this->getFileDriver()->isDirectory($destinationFolder)) {
679+
$result = $this->getFileDriver()->createDirectory($destinationFolder);
680+
if (!$result) {
681+
throw new FileSystemException(__('Unable to create directory %1.', $destinationFolder));
682+
}
671683
}
684+
672685
return $this;
673686
}
674687

@@ -730,4 +743,20 @@ public static function getDispersionPath($fileName)
730743
}
731744
return $dispersionPath;
732745
}
746+
747+
/**
748+
* Get driver for file
749+
*
750+
* @deprecated
751+
* @return DriverInterface
752+
*/
753+
private function getFileDriver(): DriverInterface
754+
{
755+
if (!$this->fileDriver) {
756+
$this->driverPool = $this->driverPool ?: ObjectManager::getInstance()->get(DriverPool::class);
757+
$this->fileDriver = $this->driverPool->getDriver(DriverPool::FILE);
758+
}
759+
760+
return $this->fileDriver;
761+
}
733762
}

lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
use Magento\Framework\App\TemplateTypesInterface;
1313
use Magento\Framework\Exception\LocalizedException;
1414
use Magento\Framework\Exception\MailException;
15-
use Magento\Framework\Mail\EmailMessageInterface;
16-
use Magento\Framework\Mail\EmailMessageInterfaceFactory;
1715
use Magento\Framework\Mail\AddressConverter;
16+
use Magento\Framework\Mail\EmailMessageInterfaceFactory;
1817
use Magento\Framework\Mail\Exception\InvalidArgumentException;
1918
use Magento\Framework\Mail\MessageInterface;
2019
use Magento\Framework\Mail\MessageInterfaceFactory;
@@ -28,7 +27,7 @@
2827
use Magento\Framework\Phrase;
2928

3029
/**
31-
* TransportBuilder
30+
* TransportBuilder for Mail Templates
3231
*
3332
* @api
3433
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -380,11 +379,11 @@ protected function prepareMessage()
380379

381380
switch ($template->getType()) {
382381
case TemplateTypesInterface::TYPE_TEXT:
383-
$part['type'] = MimeInterface::TYPE_TEXT;
382+
$partType = MimeInterface::TYPE_TEXT;
384383
break;
385384

386385
case TemplateTypesInterface::TYPE_HTML:
387-
$part['type'] = MimeInterface::TYPE_HTML;
386+
$partType = MimeInterface::TYPE_HTML;
388387
break;
389388

390389
default:
@@ -394,7 +393,12 @@ protected function prepareMessage()
394393
}
395394

396395
/** @var \Magento\Framework\Mail\MimePartInterface $mimePart */
397-
$mimePart = $this->mimePartInterfaceFactory->create(['content' => $content]);
396+
$mimePart = $this->mimePartInterfaceFactory->create(
397+
[
398+
'content' => $content,
399+
'type' => $partType
400+
]
401+
);
398402
$this->messageData['encoding'] = $mimePart->getCharset();
399403
$this->messageData['body'] = $this->mimeMessageInterfaceFactory->create(
400404
['parts' => [$mimePart]]

0 commit comments

Comments
 (0)