Skip to content

Commit 36d6503

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'ogre/PR_Branch' into develop
2 parents 7797df0 + 4c9841e commit 36d6503

File tree

13 files changed

+260
-64
lines changed

13 files changed

+260
-64
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ php:
1414
env:
1515
global:
1616
- COMPOSER_BIN_DIR=~/bin
17-
- INTEGRATION_SETS=2
17+
- INTEGRATION_SETS=3
1818
matrix:
1919
- TEST_SUITE=unit
2020
- TEST_SUITE=integration INTEGRATION_INDEX=1
2121
- TEST_SUITE=integration INTEGRATION_INDEX=2
22+
- TEST_SUITE=integration INTEGRATION_INDEX=3
2223
- TEST_SUITE=static
2324
cache:
2425
apt: true
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Model\Setup;
7+
8+
use Magento\Backend\Model\Menu;
9+
use Magento\Backend\Model\Menu\Builder;
10+
use Magento\Framework\App\DocRootLocator;
11+
12+
/**
13+
* Plugin class to remove web setup wizard from menu if application root is pub/ and no setup url variable is specified.
14+
*/
15+
class MenuBuilder
16+
{
17+
/**
18+
* @var DocRootLocator
19+
*/
20+
protected $docRootLocator;
21+
22+
/**
23+
* MenuBuilder constructor.
24+
*
25+
* @param DocRootLocator $docRootLocator
26+
*/
27+
public function __construct(DocRootLocator $docRootLocator)
28+
{
29+
$this->docRootLocator = $docRootLocator;
30+
}
31+
32+
/**
33+
* Removes 'Web Setup Wizard' from the menu if doc root is pub and no setup url variable is specified.
34+
*
35+
* @param Builder $subject
36+
* @param Menu $menu
37+
* @return Menu
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
39+
*/
40+
public function afterGetResult(Builder $subject, Menu $menu)
41+
{
42+
if ($this->docRootLocator->isPub()) {
43+
$menu->remove('Magento_Backend::setup_wizard');
44+
}
45+
return $menu;
46+
}
47+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Model;
8+
9+
use Magento\Backend\Model\Setup\MenuBuilder;
10+
11+
class MenuBuilderTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @dataProvider afterGetResultDataProvider
15+
*
16+
* @param string $isPub
17+
* @param int $times
18+
* @param bool $result
19+
*/
20+
public function testAfterGetResult($isPub, $times)
21+
{
22+
$docRootLocator = $this->getMock('\Magento\Framework\App\DocRootLocator', [], [], '', false);
23+
$docRootLocator->expects($this->once())->method('isPub')->willReturn($isPub);
24+
$model = new MenuBuilder($docRootLocator);
25+
/** @var \Magento\Backend\Model\Menu $menu */
26+
$menu = $this->getMock('\Magento\Backend\Model\Menu', [], [], '', false);
27+
$menu->expects($this->exactly($times))->method('remove')->willReturn(true);
28+
29+
/** @var \Magento\Backend\Model\Menu\Builder $menuBuilder */
30+
$menuBuilder = $this->getMock('\Magento\Backend\Model\Menu\Builder', [], [], '', false);
31+
32+
$this->assertInstanceOf(
33+
'\Magento\Backend\Model\Menu',
34+
$model->afterGetResult($menuBuilder, $menu)
35+
);
36+
}
37+
38+
public function afterGetResultDataProvider()
39+
{
40+
return [[true, 1], [false, 0],];
41+
}
42+
}

app/code/Magento/Backend/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,7 @@
138138
<argument name="isIncludesAvailable" xsi:type="boolean">false</argument>
139139
</arguments>
140140
</type>
141+
<type name="Magento\Backend\Model\Menu\Builder">
142+
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
143+
</type>
141144
</config>

dev/tests/functional/tests/app/Magento/Upgrade/Test/TestCase/UpgradeSystemTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,20 @@ public function test(
7373
);
7474
$version = $upgrade['upgradeVersion'];
7575

