Skip to content

Commit

Permalink
Merge remote-tracking branch 'ogre/PR_Branch' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Korshenko committed Jun 8, 2016
2 parents 7797df0 + 4c9841e commit 36d6503
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 64 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ php:
env:
global:
- COMPOSER_BIN_DIR=~/bin
- INTEGRATION_SETS=2
- INTEGRATION_SETS=3
matrix:
- TEST_SUITE=unit
- TEST_SUITE=integration INTEGRATION_INDEX=1
- TEST_SUITE=integration INTEGRATION_INDEX=2
- TEST_SUITE=integration INTEGRATION_INDEX=3
- TEST_SUITE=static
cache:
apt: true
Expand Down
47 changes: 47 additions & 0 deletions app/code/Magento/Backend/Model/Setup/MenuBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Model\Setup;

use Magento\Backend\Model\Menu;
use Magento\Backend\Model\Menu\Builder;
use Magento\Framework\App\DocRootLocator;

/**
* Plugin class to remove web setup wizard from menu if application root is pub/ and no setup url variable is specified.
*/
class MenuBuilder
{
/**
* @var DocRootLocator
*/
protected $docRootLocator;

/**
* MenuBuilder constructor.
*
* @param DocRootLocator $docRootLocator
*/
public function __construct(DocRootLocator $docRootLocator)
{
$this->docRootLocator = $docRootLocator;
}

/**
* Removes 'Web Setup Wizard' from the menu if doc root is pub and no setup url variable is specified.
*
* @param Builder $subject
* @param Menu $menu
* @return Menu
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterGetResult(Builder $subject, Menu $menu)
{
if ($this->docRootLocator->isPub()) {
$menu->remove('Magento_Backend::setup_wizard');
}
return $menu;
}
}
42 changes: 42 additions & 0 deletions app/code/Magento/Backend/Test/Unit/Model/MenuBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Backend\Test\Unit\Model;

use Magento\Backend\Model\Setup\MenuBuilder;

class MenuBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider afterGetResultDataProvider
*
* @param string $isPub
* @param int $times
* @param bool $result
*/
public function testAfterGetResult($isPub, $times)
{
$docRootLocator = $this->getMock('\Magento\Framework\App\DocRootLocator', [], [], '', false);
$docRootLocator->expects($this->once())->method('isPub')->willReturn($isPub);
$model = new MenuBuilder($docRootLocator);
/** @var \Magento\Backend\Model\Menu $menu */
$menu = $this->getMock('\Magento\Backend\Model\Menu', [], [], '', false);
$menu->expects($this->exactly($times))->method('remove')->willReturn(true);

/** @var \Magento\Backend\Model\Menu\Builder $menuBuilder */
$menuBuilder = $this->getMock('\Magento\Backend\Model\Menu\Builder', [], [], '', false);

$this->assertInstanceOf(
'\Magento\Backend\Model\Menu',
$model->afterGetResult($menuBuilder, $menu)
);
}

public function afterGetResultDataProvider()
{
return [[true, 1], [false, 0],];
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,7 @@
<argument name="isIncludesAvailable" xsi:type="boolean">false</argument>
</arguments>
</type>
<type name="Magento\Backend\Model\Menu\Builder">
<plugin name="SetupMenuBuilder" type="Magento\Backend\Model\Setup\MenuBuilder" />
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,20 @@ public function test(
);
$version = $upgrade['upgradeVersion'];

if (preg_match('/^[0-9].[0-9].[0-9]/', $version, $out)) {
$suffix = "( (CE|EE))$";
$normalVersion = '(0|[1-9]\d*)';
$preReleaseVersion = "((0(?!\\d+(\\.|\\+|{$suffix}))|[1-9A-Za-z])[0-9A-Za-z-]*)";
$buildVersion = '([0-9A-Za-z][0-9A-Za-z-]*)';
$versionPattern = "/^{$normalVersion}(\\.{$normalVersion}){2}"
. "(-{$preReleaseVersion}(\\.{$preReleaseVersion})*)?"
. "(\\+{$buildVersion}(\\.{$buildVersion})*)?{$suffix}/";

if (preg_match($versionPattern, $version, $out)) {
$version = array_shift($out);
} else {
$this->fail(
"Provided version format does not comply with semantic versioning specification. Got '{$version}'"
);
}

// Authenticate in admin area
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,6 @@ public function testCustomFilterableAttribute()
*/
public function testAdvancedSearchDateField($rangeFilter, $expectedRecordsCount)
{
array_walk($rangeFilter, function (&$item) {
if (!empty($item)) {
$item = gmdate('c', strtotime($item)) . 'Z';
}
});
$this->requestBuilder->bind('date.from', $rangeFilter['from']);
$this->requestBuilder->bind('date.to', $rangeFilter['to']);
$this->requestBuilder->setRequestName('advanced_search_date_field');
Expand All @@ -421,10 +416,10 @@ public function testAdvancedSearchDateField($rangeFilter, $expectedRecordsCount)
public function dateDataProvider()
{
return [
[['from' => '2000-01-01', 'to' => '2000-01-01'], 1], //Y-m-d
[['from' => '2000-01-01', 'to' => ''], 1],
[['from' => '1999-12-31', 'to' => '2000-01-01'], 1],
[['from' => '2000-02-01', 'to' => ''], 0],
[['from' => '2000-01-01T00:00:00Z', 'to' => '2000-01-01T00:00:00Z'], 1], //Y-m-d
[['from' => '2000-01-01T00:00:00Z', 'to' => ''], 1],
[['from' => '1999-12-31T00:00:00Z', 'to' => '2000-01-01T00:00:00Z'], 1],
[['from' => '2000-02-01T00:00:00Z', 'to' => ''], 0],
];
}
}
48 changes: 48 additions & 0 deletions lib/internal/Magento/Framework/App/DocRootLocator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\App;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Directory\ReadFactory;

/**
* This class calculates if document root is set to pub
*/
class DocRootLocator
{
/**
* @var RequestInterface
*/
private $request;

/**
* @var ReadFactory
*/
private $readFactory;

/**
* @param RequestInterface $request
* @param ReadFactory $readFactory
*/
public function __construct(RequestInterface $request, ReadFactory $readFactory)
{
$this->request = $request;
$this->readFactory = $readFactory;
}

/**
* Returns true if doc root is pub/ and not BP
*
* @return bool
*/
public function isPub()
{
$rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
$readDirectory = $this->readFactory->create(DirectoryList::ROOT);
return (substr($rootBasePath, -strlen('/pub')) === '/pub') && !$readDirectory->isExist($rootBasePath . 'setup');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\App\Test\Unit;

use Magento\Framework\App\DocRootLocator;

class DocRootLocatorTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider isPubDataProvider
*
* @param string $path
* @param bool $isExist
* @param bool $result
*/
public function testIsPub($path, $isExist, $result)
{
$request = $this->getMock('\Magento\Framework\App\Request\Http', [], [], '', false);
$request->expects($this->once())->method('getServer')->willReturn($path);
$reader = $this->getMock('\Magento\Framework\Filesystem\Directory\Read', [], [], '', false);
$reader->expects($this->any())->method('isExist')->willReturn($isExist);
$readFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadFactory', [], [], '', false);
$readFactory->expects($this->once())->method('create')->willReturn($reader);
$model = new DocRootLocator($request, $readFactory);
$this->assertSame($result, $model->isPub());
}

public function isPubDataProvider()
{
return [
['/some/path/to/root', false, false],
['/some/path/to/root', true, false],
['/some/path/to/pub', false, true],
['/some/path/to/pub', true, false],
];
}
}
2 changes: 2 additions & 0 deletions lib/internal/Magento/Framework/Code/GeneratedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ public function __construct(DirectoryList $directoryList, WriteFactory $writeFac
public function regenerate()
{
if ($this->write->isExist(self::REGENERATE_FLAG)) {
//TODO: to be removed in scope of MAGETWO-53476
//clean cache
$deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
$configPool = new ConfigFilePool();
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
if ($this->write->isExist($this->write->getRelativePath($envPath))) {
$this->saveCacheStatus($envPath);
}
//TODO: Till here
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));
Expand Down
39 changes: 39 additions & 0 deletions setup/src/Magento/Setup/Console/Command/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
*/
namespace Magento\Setup\Console\Command;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Backend\Console\Command\AbstractCacheManageCommand;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Setup\ConsoleLogger;
use Magento\Setup\Model\InstallerFactory;
use Magento\Setup\Model\ObjectManagerProvider;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -94,5 +97,41 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$keepGenerated) {
$output->writeln('<info>Please re-run Magento compile command</info>');
}

return $this->enableCaches($objectManager, $output);
}

/**
* Enables cache if cachestates exists
* TODO: to be removed in scope of MAGETWO-53476
*
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return int
*/
private function enableCaches($objectManager, $output)
{
$writeFactory = $objectManager->get('Magento\Framework\Filesystem\Directory\WriteFactory');
$write = $writeFactory->create(BP);
/** @var \Magento\Framework\App\Filesystem\DirectoryList $dirList */
$dirList = $objectManager->get('Magento\Framework\App\Filesystem\DirectoryList');

$pathToCacheStatus = $write->getRelativePath($dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json');

if ($write->isExist($pathToCacheStatus)) {
$params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));
$command = $this->getApplication()->find('cache:enable');

$arguments = ['command' => 'cache:enable', AbstractCacheManageCommand::INPUT_KEY_TYPES => $params ];
$returnCode = $command->run(new ArrayInput($arguments), $output);

$write->delete($pathToCacheStatus);
if (isset($returnCode) && $returnCode > 0) {
$message = '<error> Error occured during upgrade. Error code: ' . $returnCode . '</error>';
$output->writeln($message);
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
}
}
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
}
}
22 changes: 0 additions & 22 deletions setup/src/Magento/Setup/Model/Cron/JobUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
namespace Magento\Setup\Model\Cron;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Setup\Console\Command\AbstractSetupCommand;
use Magento\Setup\Model\ObjectManagerProvider;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -72,26 +70,6 @@ public function execute()
);
$this->params['command'] = 'setup:upgrade';
$this->command->run(new ArrayInput($this->params), $this->output);

