Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 4874a83

Browse files
author
Oleksii Korshenko
authored
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - magento/magento2#14339: Removal of inline translate script block and load a require file. (by @jonathanKingston) - magento/magento2#14353: magento/magento2#13929: Images can't be uploaded using WYSIWYG if media directory is a symlink (by @mikewhitby) Fixed GitHub Issues: - magento/magento2#13929: Images can't be uploaded using WYSIWYG if media directory is a symlink (reported by @erikhansen) has been fixed in magento/magento2#14353 by @mikewhitby in 2.3-develop branch Related commits: 1. a866bb5
2 parents d7352dd + b54efd0 commit 4874a83

File tree

5 files changed

+106
-51
lines changed

5 files changed

+106
-51
lines changed

app/code/Magento/Translation/Block/Js.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Framework\View\Element\Template;
1010
use Magento\Translation\Model\Js\Config;
11+
use Magento\Framework\Escaper;
1112

1213
/**
1314
* @api

app/code/Magento/Translation/view/base/templates/translate.phtml

+11-42
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,19 @@
99
/** @var \Magento\Translation\Block\Js $block */
1010
?>
1111
<?php if ($block->dictionaryEnabled()): ?>
12-
<script>
13-
require.config({
14-
deps: [
15-
'jquery',
16-
'mage/translate',
17-
'jquery/jquery-storageapi'
18-
],
19-
callback: function ($) {
20-
'use strict';
21-
22-
var dependencies = [],
23-
versionObj;
24-
25-
$.initNamespaceStorage('mage-translation-storage');
26-
$.initNamespaceStorage('mage-translation-file-version');
27-
versionObj = $.localStorage.get('mage-translation-file-version');
28-
29-
<?php $version = $block->getTranslationFileVersion(); ?>
30-
31-
if (versionObj.version !== '<?= /* @escapeNotVerified */ $block->escapeJsQuote($version) ?>') {
32-
dependencies.push(
33-
'text!<?= /* @noEscape */ Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME ?>'
34-
);
3512

13+
<?php
14+
$version = $block->getTranslationFileVersion();
15+
$fileName = Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME;
16+
?>
17+
<script type="text/x-magento-init">
18+
{
19+
"*": {
20+
"mage/translate-init": {
21+
"dictionaryFile": "text!<?= $block->escapeJs($fileName); ?>",
22+
"version": "<?= $block->escapeJs($version) ?>"
3623
}
37-
38-
require.config({
39-
deps: dependencies,
40-
callback: function (string) {
41-
if (typeof string === 'string') {
42-
$.mage.translate.add(JSON.parse(string));
43-
$.localStorage.set('mage-translation-storage', string);
44-
$.localStorage.set(
45-
'mage-translation-file-version',
46-
{
47-
version: '<?= /* @escapeNotVerified */ $block->escapeJsQuote($version) ?>'
48-
}
49-
);
50-
} else {
51-
$.mage.translate.add($.localStorage.get('mage-translation-storage'));
52-
}
53-
}
54-
});
5524
}
56-
});
25+
}
5726
</script>
5827
<?php endif; ?>

dev/tests/integration/testsuite/Magento/Framework/App/Filesystem/DirectoryResolverTest.php

+43-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class DirectoryResolverTest extends \PHPUnit\Framework\TestCase
2424
private $directoryResolver;
2525

2626
/**
27-
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
27+
* @var \Magento\Framework\Filesystem
2828
*/
29-
private $directory;
29+
private $filesystem;
3030

3131
/**
3232
* @inheritdoc
@@ -36,22 +36,23 @@ protected function setUp()
3636
$this->objectManager = Bootstrap::getObjectManager();
3737
$this->directoryResolver = $this->objectManager
3838
->create(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
39-
/** @var \Magento\Framework\Filesystem $filesystem */
40-
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
41-
$this->directory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
39+
$this->filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
4240
}
4341

4442
/**
4543
* @param string $path
4644
* @param string $directoryConfig
4745
* @param bool $expectation
4846
* @dataProvider validatePathDataProvider
47+
* @throws \Magento\Framework\Exception\FileSystemException
4948
* @magentoAppIsolation enabled
5049
* @return void
5150
*/
5251
public function testValidatePath($path, $directoryConfig, $expectation)
5352
{
54-
$path = $this->directory->getAbsolutePath($path);
53+
$directory = $this->filesystem
54+
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
55+
$path = $directory->getAbsolutePath($path);
5556
$this->assertEquals($expectation, $this->directoryResolver->validatePath($path, $directoryConfig));
5657
}
5758

@@ -62,10 +63,45 @@ public function testValidatePath($path, $directoryConfig, $expectation)
6263
*/
6364
public function testValidatePathWithException()
6465
{
65-
$path = $this->directory->getAbsolutePath();
66+
$directory = $this->filesystem
67+
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
68+
$path = $directory->getAbsolutePath();
6669
$this->directoryResolver->validatePath($path, 'wrong_dir');
6770
}
6871

72+
/**
73+
* @param string $path
74+
* @param string $directoryConfig
75+
* @param bool $expectation
76+
* @dataProvider validatePathDataProvider
77+
* @throws \Magento\Framework\Exception\FileSystemException
78+
* @magentoAppIsolation enabled
79+
* @return void
80+
*/
81+
public function testValidatePathWithSymlink($path, $directoryConfig, $expectation)
82+
{
83+
$directory = $this->filesystem
84+
->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::PUB);
85+
$driver = $directory->getDriver();
86+
87+
$mediaPath = $directory->getAbsolutePath('media');
88+
$mediaMovedPath = $directory->getAbsolutePath('moved-media');
89+
90+
try {
91+
$driver->rename($mediaPath, $mediaMovedPath);
92+
$driver->symlink($mediaMovedPath, $mediaPath);
93+
$this->testValidatePath($path, $directoryConfig, $expectation);
94+
} finally {
95+
// be defensive in case some operations failed
96+
if ($driver->isExists($mediaPath) && $driver->isExists($mediaMovedPath)) {
97+
$driver->deleteFile($mediaPath);
98+
$driver->rename($mediaMovedPath, $mediaPath);
99+
} elseif ($driver->isExists($mediaMovedPath)) {
100+
$driver->rename($mediaMovedPath, $mediaPath);
101+
}
102+
}
103+
}
104+
69105
/**
70106
* @return array
71107
*/

