Skip to content

Commit

Permalink
Merge branch '7.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
kmadejski committed Feb 15, 2019
2 parents 9368f9f + d6c2968 commit 4f484f6
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 55 deletions.
35 changes: 28 additions & 7 deletions eZ/Bundle/EzPublishCoreBundle/Command/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ class ReindexCommand extends ContainerAwareCommand
*/
private $siteaccess;

/**
* @var string
*/
private $env;

/**
* @var bool
*/
private $isDebug;

/**
* Initialize objects required by {@see execute()}.
*
Expand All @@ -62,6 +72,8 @@ public function initialize(InputInterface $input, OutputInterface $output)
$this->searchIndexer = $this->getContainer()->get('ezpublish.spi.search.indexer');
$this->connection = $this->getContainer()->get('ezpublish.api.storage_engine.legacy.connection');
$this->logger = $this->getContainer()->get('logger');
$this->env = $this->getContainer()->getParameter('kernel.environment');
$this->isDebug = $this->getContainer()->getParameter('kernel.debug');
if (!$this->searchIndexer instanceof Indexer) {
throw new RuntimeException(
sprintf(
Expand Down Expand Up @@ -186,7 +198,7 @@ protected function indexIncrementally(InputInterface $input, OutputInterface $ou
$contentIds = explode(',', $contentIds);
$output->writeln(sprintf(
'Indexing list of content id\'s (%s)' . ($commit ? ', with commit' : ''),
count($contentIds)
\count($contentIds)
));

return $this->searchIndexer->updateSearchIndex($contentIds, $commit);
Expand Down Expand Up @@ -375,12 +387,21 @@ private function fetchIteration(Statement $stmt, $iterationCount)
*/
private function getPhpProcess(array $contentIds, $commit)
{
$process = new ProcessBuilder(array_filter([
file_exists('bin/console') ? 'bin/console' : 'app/console',
$this->siteaccess ? '--siteaccess=' . $this->siteaccess : null,
$consolePath = file_exists('bin/console') ? 'bin/console' : 'app/console';
$subProcessArgs = [
$consolePath,
'ezplatform:reindex',
'--content-ids=' . implode(',', $contentIds),
]));
'--env=' . $this->env,
];
if ($this->siteaccess) {
$subProcessArgs[] = '--siteaccess=' . $this->siteaccess;
}
if (!$this->isDebug) {
$subProcessArgs[] = '--no-debug';
}

$process = new ProcessBuilder($subProcessArgs);
$process->setTimeout(null);
$process->setPrefix($this->getPhpPath());

Expand Down Expand Up @@ -421,8 +442,8 @@ private function getNumberOfCPUCores()
// Linux (and potentially Windows with linux sub systems)
$cpuinfo = file_get_contents('/proc/cpuinfo');
preg_match_all('/^processor/m', $cpuinfo, $matches);
$cores = count($matches[0]);
} elseif (DIRECTORY_SEPARATOR === '\\') {
$cores = \count($matches[0]);
} elseif (\DIRECTORY_SEPARATOR === '\\') {
// Windows
if (($process = @popen('wmic cpu get NumberOfCores', 'rb')) !== false) {
fgets($process);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\Resolver;

use Liip\ImagineBundle\Binary\BinaryInterface;
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface;

class RelativeResolver implements ResolverInterface
{
/**
* @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface
*/
private $resolver;

/**
* @param \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface $resolver
*/
public function __construct(ResolverInterface $resolver)
{
$this->resolver = $resolver;
}

/**
* {@inheritdoc}
*/
public function isStored($path, $filter)
{
return $this->resolver->isStored($path, $filter);
}

/**
* {@inheritdoc}
*/
public function resolve($path, $filter)
{
return $this->rewriteUrl($this->resolver->resolve($path, $filter));
}

/**
* {@inheritdoc}
*/
public function store(BinaryInterface $binary, $path, $filter)
{
return $this->resolver->store($binary, $path, $filter);
}

/**
* {@inheritdoc}
*/
public function remove(array $paths, array $filters)
{
return $this->resolver->remove($paths, $filters);
}

/**
* Returns relative image path.
*
* @param $url string
* @return string
*/
protected function rewriteUrl($url)
{
return parse_url($url, PHP_URL_PATH);
}
}
78 changes: 78 additions & 0 deletions eZ/Bundle/EzPublishCoreBundle/Imagine/Cache/ResolverFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Bundle\EzPublishCoreBundle\Imagine\Cache;

use eZ\Publish\Core\MVC\ConfigResolverInterface;
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface;

class ResolverFactory
{
/**
* @var \eZ\Publish\Core\MVC\ConfigResolverInterface
*/
private $configResolver;

/**
* @var \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface
*/
private $resolver;

/**
* @var string|null
*/
private $resolverDecoratorClass;

/**
* @var string
*/
private $proxyResolverClass;

/**
* @var string
*/
private $relativeResolverClass;

/**
* @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver
* @param \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface $resolver
* @param string $proxyResolverClass
* @param string $relativeResolverClass
*/
public function __construct(
ConfigResolverInterface $configResolver,
ResolverInterface $resolver,
$proxyResolverClass,
$relativeResolverClass
) {
$this->configResolver = $configResolver;
$this->resolver = $resolver;
$this->proxyResolverClass = $proxyResolverClass;
$this->relativeResolverClass = $relativeResolverClass;
}

/**
* @return \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface
*/
public function createCacheResolver()
{
$imageHost = $this->configResolver->hasParameter('image_host') ?
$this->configResolver->getParameter('image_host') :
'';

if ($imageHost === '') {
return $this->resolver;
}

if ($imageHost === '/') {
$this->resolverDecoratorClass = $this->relativeResolverClass;
} else {
$this->resolverDecoratorClass = $this->proxyResolverClass;
}

return new $this->resolverDecoratorClass($this->resolver, [$imageHost]);
}
}
44 changes: 0 additions & 44 deletions eZ/Bundle/EzPublishCoreBundle/Imagine/ResolverFactory.php

This file was deleted.

11 changes: 7 additions & 4 deletions eZ/Bundle/EzPublishCoreBundle/Resources/config/image.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
parameters:
ezpublish.image_alias.imagine.binary_loader.class: eZ\Bundle\EzPublishCoreBundle\Imagine\BinaryLoader
ezpublish.image_alias.imagine.decorated_cache_resolver_factory.class: eZ\Bundle\EzPublishCoreBundle\Imagine\ResolverFactory
ezpublish.image_alias.imagine.cache_resolver_decorator_factory.class: eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\ResolverFactory
ezpublish.image_alias.imagine.cache_resolver_decorator_relative.class: eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\Resolver\RelativeResolver
ezpublish.image_alias.imagine.cache_resolver_decorator_proxy.class: Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver
ezpublish.image_alias.imagine.cache_resolver.class: eZ\Bundle\EzPublishCoreBundle\Imagine\IORepositoryResolver
ezpublish.image_alias.imagine.cache_resolver_decorator.class: Liip\ImagineBundle\Imagine\Cache\Resolver\ProxyResolver
ezpublish.image_alias.imagine.cache.alias_generator_decorator.class: eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\AliasGeneratorDecorator
Expand Down Expand Up @@ -84,14 +86,15 @@ services:
- { name: liip_imagine.cache.resolver, resolver: ezpublish }

ezpublish.image_alias.imagine.cache_resolver_decorator_factory:
class: '%ezpublish.image_alias.imagine.decorated_cache_resolver_factory.class%'
class: '%ezpublish.image_alias.imagine.cache_resolver_decorator_factory.class%'
arguments:
- '@ezpublish.config.resolver'
- '@ezpublish.image_alias.imagine.cache_resolver_decorator.inner'
- '%ezpublish.image_alias.imagine.cache_resolver_decorator.class%'
- '%ezpublish.image_alias.imagine.cache_resolver_decorator_proxy.class%'
- '%ezpublish.image_alias.imagine.cache_resolver_decorator_relative.class%'

ezpublish.image_alias.imagine.cache_resolver_decorator:
class: '%ezpublish.image_alias.imagine.cache_resolver_decorator.class%'
class: Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface
factory: 'ezpublish.image_alias.imagine.cache_resolver_decorator_factory:createCacheResolver'
decorates: ezpublish.image_alias.imagine.cache_resolver

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Bundle\EzPublishCoreBundle\Tests\Imagine\Cache\Resolver;

use eZ\Bundle\EzPublishCoreBundle\Imagine\Cache\Resolver\RelativeResolver;
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface;
use PHPUnit\Framework\TestCase;

class RelativeResolverTest extends TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface
*/
private $liipResolver;

protected function setUp()
{
parent::setUp();
$this->liipResolver = $this->getMockBuilder(ResolverInterface::class)->getMock();
}

public function testResolve()
{
$resolver = new RelativeResolver($this->liipResolver);

$path = '7/4/2/0/247-1-eng-GB/test.png';
$filter = 'big';

$absolute = 'http://ez.no/var/site/storage/images/_aliases/big/7/4/2/0/247-1-eng-GB/test.png';
$expected = '/var/site/storage/images/_aliases/big/7/4/2/0/247-1-eng-GB/test.png';

$this->liipResolver
->expects($this->once())
->method('resolve')
->with($path, $filter)
->willReturn($absolute);

$this->assertSame($expected, $resolver->resolve($path, $filter));
}
}
Loading

0 comments on commit 4f484f6

Please sign in to comment.