/**
* @var \Magento\Framework\Filesystem\Directory\WriteFactory $writeFactory
*/
$writeFactory = $this->objectManager->get('\Magento\Framework\Filesystem\Directory\WriteFactory');
$write = $writeFactory->create(BP);
$dirList = $this->objectManager->get('\Magento\Framework\App\Filesystem\DirectoryList');
$pathToCacheStatus = $write->getRelativePath(
$dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json'
);

if ($write->isExist($pathToCacheStatus)) {
$params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));

$this->queue->addJobs(
[['name' => JobFactory::JOB_ENABLE_CACHE, 'params' => [implode(' ', $params)]]]
);
$write->delete($pathToCacheStatus);
}

} catch (\Exception $e) {
$this->status->toggleUpdateError(true);
throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,31 @@ public function testExecute()
$state = $this->getMock('Magento\Framework\App\State', [], [], '', false);
$state->expects($this->once())->method('setAreaCode')->with('setup');
$objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
$objectManager->expects($this->exactly(2))
->method('get')
->will($this->returnValueMap([
['Magento\Framework\App\State', $state],
['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader],
]));
$objectManager->expects($this->once())->method('configure');
$state->expects($this->once())->method('setAreaCode')->with('setup');
$installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false);
$installer->expects($this->at(0))->method('updateModulesSequence');
$installer->expects($this->at(1))->method('installSchema');
$installer->expects($this->at(2))->method('installDataFixtures');
$installerFactory->expects($this->once())->method('create')->willReturn($installer);

$pathToCacheStatus = '/path/to/cachefile';
$writeFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteFactory', [], [], '', false);
$write = $this->getMock('\Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
$write->expects($this->once())->method('isExist')->with('/path/to/cachefile')->willReturn(false);
$write->expects($this->once())->method('getRelativePath')->willReturn($pathToCacheStatus);

$writeFactory->expects($this->once())->method('create')->willReturn($write);
$directoryList = $this->getMock('\Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
$objectManager->expects($this->exactly(4))
->method('get')
->will($this->returnValueMap([
['Magento\Framework\App\State', $state],
['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader],
['Magento\Framework\Filesystem\Directory\WriteFactory', $writeFactory],
['Magento\Framework\App\Filesystem\DirectoryList', $directoryList],
]));

$commandTester = new CommandTester(new UpgradeCommand($installerFactory, $objectManagerProvider));
$commandTester->execute([]);
}
Expand Down
Loading

0 comments on commit 36d6503

Please sign in to comment.