Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Browse files Browse the repository at this point in the history
Accepted Community Pull Requests:
 - #28739: Close prompt immediately after click ok instead of wait ajax request (by @Nazar65)
 - #28351: Generated code is not consistent with Magento requirements and Coding Standard (by @lbajsarowicz)
 - #27429: Add ACL role ID to category tree cache id (by @quangdo-aligent)
 - #27567: #27091 Removed array print while setup upgrade (by @srsathish92)
 - #28515: Changed array creation to be in line with the class (by @litsher)
 - #28460: Product CSV import error report file missing (by @engcom-Charlie)
 - #28421: Error when creating a store view if there are CMS pages with the same URL key (by @engcom-Charlie)
 - #27965: #27962 Migrate Plugin out of Framework (to Theme module) (by @lbajsarowicz)


Fixed GitHub Issues:
 - #28376: [Issue] Generated code is not consistent with Magento requirements and Coding Standard (reported by @m2-backlog[bot]) has been fixed in #28351 by @lbajsarowicz in 2.4-develop branch
   Related commits:
     1. fcc3e27
     2. 3f87a5b

 - #28306: [Issue] Add ACL role ID to category tree cache id (reported by @m2-backlog[bot]) has been fixed in #27429 by @quangdo-aligent in 2.4-develop branch
   Related commits:
     1. 54a11eb
     2. f1c8ad5
     3. 207a449
     4. 61f847e
     5. 5a4e93f
     6. e5b64f5
     7. 06d3e3a
     8. 179a72f
     9. a096270

 - #27091: Magento 2.3.4 array print while setup upgrade (reported by @RHapani) has been fixed in #27567 by @srsathish92 in 2.4-develop branch
   Related commits:
     1. d95a65a
     2. 981df7b
     3. 16ebd28
     4. a044c53
     5. 075f997
     6. 479166e

 - #28795: [Issue] Changed array creation to be in line with the class (reported by @m2-assistant[bot]) has been fixed in #28515 by @litsher in 2.4-develop branch
   Related commits:
     1. 8901baa
     2. 4418a95
     3. f44321f
     4. ba12f12

 - #28420: Product CSV import error report file missing (reported by @mischabraam) has been fixed in #28460 by @engcom-Charlie in 2.4-develop branch
   Related commits:
     1. d4d8ef4
     2. 597d65f

 - #28357: Error when creating a store view if there are CMS pages with the same URL key (reported by @stupachenko) has been fixed in #28421 by @engcom-Charlie in 2.4-develop branch
   Related commits:
     1. 035aaf0
     2. f1d1450
     3. 9d417ec

 - #27962: Plugins in \Magento\Framework namespace (reported by @lbajsarowicz) has been fixed in #27965 by @lbajsarowicz in 2.4-develop branch
   Related commits:
     1. d938e7b
     2. ae58f56
     3. 02aae13
     4. a84633e
     5. 7ff6063
  • Loading branch information
magento-engcom-team committed Jun 24, 2020
2 parents 3b19d14 + 757c11a commit c35093a
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
use Magento\Framework\AuthorizationInterface;
use Magento\Framework\DB\Helper as DbHelper;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\Store;
use Magento\Backend\Model\Auth\Session;
use Magento\Authorization\Model\Role;
use Magento\User\Model\User;
use PHPUnit\Framework\MockObject\MockObject;

/**
Expand Down Expand Up @@ -51,6 +54,11 @@ class CategoriesTest extends AbstractModifierTest
*/
private $authorizationMock;

/**
* @var Session|MockObject
*/
private $sessionMock;

