Skip to content

Commit

Permalink
Merge pull request magento#609 from magento-ogre/PR_Branch_merchant_beta
Browse files Browse the repository at this point in the history
[Ogres] Merchant Beta Bug Fixes
  • Loading branch information
mazhalai committed Sep 17, 2015
2 parents d43e527 + 8a1d1b9 commit d1977f0
Show file tree
Hide file tree
Showing 42 changed files with 910 additions and 408 deletions.
36 changes: 18 additions & 18 deletions app/code/Magento/CacheInvalidate/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
namespace Magento\CacheInvalidate\Model;

use Symfony\Component\Config\Definition\Exception\Exception;
use Zend\Uri\Uri;
use Zend\Http\Client\Adapter\Socket;
use Magento\Framework\Cache\InvalidateLogger;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Config\ConfigOptionsListConstants;
Expand Down Expand Up @@ -37,14 +35,14 @@ class Observer
private $logger;

/**
* @var Uri
* @var UriFactory
*/
protected $uri;
protected $uriFactory;

/**
* @var Socket
* @var SocketFactory
*/
protected $socketAdapter;
protected $socketAdapterFactory;

/**
* @var DeploymentConfig
Expand All @@ -58,23 +56,23 @@ class Observer

/**
* @param \Magento\PageCache\Model\Config $config
* @param Uri $uri
* @param Socket $socketAdapter
* @param UriFactory $uriFactory
* @param SocketFactory $socketAdapterFactory
* @param InvalidateLogger $logger
* @param DeploymentConfig $deploymentConfig
* @param RequestInterface $request
*/
public function __construct(
\Magento\PageCache\Model\Config $config,
Uri $uri,
Socket $socketAdapter,
UriFactory $uriFactory,
SocketFactory $socketAdapterFactory,
InvalidateLogger $logger,
DeploymentConfig $deploymentConfig,
RequestInterface $request
) {
$this->config = $config;
$this->uri = $uri;
$this->socketAdapter = $socketAdapter;
$this->uriFactory = $uriFactory;
$this->socketAdapterFactory = $socketAdapterFactory;
$this->logger = $logger;
$this->deploymentConfig = $deploymentConfig;
$this->request = $request;
Expand Down Expand Up @@ -126,24 +124,26 @@ public function flushAllCache(\Magento\Framework\Event\Observer $observer)
*/
protected function sendPurgeRequest($tagsPattern)
{
$uri = $this->uriFactory->create();
$socketAdapter = $this->socketAdapterFactory->create();
$servers = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS)
?: [['host' => $this->request->getHttpHost()]];
$headers = ['X-Magento-Tags-Pattern' => $tagsPattern];
$this->socketAdapter->setOptions(['timeout' => 10]);
$socketAdapter->setOptions(['timeout' => 10]);
foreach ($servers as $server) {
$port = isset($server['port']) ? $server['port'] : self::DEFAULT_PORT;
$this->uri->setScheme('http')
$uri->setScheme('http')
->setHost($server['host'])
->setPort($port);
try {
$this->socketAdapter->connect($server['host'], $port);
$this->socketAdapter->write(
$socketAdapter->connect($server['host'], $port);
$socketAdapter->write(
'PURGE',
$this->uri,
$uri,
'1.1',
$headers
);
$this->socketAdapter->close();
$socketAdapter->close();
} catch (Exception $e) {
$this->logger->critical($e->getMessage(), compact('server', 'tagsPattern'));
}
Expand Down
18 changes: 18 additions & 0 deletions app/code/Magento/CacheInvalidate/Model/SocketFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CacheInvalidate\Model;

class SocketFactory
{

/**
* @return \Zend\Http\Client\Adapter\Socket
*/
public function create()
{
return new \Zend\Http\Client\Adapter\Socket();
}
}
18 changes: 18 additions & 0 deletions app/code/Magento/CacheInvalidate/Model/UriFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CacheInvalidate\Model;

class UriFactory
{

/**
* @return \Zend\Uri\Uri
*/
public function create()
{
return new \Zend\Uri\Uri();
}
}
28 changes: 24 additions & 4 deletions app/code/Magento/CacheInvalidate/Test/Unit/Model/ObserverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class ObserverTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->configMock = $this->getMock('Magento\PageCache\Model\Config', [], [], '', false);
$this->uriFactoryMock = $this->getMock('Magento\CacheInvalidate\Model\UriFactory', [], [], '', false);
$this->uriMock = $this->getMock('\Zend\Uri\Uri', [], [], '', false);
$this->socketFactoryMock = $this->getMock('Magento\CacheInvalidate\Model\SocketFactory', [], [], '', false);
$this->socketAdapterMock = $this->getMock('\Zend\Http\Client\Adapter\Socket', [], [], '', false);
$this->deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
$this->loggerMock = $this->getMock('Magento\Framework\Cache\InvalidateLogger', [], [], '', false);
Expand All @@ -55,17 +57,17 @@ public function setUp()
['sendPurgeRequest'],
[
$this->configMock,
$this->uriMock,
$this->socketAdapterMock,
$this->uriFactoryMock,
$this->socketFactoryMock,
$this->loggerMock,
$this->deploymentConfigMock,
$this->requestMock
]
);
$this->model = new \Magento\CacheInvalidate\Model\Observer(
$this->configMock,
$this->uriMock,
$this->socketAdapterMock,
$this->uriFactoryMock,
$this->socketFactoryMock,
$this->loggerMock,
$this->deploymentConfigMock,
$this->requestMock
Expand Down Expand Up @@ -120,6 +122,12 @@ public function testFlushAllCache()

public function testSendPurgeRequestEmptyConfig()
{
$this->uriFactoryMock->expects($this->once())
->method('create')
->willReturn($this->uriMock);
$this->socketFactoryMock->expects($this->once())
->method('create')
->willReturn($this->socketAdapterMock);
$this->socketAdapterMock->expects($this->once())
->method('write')
->with('PURGE', $this->uriMock, '1.1', $this->equalTo(['X-Magento-Tags-Pattern' => 'tags']));
Expand Down Expand Up @@ -152,6 +160,12 @@ public function testSendPurgeRequestEmptyConfig()

public function testSendPurgeRequestOneServer()
{
$this->uriFactoryMock->expects($this->once())
->method('create')
->willReturn($this->uriMock);
$this->socketFactoryMock->expects($this->once())
->method('create')
->willReturn($this->socketAdapterMock);
$this->socketAdapterMock->expects($this->once())
->method('write')
->with('PURGE', $this->uriMock, '1.1', $this->equalTo(['X-Magento-Tags-Pattern' => 'tags']));
Expand Down Expand Up @@ -181,6 +195,12 @@ public function testSendPurgeRequestOneServer()

public function testSendPurgeRequestMultipleServers()
{
$this->uriFactoryMock->expects($this->once())
->method('create')
->willReturn($this->uriMock);
$this->socketFactoryMock->expects($this->once())
->method('create')
->willReturn($this->socketAdapterMock);
$this->socketAdapterMock->expects($this->exactly(2))
->method('write')
->with('PURGE', $this->uriMock, '1.1', $this->equalTo(['X-Magento-Tags-Pattern' => 'tags']));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CacheInvalidate\Test\Unit\Model;

class SocketFactoryTest extends \PHPUnit_Framework_TestCase
{

public function testCreate()
{
$factory = new \Magento\CacheInvalidate\Model\SocketFactory();
$this->assertInstanceOf('\Zend\Http\Client\Adapter\Socket', $factory->create());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CacheInvalidate\Test\Unit\Model;

class UriFactoryTest extends \PHPUnit_Framework_TestCase
{

public function testCreate()
{
$factory = new \Magento\CacheInvalidate\Model\UriFactory();
$this->assertInstanceOf('\Zend\Uri\Uri', $factory->create());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* See COPYING.txt for license details.
*/

namespace Magento\Setup\Console\Command;
namespace Magento\Deploy\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\App\DeploymentConfig;
use Symfony\Component\Console\Input\InputArgument;
use Magento\Setup\Model\ObjectManagerProvider;
use Magento\Framework\App\ObjectManagerFactory;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Validator\Locale;

/**
Expand All @@ -31,39 +31,40 @@ class DeployStaticContentCommand extends Command
const LANGUAGE_OPTION = 'languages';

/**
* Object manager provider
*
* @var ObjectManagerProvider
* @var Locale
*/
private $objectManagerProvider;
private $validator;

/**
* Deployment configuration
* Factory to get object manager
*
* @var DeploymentConfig
* @var ObjectManagerFactory
*/
private $deploymentConfig;
private $objectManagerFactory;

/**
* @var Locale
* object manager to create various objects
*
* @var ObjectManagerInterface
*
*/
private $validator;
private $objectManager;

/**
* Inject dependencies
*
* @param ObjectManagerProvider $objectManagerProvider
* @param DeploymentConfig $deploymentConfig
* @param ObjectManagerFactory $objectManagerFactory
* @param Locale $validator
* @param ObjectManagerInterface $objectManager
*/
public function __construct(
ObjectManagerProvider $objectManagerProvider,
DeploymentConfig $deploymentConfig,
Locale $validator
ObjectManagerFactory $objectManagerFactory,
Locale $validator,
ObjectManagerInterface $objectManager
) {
$this->objectManagerProvider = $objectManagerProvider;
$this->deploymentConfig = $deploymentConfig;
$this->objectManagerFactory = $objectManagerFactory;
$this->validator = $validator;
$this->objectManager = $objectManager;
parent::__construct();
}

Expand Down Expand Up @@ -96,11 +97,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->deploymentConfig->isAvailable()) {
$output->writeln("<info>You need to install the Magento application before running this utility.</info>");
return;
}

$options = $input->getOptions();

$languages = $input->getArgument(self::LANGUAGE_OPTION);
Expand All @@ -114,26 +110,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

try {
$objectManager = $this->objectManagerProvider->get();

// run the deployment logic
$filesUtil = $objectManager->create(
$filesUtil = $this->objectManager->create(
'\Magento\Framework\App\Utility\Files',
['pathToSource' => BP]
);

$objectManagerFactory = $this->objectManagerProvider->getObjectManagerFactory();

/** @var \Magento\Setup\Model\Deployer $deployer */
$deployer = $objectManager->create(
'Magento\Setup\Model\Deployer',
$deployer = $this->objectManager->create(
'Magento\Deploy\Model\Deployer',
['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]]
);
$deployer->deploy($objectManagerFactory, $languages);
$deployer->deploy($this->objectManagerFactory, $languages);

} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>>');
if ($output->isVerbose()) {
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln($e->getTraceAsString());
}
return;
Expand Down
Loading

0 comments on commit d1977f0

Please sign in to comment.