Skip to content

Commit 69d5bbf

Browse files
committed
Merge remote-tracking branch 'tango/MAGETWO-99401' into pr_vk_2019_08_16
2 parents 068c62f + 4ff6893 commit 69d5bbf

File tree

4 files changed

+93
-21
lines changed

4 files changed

+93
-21
lines changed

app/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,4 +1777,7 @@
17771777
type="Magento\Framework\Mail\MimeMessage" />
17781778
<preference for="Magento\Framework\Mail\MimePartInterface"
17791779
type="Magento\Framework\Mail\MimePart" />
1780+
<type name="Magento\Framework\DB\Adapter\AdapterInterface">
1781+
<plugin name="execute_commit_callbacks" type="Magento\Framework\Model\ExecuteCommitCallbacks" />
1782+
</type>
17801783
</config>

lib/internal/Magento/Framework/Config/Scope.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
*/
66
namespace Magento\Framework\Config;
77

8-
class Scope implements \Magento\Framework\Config\ScopeInterface, \Magento\Framework\Config\ScopeListInterface
9-
{
10-
/**
11-
* Default application scope
12-
*
13-
* @var string
14-
*/
15-
protected $_defaultScope;
8+
use Magento\Framework\App\AreaList;
169

10+
/**
11+
* Scope config
12+
*/
13+
class Scope implements ScopeInterface, ScopeListInterface
14+
{
1715
/**
1816
* Current config scope
1917
*
@@ -24,19 +22,19 @@ class Scope implements \Magento\Framework\Config\ScopeInterface, \Magento\Framew
2422
/**
2523
* List of all available areas
2624
*
27-
* @var \Magento\Framework\App\AreaList
25+
* @var AreaList
2826
*/
2927
protected $_areaList;
3028

3129
/**
3230
* Constructor
3331
*
34-
* @param \Magento\Framework\App\AreaList $areaList
32+
* @param AreaList $areaList
3533
* @param string $defaultScope
3634
*/
37-
public function __construct(\Magento\Framework\App\AreaList $areaList, $defaultScope = 'primary')
35+
public function __construct(AreaList $areaList, $defaultScope = 'primary')
3836
{
39-
$this->_defaultScope = $this->_currentScope = $defaultScope;
37+
$this->_currentScope = $defaultScope;
4038
$this->_areaList = $areaList;
4139
}
4240

@@ -69,7 +67,9 @@ public function setCurrentScope($scope)
6967
public function getAllScopes()
7068
{
7169
$codes = $this->_areaList->getCodes();
72-
array_unshift($codes, $this->_defaultScope);
70+
array_unshift($codes, 'global');
71+
array_unshift($codes, 'primary');
72+
7373
return $codes;
7474
}
7575
}

lib/internal/Magento/Framework/Config/Test/Unit/ScopeTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@
66

77
namespace Magento\Framework\Config\Test\Unit;
88

9-
use \Magento\Framework\Config\Scope;
9+
use Magento\Framework\App\AreaList;
10+
use Magento\Framework\Config\Scope;
11+
use PHPUnit\Framework\MockObject\MockObject;
1012

1113
class ScopeTest extends \PHPUnit\Framework\TestCase
1214
{
1315
/**
14-
* @var \Magento\Framework\Config\Scope
16+
* @var Scope
1517
*/
16-
protected $model;
18+
private $model;
1719

1820
/**
19-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\AreaList
21+
* @var MockObject|AreaList
2022
*/
21-
protected $areaListMock;
23+
private $areaListMock;
2224

2325
protected function setUp()
2426
{
25-
$this->areaListMock = $this->createPartialMock(\Magento\Framework\App\AreaList::class, ['getCodes']);
27+
$this->areaListMock = $this->createPartialMock(AreaList::class, ['getCodes']);
2628
$this->model = new Scope($this->areaListMock);
2729
}
2830

@@ -35,10 +37,10 @@ public function testScopeSetGet()
3537

3638
public function testGetAllScopes()
3739
{
38-
$expectedBalances = ['primary', 'test_scope'];
40+
$expectedBalances = ['primary', 'global', 'test_scope'];
3941
$this->areaListMock->expects($this->once())
4042
->method('getCodes')
41-
->will($this->returnValue(['test_scope']));
43+
->willReturn(['test_scope']);
4244
$this->assertEquals($expectedBalances, $this->model->getAllScopes());
4345
}
4446
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Model;
9+
10+
use Magento\Framework\DB\Adapter\AdapterInterface;
11+
use Psr\Log\LoggerInterface;
12+
13+
/**
14+
* Execute added callbacks for transaction commit.
15+
*/
16+
class ExecuteCommitCallbacks
17+
{
18+
/**
19+
* @var LoggerInterface
20+
*/
21+
private $logger;
22+
23+
/**
24+
* @param LoggerInterface $logger
25+
*/
26+
public function __construct(LoggerInterface $logger)
27+
{
28+
$this->logger = $logger;
29+
}
30+
31+
/**
32+
* Execute callbacks after commit.
33+
*
34+
* @param AdapterInterface $subject
35+
* @param AdapterInterface $result
36+
* @return AdapterInterface
37+
*/
38+
public function afterCommit(AdapterInterface $subject, AdapterInterface $result): AdapterInterface
39+
{
40+
if ($result->getTransactionLevel() === 0) {
41+
$callbacks = CallbackPool::get(spl_object_hash($subject));
42+
foreach ($callbacks as $callback) {
43+
try {
44+
call_user_func($callback);
45+
} catch (\Throwable $e) {
46+
$this->logger->critical($e);
47+
}
48+
}
49+
}
50+
51+
return $result;
52+
}
53+
54+
/**
55+
* Drop callbacks after rollBack.
56+
*
57+
* @param AdapterInterface $subject
58+
* @param AdapterInterface $result
59+
* @return AdapterInterface
60+
*/
61+
public function afterRollBack(AdapterInterface $subject, AdapterInterface $result): AdapterInterface
62+
{
63+
CallbackPool::clear(spl_object_hash($subject));
64+
65+
return $result;
66+
}
67+
}

0 commit comments

Comments
 (0)