Skip to content

Commit

Permalink
Merge pull request #2687 from laboro/fix/BAP-10013_1.12
Browse files Browse the repository at this point in the history
BAP-10013: A plural alias for "Extend\Entity\EV_Prod_Inventory_Status…
  • Loading branch information
vsoroka authored Sep 9, 2016
2 parents e19c991 + c757bc8 commit 210441c
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Oro\Component\Routing\Resolver\RouteOptionsResolverInterface;

use Oro\Bundle\ActivityBundle\EntityConfig\ActivityScope;
use Oro\Bundle\EntityBundle\Exception\EntityAliasNotFoundException;
use Oro\Bundle\EntityBundle\ORM\EntityAliasResolver;
use Oro\Bundle\EntityConfigBundle\Config\ConfigInterface;
use Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider;
Expand Down Expand Up @@ -71,12 +72,16 @@ public function resolve(Route $route, RouteCollectionAccessor $routes)
protected function getSupportedActivities()
{
if (null === $this->supportedActivities) {
$this->supportedActivities = array_map(
$this->supportedActivities = array_filter(array_map(
function (ConfigInterface $config) {
// convert to entity alias
return $this->entityAliasResolver->getPluralAlias(
$config->getId()->getClassName()
);
try {
// convert to entity alias
return $this->entityAliasResolver->getPluralAlias(
$config->getId()->getClassName()
);
} catch (EntityAliasNotFoundException $e) {
return false;
}
},
$this->groupingConfigProvider->filter(
function (ConfigInterface $config) {
Expand All @@ -88,7 +93,7 @@ function (ConfigInterface $config) {
&& in_array(ActivityScope::GROUP_ACTIVITY, $groups, true);
}
)
);
));
}

return $this->supportedActivities;
Expand Down
2 changes: 2 additions & 0 deletions src/Oro/Bundle/ApiBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ services:
- '@oro_api.entity_alias_loader'
- '@oro_api.entity_alias_cache'
- %kernel.debug%
calls:
- [ setLogger, [ '@logger' ] ]
lazy: true

oro_api.entity_alias_cache:
Expand Down
3 changes: 3 additions & 0 deletions src/Oro/Bundle/EmailBundle/Cache/EntityCacheClearer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Symfony\Component\Filesystem\Filesystem;

/**
* @deprecated since 1.9. Removing classes breaks doctrine metadata functionality
*/
class EntityCacheClearer implements CacheClearerInterface
{
/**
Expand Down
3 changes: 1 addition & 2 deletions src/Oro/Bundle/EmailBundle/Entity/MailboxProcessSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Doctrine\ORM\Mapping as ORM;

use Oro\Bundle\EmailBundle\Entity\Mailbox;
use Oro\Bundle\EmailBundle\Form\Model\ExtendMailboxProcessSettings;

/**
* @ORM\Table(
Expand All @@ -15,7 +14,7 @@
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string", length=30)
*/
abstract class MailboxProcessSettings extends ExtendMailboxProcessSettings
abstract class MailboxProcessSettings
{
/**
* @ORM\Id
Expand Down

This file was deleted.

8 changes: 3 additions & 5 deletions src/Oro/Bundle/EmailBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ services:
- '@kernel'
tags:
- { name: kernel.cache_warmer, priority: 30 }
- { name: oro_entity_extend.warmer }

oro_email.entity.cache.clearer:
class: %oro_email.entity.cache.clearer.class%
deprecated: ~
arguments:
- %oro_email.entity.cache_dir%
- %oro_email.entity.proxy_name_template%
tags:
- { name: kernel.cache_clearer }

oro_email.email.cache.manager:
class: %oro_email.email.cache.manager.class%
Expand All @@ -184,9 +184,7 @@ services:
class: %oro_email.email_flag_manager_loader_selector.class%

oro_email.email_address.entity_manager:
public: false
class: Doctrine\ORM\EntityManager
factory: ['@doctrine', getManagerForClass]
parent: oro_entity.abstract_entity_manager
arguments:
- 'OroEmailBundle:EmailAddress'

Expand Down
18 changes: 16 additions & 2 deletions src/Oro/Bundle/EntityBundle/ORM/EntityAliasResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
use Oro\Bundle\EntityBundle\Provider\EntityAliasLoader;
use Oro\Bundle\EntityBundle\Provider\EntityAliasStorage;

class EntityAliasResolver
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

class EntityAliasResolver implements LoggerAwareInterface
{
use LoggerAwareTrait;

const CACHE_KEY = 'entity_aliases';

/** @var EntityAliasLoader */
Expand Down Expand Up @@ -186,7 +191,16 @@ protected function ensureAllAliasesLoaded()
} else {
$this->storage = new EntityAliasStorage();
$this->storage->setDebug($this->debug);
$this->loader->load($this->storage);
try {
$this->loader->load($this->storage);
} catch (\Exception $e) {
if ($this->logger) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
}

return;
}

$this->cache->save(self::CACHE_KEY, $this->storage);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/EntityBundle/ORM/OrmEntityClassProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getClassNames()
$result = [];
$managers = $this->managerBag->getManagers();
foreach ($managers as $om) {
$allMetadata = $this->doctrineHelper->getAllShortMetadata($om, false);
$allMetadata = $this->doctrineHelper->getAllShortMetadata($om);
foreach ($allMetadata as $metadata) {
if (!$metadata->isMappedSuperclass) {
$result[] = $metadata->name;
Expand Down
12 changes: 12 additions & 0 deletions src/Oro/Bundle/EntityBundle/Resources/config/orm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ services:
arguments:
- '@doctrine'

oro_entity.abstract_repository:
class: Doctrine\ORM\EntityRepository
factory: ['@oro_entity.doctrine_helper', getEntityRepository]
abstract: true
lazy: true

oro_entity.abstract_entity_manager:
class: Doctrine\ORM\EntityManager
factory: ['@oro_entity.doctrine_helper', getEntityManagerForClass]
abstract: true
lazy: true

oro_entity.entity_identifier_accessor:
class: %oro_entity.entity_identifier_accessor.class%
arguments:
Expand Down
4 changes: 4 additions & 0 deletions src/Oro/Bundle/EntityBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ services:
- '@oro_entity.entity_alias_loader'
- '@oro_entity.entity_alias_cache'
- %kernel.debug%
calls:
- [ setLogger, [ '@logger' ] ]
lazy: true

oro_entity.entity_alias_cache:
Expand Down Expand Up @@ -375,6 +377,8 @@ services:
- '@oro_entity.dictionary_value_list_provider'
- '@oro_entity.entity_alias_resolver'
- '@oro_entity.entity_class_name_helper'
calls:
- [ setLogger, [ '@logger' ] ]
tags:
- { name: routing.options_resolver }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
use Oro\Component\Routing\Resolver\RouteCollectionAccessor;
use Oro\Component\Routing\Resolver\RouteOptionsResolverInterface;

use Oro\Bundle\EntityBundle\Exception\EntityAliasNotFoundException;
use Oro\Bundle\EntityBundle\ORM\EntityAliasResolver;
use Oro\Bundle\EntityBundle\Provider\ChainDictionaryValueListProvider;
use Oro\Bundle\EntityBundle\Tools\EntityClassNameHelper;

class DictionaryEntityRouteOptionsResolver implements RouteOptionsResolverInterface
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

class DictionaryEntityRouteOptionsResolver implements RouteOptionsResolverInterface, LoggerAwareInterface
{
use LoggerAwareTrait;

const ROUTE_GROUP = 'dictionary_entity';
const ENTITY_ATTRIBUTE = 'dictionary';
const ENTITY_PLACEHOLDER = '{dictionary}';
Expand Down Expand Up @@ -74,10 +80,16 @@ protected function getSupportedEntities()

$this->supportedEntities = [];
foreach ($entities as $className) {
$this->supportedEntities[] = [
$this->entityAliasResolver->getPluralAlias($className),
$this->entityClassNameHelper->getUrlSafeClassName($className)
];
try {
$this->supportedEntities[] = [
$this->entityAliasResolver->getPluralAlias($className),
$this->entityClassNameHelper->getUrlSafeClassName($className)
];
} catch (EntityAliasNotFoundException $e) {
if ($this->logger) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testGetClassNames()

$doctrineHelper->expects($this->once())
->method('getAllShortMetadata')
->with($this->identicalTo($em), false)
->with($this->identicalTo($em))
->willReturn(
[
new ShortClassMetadata('Test\Entity1'),
Expand Down
62 changes: 62 additions & 0 deletions src/Oro/Bundle/EntityExtendBundle/Cache/CacheWarmerAggregate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Oro\Bundle\EntityExtendBundle\Cache;

use Oro\Bundle\InstallerBundle\CommandExecutor;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate as BaseCacheWarmerAggregate;

class CacheWarmerAggregate implements CacheWarmerInterface
{
/** @var BaseCacheWarmerAggregate */
private $baseCacheWarmerAggregate;

/** @var CacheWarmerInterface[] Warmers required for extend bundle */
private $warmers;

/**
* @param BaseCacheWarmerAggregate $baseCacheWarmerAggregate
*/
public function __construct(BaseCacheWarmerAggregate $baseCacheWarmerAggregate)
{
$this->baseCacheWarmerAggregate = $baseCacheWarmerAggregate;
}

/** {@inheritdoc} */
public function enableOptionalWarmers()
{
$this->baseCacheWarmerAggregate->enableOptionalWarmers();
}

/** {@inheritdoc} */
public function isOptional()
{
return $this->baseCacheWarmerAggregate->isOptional();
}

/**
* {@inheritdoc}
*
* Do not warmup caches if extend caches are not up to date
*/
public function warmUp($cacheDir)
{
if (CommandExecutor::isCurrentCommand('oro:entity-extend:cache:', true)) {
foreach ($this->warmers as $warmer) {
$warmer->warmUp($cacheDir);
}

return;
}

$this->baseCacheWarmerAggregate->warmUp($cacheDir);
}

/**
* @param CacheWarmerInterface $cacheWarmer
*/
public function addWarmer(CacheWarmerInterface $cacheWarmer)
{
$this->warmers[] = $cacheWarmer;
}
}
22 changes: 1 addition & 21 deletions src/Oro/Bundle/EntityExtendBundle/Command/CacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,29 +176,9 @@ protected function warmupEntityAliasesCache(OutputInterface $output)
* Sets class aliases for extended entities.
*
* @param string $cacheDir The cache directory
*
* @throws \ReflectionException
*/
protected function setClassAliases($cacheDir)
{
$aliases = ExtendClassLoadingUtils::getAliases($cacheDir);
foreach ($aliases as $className => $alias) {
if (class_exists($className)) {
if (class_exists($alias, false)) {
throw new \ReflectionException(
sprintf(
'The alias "%1$s" for the class "%2$s" cannot be registered '
. 'because the class "%1$s" is already loaded. '
. 'This may happen if this class or a derived class '
. 'is used in EntityConfigDumperExtension or EntityGeneratorExtension.',
$alias,
$className
)
);
}

class_alias($className, $alias);
}
}
ExtendClassLoadingUtils::setAliases($cacheDir);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Oro\Bundle\EntityExtendBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class WarmerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('oro_entity_extend.cache_warmer')) {
return;
}

$taggedServices = $container->findTaggedServiceIds('oro_entity_extend.warmer');
if (!$taggedServices) {
return;
}

$definition = $container->getDefinition('oro_entity_extend.cache_warmer');

foreach ($taggedServices as $id => $attributes) {
$definition->addMethodCall('addWarmer', [new Reference($id)]);
}
}
}
Loading

0 comments on commit 210441c

Please sign in to comment.