Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.10' into 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Sep 28, 2016
2 parents bf325b0 + 86d9489 commit 8117e09
Show file tree
Hide file tree
Showing 261 changed files with 12,439 additions and 2,071 deletions.
12 changes: 12 additions & 0 deletions UPGRADE-1.10.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ oro_email.email_address.entity_manager:

####LocaleBundle
- `oro_locale.repository.localization` inherits `oro_entity.abstract_repository`

####DatagridBundle:
- Class `Oro\Bundle\DataGridBundle\Datasource\Orm\OrmDatasource.php`
- construction signature was changed now it takes next arguments:
`ConfigProcessorInterface` $processor,
`EventDispatcherInterface` $eventDispatcher,
`ParameterBinderInterface` $parameterBinder,
`QueryHintResolver` $queryHintResolver
- Added class `Oro\Bundle\DataGridBundle\Datasource\Orm\Configs\YamlProcessor`
- Added interface `Oro\Bundle\DataGridBundle\Datasource\Orm\Configs\ConfigProcessorInterface`
- `Oro\Bundle\DataGridBundle\Datasource\Orm\OrmDatasource::getParameterBinder` was deprecated
- `Oro\Bundle\DataGridBundle\Datasource\ParameterBinderAwareInterface::getParameterBinder` was deprecated
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"composer/composer": "1.2.*",
"akeneo/batch-bundle": "0.4.2",
"nesbot/Carbon": "1.8.*",
"monolog/monolog": "1.8.*",
"monolog/monolog": "^1.17",
"ocramius/proxy-manager": "~0.4",
"knplabs/knp-gaufrette-bundle": "0.1.*",
"oro/doctrine-extensions": "1.0.*",
Expand Down
26 changes: 14 additions & 12 deletions src/Oro/Bundle/ApiBundle/ApiDoc/RestDocHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Oro\Bundle\ApiBundle\Config\DescriptionsConfigExtra;
use Oro\Bundle\ApiBundle\Config\EntityDefinitionConfig;
use Oro\Bundle\ApiBundle\Config\StatusCodesConfig;
use Oro\Bundle\ApiBundle\Filter\ComparisonFilter;
use Oro\Bundle\ApiBundle\Filter\FieldAwareFilterInterface;
use Oro\Bundle\ApiBundle\Filter\FilterCollection;
use Oro\Bundle\ApiBundle\Filter\StandaloneFilter;
use Oro\Bundle\ApiBundle\Filter\StandaloneFilterWithDefaultValue;
Expand Down Expand Up @@ -294,18 +294,20 @@ protected function addFilters(ApiDoc $annotation, FilterCollection $filters, Ent
}
}