lib/internal/Magento/Framework/App/Filesystem/DirectoryResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public function __construct(DirectoryList $directoryList)
3939
public function validatePath($path, $directoryConfig = DirectoryList::MEDIA)
4040
{
4141
$realPath = realpath($path);
42-
$root = $this->directoryList->getPath($directoryConfig);
43-
42+
$root = realpath($this->directoryList->getPath($directoryConfig));
43+
4444
return strpos($realPath, $root) === 0;
4545
}
4646
}

lib/web/mage/translate-init.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'mage/translate',
9+
'jquery/jquery-storageapi'
10+
], function ($) {
11+
'use strict';
12+
13+
return function (pageOptions) {
14+
var dependencies = [],
15+
versionObj;
16+
17+
$.initNamespaceStorage('mage-translation-storage');
18+
$.initNamespaceStorage('mage-translation-file-version');
19+
versionObj = $.localStorage.get('mage-translation-file-version');
20+
21+
if (versionObj.version !== pageOptions.version) {
22+
dependencies.push(
23+
pageOptions.dictionaryFile
24+
);
25+
}
26+
27+
require.config({
28+
deps: dependencies,
29+
30+
/**
31+
* @param {String} string
32+
*/
33+
callback: function (string) {
34+
if (typeof string === 'string') {
35+
$.mage.translate.add(JSON.parse(string));
36+
$.localStorage.set('mage-translation-storage', string);
37+
$.localStorage.set(
38+
'mage-translation-file-version',
39+
{
40+
version: pageOptions.version
41+
}
42+
);
43+
} else {
44+
$.mage.translate.add($.localStorage.get('mage-translation-storage'));
45+
}
46+
}
47+
});
48+
};
49+
});

0 commit comments

Comments
 (0)