76-
if (preg_match('/^[0-9].[0-9].[0-9]/', $version, $out)) {
76+
$suffix = "( (CE|EE))$";
77+
$normalVersion = '(0|[1-9]\d*)';
78+
$preReleaseVersion = "((0(?!\\d+(\\.|\\+|{$suffix}))|[1-9A-Za-z])[0-9A-Za-z-]*)";
79+
$buildVersion = '([0-9A-Za-z][0-9A-Za-z-]*)';
80+
$versionPattern = "/^{$normalVersion}(\\.{$normalVersion}){2}"
81+
. "(-{$preReleaseVersion}(\\.{$preReleaseVersion})*)?"
82+
. "(\\+{$buildVersion}(\\.{$buildVersion})*)?{$suffix}/";
83+
84+
if (preg_match($versionPattern, $version, $out)) {
7785
$version = array_shift($out);
86+
} else {
87+
$this->fail(
88+
"Provided version format does not comply with semantic versioning specification. Got '{$version}'"
89+
);
7890
}
7991

8092
// Authenticate in admin area

dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/AdapterTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,6 @@ public function testCustomFilterableAttribute()
405405
*/
406406
public function testAdvancedSearchDateField($rangeFilter, $expectedRecordsCount)
407407
{
408-
array_walk($rangeFilter, function (&$item) {
409-
if (!empty($item)) {
410-
$item = gmdate('c', strtotime($item)) . 'Z';
411-
}
412-
});
413408
$this->requestBuilder->bind('date.from', $rangeFilter['from']);
414409
$this->requestBuilder->bind('date.to', $rangeFilter['to']);
415410
$this->requestBuilder->setRequestName('advanced_search_date_field');
@@ -421,10 +416,10 @@ public function testAdvancedSearchDateField($rangeFilter, $expectedRecordsCount)
421416
public function dateDataProvider()
422417
{
423418
return [
424-
[['from' => '2000-01-01', 'to' => '2000-01-01'], 1], //Y-m-d
425-
[['from' => '2000-01-01', 'to' => ''], 1],
426-
[['from' => '1999-12-31', 'to' => '2000-01-01'], 1],
427-
[['from' => '2000-02-01', 'to' => ''], 0],
419+
[['from' => '2000-01-01T00:00:00Z', 'to' => '2000-01-01T00:00:00Z'], 1], //Y-m-d
420+
[['from' => '2000-01-01T00:00:00Z', 'to' => ''], 1],
421+
[['from' => '1999-12-31T00:00:00Z', 'to' => '2000-01-01T00:00:00Z'], 1],
422+
[['from' => '2000-02-01T00:00:00Z', 'to' => ''], 0],
428423
];
429424
}
430425
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App;
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem\Directory\ReadFactory;
11+
12+
/**
13+
* This class calculates if document root is set to pub
14+
*/
15+
class DocRootLocator
16+
{
17+
/**
18+
* @var RequestInterface
19+
*/
20+
private $request;
21+
22+
/**
23+
* @var ReadFactory
24+
*/
25+
private $readFactory;
26+
27+
/**
28+
* @param RequestInterface $request
29+
* @param ReadFactory $readFactory
30+
*/
31+
public function __construct(RequestInterface $request, ReadFactory $readFactory)
32+
{
33+
$this->request = $request;
34+
$this->readFactory = $readFactory;
35+
}
36+
37+
/**
38+
* Returns true if doc root is pub/ and not BP
39+
*
40+
* @return bool
41+
*/
42+
public function isPub()
43+
{
44+
$rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
45+
$readDirectory = $this->readFactory->create(DirectoryList::ROOT);
46+
return (substr($rootBasePath, -strlen('/pub')) === '/pub') && !$readDirectory->isExist($rootBasePath . 'setup');
47+
}
48+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\Test\Unit;
8+
9+
use Magento\Framework\App\DocRootLocator;
10+
11+
class DocRootLocatorTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @dataProvider isPubDataProvider
15+
*
16+
* @param string $path
17+
* @param bool $isExist
18+
* @param bool $result
19+
*/
20+
public function testIsPub($path, $isExist, $result)
21+
{
22+
$request = $this->getMock('\Magento\Framework\App\Request\Http', [], [], '', false);
23+
$request->expects($this->once())->method('getServer')->willReturn($path);
24+
$reader = $this->getMock('\Magento\Framework\Filesystem\Directory\Read', [], [], '', false);
25+
$reader->expects($this->any())->method('isExist')->willReturn($isExist);
26+
$readFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadFactory', [], [], '', false);
27+
$readFactory->expects($this->once())->method('create')->willReturn($reader);
28+
$model = new DocRootLocator($request, $readFactory);
29+
$this->assertSame($result, $model->isPub());
30+
}
31+
32+
public function isPubDataProvider()
33+
{
34+
return [
35+
['/some/path/to/root', false, false],
36+
['/some/path/to/root', true, false],
37+
['/some/path/to/pub', false, true],
38+
['/some/path/to/pub', true, false],
39+
];
40+
}
41+
}

lib/internal/Magento/Framework/Code/GeneratedFiles.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ public function __construct(DirectoryList $directoryList, WriteFactory $writeFac
5252
public function regenerate()
5353
{
5454
if ($this->write->isExist(self::REGENERATE_FLAG)) {
55+
//TODO: to be removed in scope of MAGETWO-53476
5556
//clean cache
5657
$deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
5758
$configPool = new ConfigFilePool();
5859
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
5960
if ($this->write->isExist($this->write->getRelativePath($envPath))) {
6061
$this->saveCacheStatus($envPath);
6162
}
63+
//TODO: Till here
6264
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
6365
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
6466
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));

setup/src/Magento/Setup/Console/Command/UpgradeCommand.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
*/
66
namespace Magento\Setup\Console\Command;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Backend\Console\Command\AbstractCacheManageCommand;
810
use Magento\Framework\ObjectManagerInterface;
911
use Magento\Framework\Setup\ConsoleLogger;
1012
use Magento\Setup\Model\InstallerFactory;
1113
use Magento\Setup\Model\ObjectManagerProvider;
14+
use Symfony\Component\Console\Input\ArrayInput;
1215
use Symfony\Component\Console\Input\InputInterface;
1316
use Symfony\Component\Console\Input\InputOption;
1417
use Symfony\Component\Console\Output\OutputInterface;
@@ -94,5 +97,41 @@ protected function execute(InputInterface $input, OutputInterface $output)
9497
if (!$keepGenerated) {
9598
$output->writeln('<info>Please re-run Magento compile command</info>');
9699
}
100+
101+
return $this->enableCaches($objectManager, $output);
102+
}
103+
104+
/**
105+
* Enables cache if cachestates exists
106+
* TODO: to be removed in scope of MAGETWO-53476
107+
*
108+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
109+
* @param \Symfony\Component\Console\Output\OutputInterface $output
110+
* @return int
111+
*/
112+
private function enableCaches($objectManager, $output)
113+
{
114+
$writeFactory = $objectManager->get('Magento\Framework\Filesystem\Directory\WriteFactory');
115+
$write = $writeFactory->create(BP);
116+
/** @var \Magento\Framework\App\Filesystem\DirectoryList $dirList */
117+
$dirList = $objectManager->get('Magento\Framework\App\Filesystem\DirectoryList');
118+
119+
$pathToCacheStatus = $write->getRelativePath($dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json');
120+
121+
if ($write->isExist($pathToCacheStatus)) {
122+
$params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));
123+
$command = $this->getApplication()->find('cache:enable');
124+
125+
$arguments = ['command' => 'cache:enable', AbstractCacheManageCommand::INPUT_KEY_TYPES => $params ];
126+
$returnCode = $command->run(new ArrayInput($arguments), $output);
127+
128+
$write->delete($pathToCacheStatus);
129+
if (isset($returnCode) && $returnCode > 0) {
130+
$message = '<error> Error occured during upgrade. Error code: ' . $returnCode . '</error>';
131+
$output->writeln($message);
132+
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
133+
}
134+
}
135+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
97136
}
98137
}

0 commit comments

Comments
 (0)