if ($filter instanceof ComparisonFilter && $metadata->hasAssociation($filter->getField())) {
$targetClassNames = $metadata->getAssociation($filter->getField())
->getAcceptableTargetClassNames();
$targetEntityTypes = [];
foreach ($targetClassNames as $targetClassName) {
$targetEntityType = $this->getEntityType($targetClassName);
if ($targetEntityType) {
$targetEntityTypes[] = $targetEntityType;
if ($filter instanceof FieldAwareFilterInterface) {
$association = $metadata->getAssociation($filter->getField());
if (null !== $association && !DataType::isAssociationAsField($association->getDataType())) {
$targetClassNames = $association->getAcceptableTargetClassNames();
$targetEntityTypes = [];
foreach ($targetClassNames as $targetClassName) {
$targetEntityType = $this->getEntityType($targetClassName);
if ($targetEntityType) {
$targetEntityTypes[] = $targetEntityType;
}
}
if (!empty($targetEntityTypes)) {
$options['relation'] = implode(',', $targetEntityTypes);
}
}
if (!empty($targetEntityTypes)) {
$options['relation'] = implode(',', $targetEntityTypes);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Oro/Bundle/ApiBundle/Command/AbstractDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ protected function resolveEntityClass($entityName, $version, RequestType $reques

/** @var ResourcesProvider $resourcesProvider */
$resourcesProvider = $this->getContainer()->get('oro_api.resources_provider');
if (!$resourcesProvider->isResourceAccessible($entityClass, $version, $requestType)) {
if (!$resourcesProvider->isResourceKnown($entityClass, $version, $requestType)) {
throw new \RuntimeException(
sprintf('The "%s" entity is not accessible through Data API.', $entityClass)
sprintf('The "%s" entity is not configured to be used in Data API.', $entityClass)
);
}

Expand Down
38 changes: 35 additions & 3 deletions src/Oro/Bundle/ApiBundle/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Oro\Bundle\ApiBundle\Request\RequestType;
use Oro\Bundle\ApiBundle\Request\ValueNormalizer;
use Oro\Bundle\ApiBundle\Request\Version;
use Oro\Bundle\ApiBundle\Util\ValueNormalizerUtil;

class DumpCommand extends AbstractDebugCommand
{
Expand Down Expand Up @@ -154,7 +155,8 @@ public function dumpResources(InputInterface $input, OutputInterface $output)
);
if ($isSubresourcesRequested) {
$subresourcesText = $this->getEntitySubresourcesText(
$subresourcesProvider->getSubresources($resource->getEntityClass(), $version, $requestType)
$subresourcesProvider->getSubresources($resource->getEntityClass(), $version, $requestType),
$requestType
);
if ($subresourcesText) {
$output->writeln($subresourcesText);
Expand All @@ -165,17 +167,28 @@ public function dumpResources(InputInterface $input, OutputInterface $output)

/**
* @param ApiResourceSubresources $entitySubresources
* @param RequestType $requestType
*
* @return string
*/
protected function getEntitySubresourcesText(ApiResourceSubresources $entitySubresources)
{
protected function getEntitySubresourcesText(
ApiResourceSubresources $entitySubresources,
$requestType
) {
$result = '';
$subresources = $entitySubresources->getSubresources();
if (!empty($subresources)) {
$result .= ' Sub-resources:';
foreach ($subresources as $associationName => $subresource) {
$targetEntityType = $this->resolveEntityType($subresource->getTargetClassName(), $requestType);
$acceptableTargetEntityTypes = [];
foreach ($subresource->getAcceptableTargetClassNames() as $className) {
$acceptableTargetEntityTypes[] = $this->resolveEntityType($className, $requestType);
}
$result .= sprintf("\n <comment>%s</comment>", $associationName);
$result .= "\n Type: " . ($subresource->isCollection() ? 'to-many' : 'to-one');
$result .= "\n Target: " . $targetEntityType;
$result .= "\n Acceptable Targets: " . implode(', ', $acceptableTargetEntityTypes);
$subresourceExcludedActions = $subresource->getExcludedActions();
if (!empty($subresourceExcludedActions)) {
$result .= "\n Excluded Actions: " . implode(', ', $subresourceExcludedActions);
Expand Down Expand Up @@ -234,4 +247,23 @@ protected function convertResourceAttributesToString(array $attributes)

return $result;
}

/**
* @param string|null $entityClass
* @param RequestType $requestType
*
* @return string|null
*/
protected function resolveEntityType($entityClass, RequestType $requestType)
{
if (!$entityClass) {
return null;
}

return ValueNormalizerUtil::convertToEntityType(
$this->getContainer()->get('oro_api.value_normalizer'),
$entityClass,
$requestType
);
}
}
12 changes: 2 additions & 10 deletions src/Oro/Bundle/ApiBundle/Command/DumpConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ protected function getConfig($entityClass, $version, RequestType $requestType, a
$config = $configProvider->getConfig($entityClass, $version, $requestType, $extras);

return [
'oro_api' => [
'entities' => [
$entityClass => $this->convertConfigToArray($config)
]
]
$entityClass => $this->convertConfigToArray($config)
];
}

Expand All @@ -210,11 +206,7 @@ protected function getRelationConfig($entityClass, $version, RequestType $reques
$config = $configProvider->getRelationConfig($entityClass, $version, $requestType, $extras);

return [
'oro_api' => [
'relations' => [
$entityClass => $this->convertConfigToArray($config)
]
]
$entityClass => $this->convertConfigToArray($config)
];
}

Expand Down
6 changes: 1 addition & 5 deletions src/Oro/Bundle/ApiBundle/Command/DumpMetadataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ protected function getMetadata($entityClass, $version, RequestType $requestType,
);

return [
'oro_api' => [
'metadata' => [
$entityClass => null !== $metadata ? $metadata->toArray() : null
]
]
$entityClass => null !== $metadata ? $metadata->toArray() : null
];
}
}
15 changes: 15 additions & 0 deletions src/Oro/Bundle/ApiBundle/Config/ConfigAccessorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Oro\Bundle\ApiBundle\Config;

interface ConfigAccessorInterface
{
/**
* Gets configuration of an entity.
*
* @param string $className
*
* @return EntityDefinitionConfig|null
*/
public function getConfig($className);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public function configure(NodeBuilder $node)
/** @var NodeBuilder $actionNode */
$actionNode = $node->end()
->useAttributeAsKey('name')
->beforeNormalization()
->always(function ($value) {
return false === $value
? array_fill_keys($this->permissibleActions, false)
: $value;
})
->end()
->validate()
->always(function ($value) {
$unknownActions = array_diff(array_keys($value), $this->permissibleActions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,45 @@ protected function configureFieldNode(NodeBuilder $node)
//$parentNode->ignoreExtraKeys(false); @todo: uncomment after migration to Symfony 2.8+
$this->callConfigureCallbacks($node, $sectionName);
$this->addPreProcessCallbacks($parentNode, $sectionName);
$this->addPostProcessCallbacks($parentNode, $sectionName);
$this->addPostProcessCallbacks(
$parentNode,
$sectionName,
function ($value) {
return $this->postProcessFieldConfig($value);
}
);

$node
->booleanNode(FilterFieldConfig::EXCLUDE)->end()
->scalarNode(FilterFieldConfig::DESCRIPTION)->cannotBeEmpty()->end()
->scalarNode(FilterFieldConfig::PROPERTY_PATH)->cannotBeEmpty()->end()
->scalarNode(FilterFieldConfig::TYPE)->cannotBeEmpty()->end()
->arrayNode(FilterFieldConfig::OPTIONS)
->useAttributeAsKey('name')
->performNoDeepMerging()
->prototype('variable')->end()
->end()
->arrayNode(FilterFieldConfig::OPERATORS)
->prototype('scalar')->end()
->end()
->scalarNode(FilterFieldConfig::DATA_TYPE)->cannotBeEmpty()->end()
->booleanNode(FilterFieldConfig::ALLOW_ARRAY)->end();
}

/**
* @param array $config
*
* @return array
*/
protected function postProcessFieldConfig(array $config)
{
if (empty($config[FilterFieldConfig::OPTIONS])) {
unset($config[FilterFieldConfig::OPTIONS]);
}
if (empty($config[FilterFieldConfig::OPERATORS])) {
unset($config[FilterFieldConfig::OPERATORS]);
}

return $config;
}
}
4 changes: 3 additions & 1 deletion src/Oro/Bundle/ApiBundle/Config/FieldConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public function hasPropertyPath();
/**
* Gets the path of the field value.
*
* @param string|null $defaultValue
*
* @return string|null
*/
public function getPropertyPath();
public function getPropertyPath($defaultValue = null);

/**
* Sets the path of the field value.
Expand Down
87 changes: 87 additions & 0 deletions src/Oro/Bundle/ApiBundle/Config/FilterFieldConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ class FilterFieldConfig implements FieldConfigInterface
/** the path of the field value */
const PROPERTY_PATH = EntityDefinitionFieldConfig::PROPERTY_PATH;

/** the type of the filter */
const TYPE = 'type';

/** the filter options */
const OPTIONS = 'options';

/** a list of operators supported by the filter */
const OPERATORS = 'operators';

/** the data type of the filter value */
const DATA_TYPE = EntityDefinitionFieldConfig::DATA_TYPE;

Expand Down Expand Up @@ -54,6 +63,84 @@ public function __clone()
$this->items = ConfigUtil::cloneItems($this->items);
}

/**
* Gets the filter type.
*
* @return string|null
*/
public function getType()
{
return array_key_exists(self::TYPE, $this->items)
? $this->items[self::TYPE]
: null;
}

/**
* Sets the filter type.
*
* @param string|null $type
*/
public function setType($type)
{
if ($type) {
$this->items[self::TYPE] = $type;
} else {
unset($this->items[self::TYPE]);
}
}

/**
* Gets the filter options.
*
* @return array|null
*/
public function getOptions()
{
return array_key_exists(self::OPTIONS, $this->items)
? $this->items[self::OPTIONS]
: null;
}

/**
* Sets the filter options.
*
* @param array|null $options
*/
public function setOptions($options)
{
if ($options) {
$this->items[self::OPTIONS] = $options;
} else {
unset($this->items[self::OPTIONS]);
}
}

/**
* Gets a list of operators supported by the filter.
*
* @return string[]|null
*/
public function getOperators()
{
return array_key_exists(self::OPERATORS, $this->items)
? $this->items[self::OPERATORS]
: null;
}

/**
* Sets a list of operators supported by the filter.
*
* @param string[]|null $operators
*/
public function setOperators($operators)
{
if ($operators) {
$this->items[self::OPERATORS] = $operators;
} else {
unset($this->items[self::OPERATORS]);
}
}

/**
* Indicates whether the "array allowed" flag is set explicitly.
*
Expand Down
8 changes: 5 additions & 3 deletions src/Oro/Bundle/ApiBundle/Config/Traits/FieldConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ public function hasPropertyPath()
/**
* Gets the path of the field value.
*
* @param string|null $defaultValue
*
* @return string|null
*/
public function getPropertyPath()
public function getPropertyPath($defaultValue = null)
{
return array_key_exists(FieldConfig::PROPERTY_PATH, $this->items)
return !empty($this->items[FieldConfig::PROPERTY_PATH])
? $this->items[FieldConfig::PROPERTY_PATH]
: null;
: $defaultValue;
}

/**
Expand Down
Loading

0 comments on commit 8117e09

Please sign in to comment.