Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #21423: [Backport] Make the module list more deterministic (by @eduard13)
 - #21437: [Backport]-issue-195196 Can't upload customer Image attribute programmatically (by @Nazar65)


Fixed GitHub Issues:
 - #8479: Sequence of module load order should be deterministic (reported by @scottsb) has been fixed in #21423 by @eduard13 in 2.2-develop branch
   Related commits:
     1. abc3e7c
     2. 4b2c1b4
     3. 730987f

 - #16116: Modules sort order in config.php is being inconsistent when no changes being made (reported by @comdiler) has been fixed in #21423 by @eduard13 in 2.2-develop branch
   Related commits:
     1. abc3e7c
     2. 4b2c1b4
     3. 730987f

 - #19983: Can't work customer Image attribute programmatically (reported by @cygnetampatel) has been fixed in #21437 by @Nazar65 in 2.2-develop branch
   Related commits:
     1. b635e09
     2. 97b8f5f
  • Loading branch information
magento-engcom-team committed Mar 1, 2019
2 parents 13b0fe9 + 16a50f0 commit 6ddfc58
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Eav/Model/Attribute/Data/File.php
Expand Up @@ -146,7 +146,7 @@ protected function _validateByRules($value)
return $this->_fileValidator->getMessages();
}

if (!empty($value['tmp_name']) && !is_uploaded_file($value['tmp_name'])) {
if (!empty($value['tmp_name']) && !file_exists($value['tmp_name'])) {
return [__('"%1" is not a valid file.', $label)];
}

Expand Down
Expand Up @@ -14,7 +14,8 @@ define([
'Magento_Ui/js/lib/validation/validator',
'Magento_Ui/js/form/element/abstract',
'mage/translate',
'jquery/file-uploader'
'jquery/file-uploader',
'mage/adminhtml/tools'
], function ($, _, utils, uiAlert, validator, Element, $t) {
'use strict';

Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Variable/view/adminhtml/web/variables.js
Expand Up @@ -9,7 +9,8 @@ define([
'mage/translate',
'Magento_Ui/js/modal/modal',
'jquery/ui',
'prototype'
'prototype',
'mage/adminhtml/tools'
], function (jQuery, $t) {
'use strict';

Expand Down
36 changes: 31 additions & 5 deletions lib/internal/Magento/Framework/Module/ModuleList/Loader.php
Expand Up @@ -126,24 +126,29 @@ private function getModuleConfigs()
*
* @param array $origList
* @return array
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
* @throws \Exception
*/
private function sortBySequence($origList)
private function sortBySequence(array $origList): array
{
ksort($origList);
$modules = $this->prearrangeModules($origList);

$expanded = [];
foreach ($origList as $moduleName => $value) {
foreach (array_keys($modules) as $moduleName) {
$sequence = $this->expandSequence($origList, $moduleName);
asort($sequence);

$expanded[] = [
'name' => $moduleName,
'sequence' => $this->expandSequence($origList, $moduleName),
'sequence' => $sequence,
];
}

// Use "bubble sorting" because usort does not check each pair of elements and in this case it is important
$total = count($expanded);
for ($i = 0; $i < $total - 1; $i++) {
for ($j = $i; $j < $total; $j++) {
if (in_array($expanded[$j]['name'], $expanded[$i]['sequence'])) {
if (in_array($expanded[$j]['name'], $expanded[$i]['sequence'], true)) {
$temp = $expanded[$i];
$expanded[$i] = $expanded[$j];
$expanded[$j] = $temp;
Expand All @@ -159,6 +164,27 @@ private function sortBySequence($origList)
return $result;
}

/**
* Prearrange all modules by putting those from Magento before the others
*
* @param array $modules
* @return array
*/
private function prearrangeModules(array $modules): array
{
$breakdown = ['magento' => [], 'others' => []];

foreach ($modules as $moduleName => $moduleDetails) {
if (strpos($moduleName, 'Magento_') !== false) {
$breakdown['magento'][$moduleName] = $moduleDetails;
} else {
$breakdown['others'][$moduleName] = $moduleDetails;
}
}

return array_merge($breakdown['magento'], $breakdown['others']);
}

/**
* Accumulate information about all transitive "sequence" references
*
Expand Down
Expand Up @@ -160,4 +160,55 @@ public function testLoadCircular()
]));
$this->loader->load();
}

/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testLoadPrearranged()
{
$fixtures = [
'Foo_Bar' => ['name' => 'Foo_Bar', 'sequence' => ['Magento_Store']],
'Magento_Directory' => ['name' => 'Magento_Directory', 'sequence' => ['Magento_Store']],
'Magento_Store' => ['name' => 'Magento_Store', 'sequence' => []],
'Magento_Theme' => ['name' => 'Magento_Theme', 'sequence' => ['Magento_Store', 'Magento_Directory']],
'Test_HelloWorld' => ['name' => 'Test_HelloWorld', 'sequence' => ['Magento_Theme']]
];

$index = 0;
foreach ($fixtures as $name => $fixture) {
$this->converter->expects($this->at($index++))->method('convert')->willReturn([$name => $fixture]);
}

$this->registry->expects($this->once())
->method('getPaths')
->willReturn([
'/path/to/Foo_Bar',
'/path/to/Magento_Directory',
'/path/to/Magento_Store',
'/path/to/Magento_Theme',
'/path/to/Test_HelloWorld'
]);

$this->driver->expects($this->exactly(5))
->method('fileGetContents')
->will($this->returnValueMap([
['/path/to/Foo_Bar/etc/module.xml', null, null, self::$sampleXml],
['/path/to/Magento_Directory/etc/module.xml', null, null, self::$sampleXml],
['/path/to/Magento_Store/etc/module.xml', null, null, self::$sampleXml],
['/path/to/Magento_Theme/etc/module.xml', null, null, self::$sampleXml],
['/path/to/Test_HelloWorld/etc/module.xml', null, null, self::$sampleXml],
]));

// Load the full module list information
$result = $this->loader->load();

$this->assertSame(
['Magento_Store', 'Magento_Directory', 'Magento_Theme', 'Foo_Bar', 'Test_HelloWorld'],
array_keys($result)
);

foreach ($fixtures as $name => $fixture) {
$this->assertSame($fixture, $result[$name]);
}
}
}
6 changes: 0 additions & 6 deletions lib/web/mage/adminhtml/tools.js
Expand Up @@ -89,12 +89,6 @@ function checkByProductPriceType(elem) {

}

Event.observe(window, 'load', function () {
if ($('price_default') && $('price_default').checked) {
$('price').disabled = 'disabled';
}
});

function toggleSeveralValueElements(checkbox, containers, excludedElements, checked) {
'use strict';

Expand Down

0 comments on commit 6ddfc58

Please sign in to comment.