protected function setUp(): void
{
parent::setUp();
Expand All @@ -72,7 +80,10 @@ protected function setUp(): void
$this->authorizationMock = $this->getMockBuilder(AuthorizationInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->sessionMock = $this->getMockBuilder(Session::class)
->setMethods(['getUser'])
->disableOriginalConstructor()
->getMock();
$this->categoryCollectionFactoryMock->expects($this->any())
->method('create')
->willReturn($this->categoryCollectionMock);
Expand All @@ -88,6 +99,26 @@ protected function setUp(): void
$this->categoryCollectionMock->expects($this->any())
->method('getIterator')
->willReturn(new \ArrayIterator([]));

$roleAdmin = $this->getMockBuilder(Role::class)
->setMethods(['getId'])
->disableOriginalConstructor()
->getMock();
$roleAdmin->expects($this->any())
->method('getId')
->willReturn(0);

$userAdmin = $this->getMockBuilder(User::class)
->setMethods(['getRole'])
->disableOriginalConstructor()
->getMock();
$userAdmin->expects($this->any())
->method('getRole')
->willReturn($roleAdmin);

$this->sessionMock->expects($this->any())
->method('getUser')
->willReturn($userAdmin);
}

/**
Expand All @@ -101,11 +132,28 @@ protected function createModel()
'locator' => $this->locatorMock,
'categoryCollectionFactory' => $this->categoryCollectionFactoryMock,
'arrayManager' => $this->arrayManagerMock,
'authorization' => $this->authorizationMock
'authorization' => $this->authorizationMock,
'session' => $this->sessionMock
]
);
}

/**
* @param object $object
* @param string $method
* @param array $args
* @return mixed
* @throws \ReflectionException
*/
private function invokeMethod($object, $method, $args = [])
{
$class = new \ReflectionClass(Categories::class);
$method = $class->getMethod($method);
$method->setAccessible(true);

return $method->invokeArgs($object, $args);
}

public function testModifyData()
{
$this->assertSame([], $this->getModel()->modifyData([]));
Expand Down Expand Up @@ -176,4 +224,44 @@ public function modifyMetaLockedDataProvider()
{
return [[true], [false]];
}

/**
* Asserts that a user with an ACL role ID of 0 and a user with an ACL role ID of 1 do not have the same cache IDs
* Assumes a store ID of 0
*
* @throws \ReflectionException
*/
public function testAclCacheIds()
{
$categoriesAdmin = $this->createModel();
$cacheIdAdmin = $this->invokeMethod($categoriesAdmin, 'getCategoriesTreeCacheId', [0]);

$roleAclUser = $this->getMockBuilder(Role::class)
->disableOriginalConstructor()
->getMock();
$roleAclUser->expects($this->any())
->method('getId')
->willReturn(1);

$userAclUser = $this->getMockBuilder(User::class)
->disableOriginalConstructor()
->getMock();
$userAclUser->expects($this->any())
->method('getRole')
->will($this->returnValue($roleAclUser));

$this->sessionMock = $this->getMockBuilder(Session::class)
->setMethods(['getUser'])
->disableOriginalConstructor()
->getMock();

$this->sessionMock->expects($this->any())
->method('getUser')
->will($this->returnValue($userAclUser));

$categoriesAclUser = $this->createModel();
$cacheIdAclUser = $this->invokeMethod($categoriesAclUser, 'getCategoriesTreeCacheId', [0]);

$this->assertNotEquals($cacheIdAdmin, $cacheIdAclUser);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
use Magento\Framework\UrlInterface;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\AuthorizationInterface;
use Magento\Backend\Model\Auth\Session;

/**
* Data provider for categories field of product page
*
* @api
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* @since 101.0.0
*/
class Categories extends AbstractModifier
Expand Down Expand Up @@ -86,6 +88,11 @@ class Categories extends AbstractModifier
*/
private $authorization;

/**
* @var Session
*/
private $session;

/**
* @param LocatorInterface $locator
* @param CategoryCollectionFactory $categoryCollectionFactory
Expand All @@ -94,6 +101,7 @@ class Categories extends AbstractModifier
* @param ArrayManager $arrayManager
* @param SerializerInterface $serializer
* @param AuthorizationInterface $authorization
* @param Session $session
*/
public function __construct(
LocatorInterface $locator,
Expand All @@ -102,7 +110,8 @@ public function __construct(
UrlInterface $urlBuilder,
ArrayManager $arrayManager,
SerializerInterface $serializer = null,
AuthorizationInterface $authorization = null
AuthorizationInterface $authorization = null,
Session $session = null
) {
$this->locator = $locator;
$this->categoryCollectionFactory = $categoryCollectionFactory;
Expand All @@ -111,6 +120,7 @@ public function __construct(
$this->arrayManager = $arrayManager;
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
$this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
$this->session = $session ?: ObjectManager::getInstance()->get(Session::class);
}

/**
Expand Down Expand Up @@ -370,10 +380,16 @@ protected function getCategoriesTree($filter = null)
* @param string $filter
* @return string
*/
private function getCategoriesTreeCacheId(int $storeId, string $filter = '') : string
private function getCategoriesTreeCacheId(int $storeId, string $filter = ''): string
{
if ($this->session->getUser() !== null) {
return self::CATEGORY_TREE_ID
. '_' . (string)$storeId
. '_' . $this->session->getUser()->getAclRole()
. '_' . $filter;
}
return self::CATEGORY_TREE_ID
. '_' . (string) $storeId
. '_' . (string)$storeId
. '_' . $filter;
}

Expand Down
22 changes: 19 additions & 3 deletions app/code/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\CmsUrlRewrite\Plugin\Cms\Model\Store;

use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Api\PageRepositoryInterface;
use Magento\CmsUrlRewrite\Model\CmsPageUrlRewriteGenerator;
use Magento\Framework\Api\SearchCriteriaBuilder;
Expand All @@ -21,6 +22,8 @@
*/
class View
{
private const ALL_STORE_VIEWS = '0';

/**
* @var UrlPersistInterface
*/
Expand Down Expand Up @@ -89,14 +92,27 @@ private function generateCmsPagesUrls(int $storeId): array
{
$rewrites = [];
$urls = [];
$searchCriteria = $this->searchCriteriaBuilder->create();
$cmsPagesCollection = $this->pageRepository->getList($searchCriteria)->getItems();
foreach ($cmsPagesCollection as $page) {

foreach ($this->getCmsPageItems() as $page) {
$page->setStoreId($storeId);
$rewrites[] = $this->cmsPageUrlRewriteGenerator->generate($page);
}
$urls = array_merge($urls, ...$rewrites);

return $urls;
}

/**
* Return cms page items for all store view
*
* @return PageInterface[]
*/
private function getCmsPageItems(): array
{
$searchCriteria = $this->searchCriteriaBuilder->addFilter('store_id', self::ALL_STORE_VIEWS)
->create();
$list = $this->pageRepository->getList($searchCriteria);

return $list->getItems();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace %moduleName%\Setup\Patch\%patchType%;

Expand Down Expand Up @@ -36,20 +37,18 @@ class %class% implements %implementsInterfaces%
}
%revertFunction%
/**
* {@inheritdoc}
* @inheritdoc
*/
public function getAliases()
{
return [];
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public static function getDependencies()
{
return [

];
return [];
}
}
13 changes: 13 additions & 0 deletions app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public function destruct()
{
if (is_object($this->_fileHandler)) {
$this->_fileHandler->close();
$this->resolveDestination();
}
}

/**
* Remove temporary destination
*
* @return void
*/
private function resolveDestination(): void
{
// only temporary file located directly in var folder
if (strpos($this->_destination, '/') === false) {
$this->_directoryHandle->delete($this->_destination);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ public function draw()
$lines = [];

// draw Product name
$lines[0] = [
[
$lines[0][] = [
'text' => $this->string->split($this->prepareText((string)$item->getName()), 35, true, true),
'feed' => 35
]
];

// draw SKU
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/Store/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<preference for="Magento\Framework\App\Router\PathConfigInterface" type="Magento\Store\Model\PathConfig" />
<type name="Magento\Framework\App\ActionInterface">
<plugin name="storeCheck" type="Magento\Store\App\Action\Plugin\StoreCheck"/>
<plugin name="designLoader" type="Magento\Framework\App\Action\Plugin\LoadDesignPlugin"/>
<plugin name="eventDispatch" type="Magento\Framework\App\Action\Plugin\EventDispatchPlugin"/>
<plugin name="actionFlagNoDispatch" type="Magento\Framework\App\Action\Plugin\ActionFlagNoDispatchPlugin"/>
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/

namespace Magento\Framework\App\Action\Plugin;
namespace Magento\Theme\Plugin;

use Magento\Framework\App\ActionInterface;
use Magento\Framework\Config\Dom\ValidationException;
Expand All @@ -21,12 +21,12 @@ class LoadDesignPlugin
/**
* @var DesignLoader
*/
protected $_designLoader;
private $designLoader;

/**
* @var MessageManagerInterface
*/
protected $messageManager;
private $messageManager;

/**
* @param DesignLoader $designLoader
Expand All @@ -36,7 +36,7 @@ public function __construct(
DesignLoader $designLoader,
MessageManagerInterface $messageManager
) {
$this->_designLoader = $designLoader;
$this->designLoader = $designLoader;
$this->messageManager = $messageManager;
}

Expand All @@ -50,7 +50,7 @@ public function __construct(
public function beforeExecute(ActionInterface $subject)
{
try {
$this->_designLoader->load();
$this->designLoader->load();
} catch (LocalizedException $e) {
if ($e->getPrevious() instanceof ValidationException) {
/** @var MessageInterface $message */
Expand Down
Loading

0 comments on commit c35093a

Please sign in to comment.