diff --git a/CHANGELOG-1.5.md b/CHANGELOG-1.5.md index c712b74bfab1..2ddcdb5a58e0 100644 --- a/CHANGELOG-1.5.md +++ b/CHANGELOG-1.5.md @@ -12,6 +12,9 @@ - Removed `Pim\Bundle\EnrichBundle\AbstractController\AbstractDoctrineController` and `Pim\Bundle\EnrichBundle\AbstractController\AbstractController`. - Change constructor of `Pim\Bundle\EnrichBundle\Filter\ProductEditDataFilter` to add `Pim\Bundle\CatalogBundle\Filter\CollectionFilterInterface` and to remove `Oro\Bundle\SecurityBundle\SecurityFacade`, `Pim\Bundle\CatalogBundle\Filter\ObjectFilterInterface`, `Pim\Component\Catalog\Repository\AttributeRepositoryInterface`, `Pim\Component\Catalog\Repository\LocaleRepositoryInterface` and `Pim\Component\Catalog\Repository\ChannelRepositoryInterface` - Change constructor of `Pim\Bundle\EnrichBundle\MassEditAction\Operation\EditCommonAttributes` to add `Pim\Bundle\CatalogBundle\Filter\CollectionFilterInterface` +- Change constructor of `Pim\Bundle\EnrichBundle\Controller\AttributeController` to add `Pim\Bundle\CatalogBundle\Factory\AttributeFactory` +- Change constructor of `Pim\Bundle\EnrichBundle\Controller\AttributeOptionController` to add `Pim\Bundle\CatalogBundle\Repository\AttributeRepositoryInterface` +- Change constructor of `Pim\Bundle\TransformBundle\Transformer\AttributeTransformer` to remove `Pim\Bundle\CatalogBundle\Manager\AttributeManager` and add `Pim\Bundle\CatalogBundle\Factory\AttributeFactory` # 1.5.0-ALPHA1 (2016-01-26) diff --git a/spec/Pim/Bundle/CatalogBundle/Manager/AttributeManagerSpec.php b/spec/Pim/Bundle/CatalogBundle/Manager/AttributeManagerSpec.php index 48bcfde85607..f2e713a82150 100644 --- a/spec/Pim/Bundle/CatalogBundle/Manager/AttributeManagerSpec.php +++ b/spec/Pim/Bundle/CatalogBundle/Manager/AttributeManagerSpec.php @@ -29,17 +29,6 @@ function let( ); } - function it_instantiates_an_attribute($factory, AttributeInterface $attribute) - { - $factory->createAttribute(null)->willReturn($attribute); - $this->createAttribute()->shouldReturn($attribute); - } - - function it_provides_the_attribute_class_used() - { - $this->getAttributeClass()->shouldReturn(self::ATTRIBUTE_CLASS); - } - function it_provides_the_list_of_attribute_types($registry) { $registry->getAliases()->willReturn(['foo', 'bar']); diff --git a/src/Pim/Bundle/CatalogBundle/Manager/AttributeManager.php b/src/Pim/Bundle/CatalogBundle/Manager/AttributeManager.php index 3982d8d136ec..d313d9fd5622 100644 --- a/src/Pim/Bundle/CatalogBundle/Manager/AttributeManager.php +++ b/src/Pim/Bundle/CatalogBundle/Manager/AttributeManager.php @@ -56,32 +56,6 @@ public function __construct( $this->factory = $factory; } - /** - * Create an attribute - * - * @param string $type - * - * @return AttributeInterface - * - * @deprecated will be removed in 1.6, please use AttributeFactory::createAttribute - */ - public function createAttribute($type = null) - { - return $this->factory->createAttribute($type); - } - - /** - * Get the attribute FQCN - * - * @return string - * - * @deprecated will be removed in 1.6 please use %pim_catalog.entity.attribute.class% - */ - public function getAttributeClass() - { - return $this->attributeClass; - } - /** * Get a list of available attribute types * @@ -116,26 +90,4 @@ public function updateSorting(AttributeInterface $attribute, array $sorting = [] } $this->optionSaver->saveAll($attribute->getOptions()->toArray()); } - - /** - * Get an attribute or throw an exception - * - * @param int $id - * - * @throws EntityNotFoundException - * - * @return AttributeInterface - * - * @deprecated will be removed in 1.6 please use AttributeRepositoryInterface->find() - */ - public function getAttribute($id) - { - $attribute = $this->repository->find($id); - - if (null === $attribute) { - throw new EntityNotFoundException(); - } - - return $attribute; - } } diff --git a/src/Pim/Bundle/EnrichBundle/Controller/AttributeController.php b/src/Pim/Bundle/EnrichBundle/Controller/AttributeController.php index c9d24b67d6e5..731969e4ca4c 100644 --- a/src/Pim/Bundle/EnrichBundle/Controller/AttributeController.php +++ b/src/Pim/Bundle/EnrichBundle/Controller/AttributeController.php @@ -7,6 +7,7 @@ use Akeneo\Component\StorageUtils\Saver\SaverInterface; use Oro\Bundle\SecurityBundle\Annotation\AclAncestor; use Pim\Bundle\CatalogBundle\AttributeType\AttributeTypes; +use Pim\Bundle\CatalogBundle\Factory\AttributeFactory; use Pim\Bundle\CatalogBundle\Manager\AttributeManager; use Pim\Bundle\CatalogBundle\Manager\AttributeOptionManager; use Pim\Bundle\CatalogBundle\Repository\GroupRepositoryInterface; @@ -98,6 +99,7 @@ class AttributeController * @param HandlerInterface $attributeHandler * @param Form $attributeForm * @param AttributeManager $attributeManager + * @param AttributeFactory $attributeFactory * @param AttributeOptionManager $optionManager * @param LocaleRepositoryInterface $localeRepository * @param VersionManager $versionManager @@ -116,6 +118,7 @@ public function __construct( HandlerInterface $attributeHandler, Form $attributeForm, AttributeManager $attributeManager, + AttributeFactory $attributeFactory, AttributeOptionManager $optionManager, LocaleRepositoryInterface $localeRepository, VersionManager $versionManager, @@ -133,6 +136,7 @@ public function __construct( $this->attributeHandler = $attributeHandler; $this->attributeForm = $attributeForm; $this->attributeManager = $attributeManager; + $this->attributeFactory = $attributeFactory; $this->optionManager = $optionManager; $this->localeRepository = $localeRepository; $this->versionManager = $versionManager; @@ -176,7 +180,7 @@ public function createAction(Request $request) return new RedirectResponse($this->router->generate('pim_enrich_attribute_index')); } - $attribute = $this->attributeManager->createAttribute($attributeType); + $attribute = $this->attributeFactory->createAttribute($attributeType); if ($this->attributeHandler->process($attribute)) { $this->request->getSession()->getFlashBag() @@ -356,7 +360,7 @@ protected function findAttributeOr404($id) if (null === $attribute) { throw new NotFoundHttpException( - sprintf('%s entity not found', $this->attributeManager->getAttributeClass()) + sprintf('%s entity not found', $this->attributeRepository->getClassName()) ); } diff --git a/src/Pim/Bundle/EnrichBundle/Controller/AttributeOptionController.php b/src/Pim/Bundle/EnrichBundle/Controller/AttributeOptionController.php index 96a2b308f319..d3465ecff1ea 100644 --- a/src/Pim/Bundle/EnrichBundle/Controller/AttributeOptionController.php +++ b/src/Pim/Bundle/EnrichBundle/Controller/AttributeOptionController.php @@ -13,6 +13,7 @@ use Pim\Bundle\CatalogBundle\Manager\AttributeOptionManager; use Pim\Component\Catalog\Model\AttributeInterface; use Pim\Component\Catalog\Model\AttributeOptionInterface; +use Pim\Component\Catalog\Repository\AttributeRepositoryInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\JsonResponse; @@ -44,6 +45,9 @@ class AttributeOptionController /** @var AttributeManager */ protected $attributeManager; + /** @var AttributeRepositoryInterface */ + protected $attributeRepository; + /** @var AttributeOptionManager */ protected $optionManager; @@ -56,14 +60,15 @@ class AttributeOptionController /** * Constructor * - * @param NormalizerInterface $normalizer - * @param EntityManager $entityManager - * @param FormFactoryInterface $formFactory - * @param ViewHandlerInterface $viewHandler - * @param AttributeManager $attributeManager - * @param AttributeOptionManager $optionManager - * @param SaverInterface $optionSaver - * @param RemoverInterface $optionRemover + * @param NormalizerInterface $normalizer + * @param EntityManager $entityManager + * @param FormFactoryInterface $formFactory + * @param ViewHandlerInterface $viewHandler + * @param AttributeManager $attributeManager + * @param AttributeOptionManager $optionManager + * @param SaverInterface $optionSaver + * @param RemoverInterface $optionRemover + * @param AttributeRepositoryInterface $attributeRepository */ public function __construct( NormalizerInterface $normalizer, @@ -73,16 +78,18 @@ public function __construct( AttributeManager $attributeManager, AttributeOptionManager $optionManager, SaverInterface $optionSaver, - RemoverInterface $optionRemover + RemoverInterface $optionRemover, + AttributeRepositoryInterface $attributeRepository ) { - $this->normalizer = $normalizer; - $this->entityManager = $entityManager; - $this->formFactory = $formFactory; - $this->viewHandler = $viewHandler; - $this->attributeManager = $attributeManager; - $this->optionManager = $optionManager; - $this->optionRemover = $optionRemover; - $this->optionSaver = $optionSaver; + $this->normalizer = $normalizer; + $this->entityManager = $entityManager; + $this->formFactory = $formFactory; + $this->viewHandler = $viewHandler; + $this->attributeManager = $attributeManager; + $this->optionManager = $optionManager; + $this->optionRemover = $optionRemover; + $this->optionSaver = $optionSaver; + $this->attributeRepository = $attributeRepository; } /** @@ -228,7 +235,7 @@ protected function manageFormSubmission(AttributeOptionInterface $attributeOptio protected function findAttributeOr404($id) { try { - $result = $this->attributeManager->getAttribute($id); + $result = $this->attributeRepository->find($id); } catch (EntityNotFoundException $e) { throw new NotFoundHttpException($e->getMessage()); } diff --git a/src/Pim/Bundle/EnrichBundle/Resources/config/controllers.yml b/src/Pim/Bundle/EnrichBundle/Resources/config/controllers.yml index be06848f3000..ea3401fa45b0 100644 --- a/src/Pim/Bundle/EnrichBundle/Resources/config/controllers.yml +++ b/src/Pim/Bundle/EnrichBundle/Resources/config/controllers.yml @@ -132,6 +132,7 @@ services: - '@pim_enrich.form.handler.attribute' - '@pim_enrich.form.attribute' - '@pim_catalog.manager.attribute' + - '@pim_catalog.factory.attribute' - '@pim_catalog.manager.attribute_option' - '@pim_catalog.repository.locale' - '@pim_versioning.manager.version' @@ -154,6 +155,7 @@ services: - '@pim_catalog.manager.attribute_option' - '@pim_catalog.saver.attribute_option' - '@pim_catalog.remover.attribute_option' + - '@pim_catalog.repository.attribute' pim_enrich.controller.product: scope: request diff --git a/src/Pim/Bundle/TransformBundle/Resources/config/transformers.yml b/src/Pim/Bundle/TransformBundle/Resources/config/transformers.yml index 07036d373bf5..2ff73ec65759 100644 --- a/src/Pim/Bundle/TransformBundle/Resources/config/transformers.yml +++ b/src/Pim/Bundle/TransformBundle/Resources/config/transformers.yml @@ -66,7 +66,7 @@ services: parent: pim_transform.transformer.entity arguments: - '@pim_transform.transformer.registry' - - '@pim_catalog.manager.attribute' + - '@pim_catalog.factory.attribute' - '@pim_catalog.manager.attribute_option' - '@pim_transform.cache.doctrine_cache' tags: diff --git a/src/Pim/Bundle/TransformBundle/Tests/Unit/Transformer/AttributeTransformerTest.php b/src/Pim/Bundle/TransformBundle/Tests/Unit/Transformer/AttributeTransformerTest.php deleted file mode 100644 index 138f909ef441..000000000000 --- a/src/Pim/Bundle/TransformBundle/Tests/Unit/Transformer/AttributeTransformerTest.php +++ /dev/null @@ -1,168 +0,0 @@ - - * @copyright 2013 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -class AttributeTransformerTest extends EntityTransformerTestCase -{ - protected $attribute; - protected $attributeManager; - protected $attributeOptionManager; - protected $doctrineCache; - protected $transformer; - protected $transformerRegistry; - - protected function setUp() - { - parent::setUp(); - $this->attribute = $this->getMock('Pim\Bundle\CatalogBundle\Entity\Attribute'); - $this->attributeManager = $this - ->getMockBuilder('Pim\Bundle\CatalogBundle\Manager\AttributeManager') - ->disableOriginalConstructor() - ->getMock(); - $this->attributeOptionManager = $this - ->getMockBuilder('Pim\Bundle\CatalogBundle\Manager\AttributeOptionManager') - ->disableOriginalConstructor() - ->getMock(); - $this->attributeManager->expects($this->any()) - ->method('getAttributeClass') - ->will($this->returnValue('Pim\Bundle\CatalogBundle\Entity\Attribute')); - $this->attributeOptionManager->expects($this->any()) - ->method('getAttributeOptionClass') - ->will($this->returnValue('Pim\Bundle\CatalogBundle\Entity\AttributeOption')); - $this->doctrineCache = $this->getMockBuilder('Pim\Bundle\TransformBundle\Cache\DoctrineCache') - ->disableOriginalConstructor() - ->getMock(); - $this->attributeManager->expects($this->any()) - ->method('createAttribute') - ->with($this->equalTo('type')) - ->will($this->returnValue($this->attribute)); - $this->transformerRegistry = $this - ->getMock('Pim\Bundle\TransformBundle\Transformer\EntityTransformerInterface'); - $this->transformer = new AttributeTransformer( - $this->doctrine, - $this->propertyAccessor, - $this->guesser, - $this->columnInfoTransformer, - $this->transformerRegistry, - $this->attributeManager, - $this->attributeOptionManager, - $this->doctrineCache - ); - $this->addColumn('code'); - $this->transformerRegistry - ->expects($this->any()) - ->method('transform') - ->will( - $this->returnCallback( - function ($class, $data) { - $this->assertEquals('Pim\Bundle\CatalogBundle\Entity\AttributeOption', $class); - $option = $this->getMock($class); - foreach ($data as $key => $value) { - $option->expects($this->any()) - ->method('get' . ucfirst($key)) - ->will($this->returnValue($value)); - } - - return $option; - } - ) - ); - } - protected function setupRepositories($referable = true) - { - $this->repository = $this - ->getMock('Akeneo\Component\StorageUtils\Repository\IdentifiableObjectRepositoryInterface'); - $this->repository->expects($this->any()) - ->method('getIdentifierProperties') - ->will($this->returnValue(['code'])); - - $this->doctrine - ->expects($this->any()) - ->method('getRepository') - ->with($this->equalTo('Pim\Bundle\CatalogBundle\Entity\Attribute')) - ->will($this->returnValue($this->repository)); - } - - public function getTransformData() - { - return [ - 'no_errors' => [false], - 'nested_errors' => [true] - ]; - } - - /** - * @dataProvider getTransformData - */ - public function testTransform($nestedErrors) - { - $this->addColumn('type'); - $this->addColumn('col1'); - $this->addColumn('col2'); - $this->addColumn('options'); - $this->addColumn('attribute'); - - if ($nestedErrors) { - $errors = [ - 'co1' => [ - ['error'] - ] - ]; - } else { - $errors = []; - } - $this->transformerRegistry->expects($this->any()) - ->method('getErrors') - ->with($this->equalTo('Pim\Bundle\CatalogBundle\Entity\AttributeOption')) - ->will($this->returnValue($errors)); - - $object = $this->transformer->transform( - 'Pim\Bundle\CatalogBundle\Entity\Attribute', - [ - 'code' => 'code', - 'type' => 'type', - 'col1' => 'val1', - 'col2' => 'val2', - 'options' => [ - [ - 'code' => 'o1code', - 'col1' => 'o1val1', - 'col2' => 'o1val2', - ], - [ - 'col1' => 'o2val1', - 'col2' => 'o2val2', - ], - ] - ] - ); - - $this->assertInstanceOf('Pim\Bundle\CatalogBundle\Entity\Attribute', $object); - if ($nestedErrors) { - $this->assertEquals( - [ - 'options' => [ - ['error'], - ['error'] - ] - ], - $this->transformer->getErrors('Pim\Bundle\CatalogBundle\Entity\Attribute') - ); - } else { - $this->assertEmpty($this->transformer->getErrors('Pim\Bundle\CatalogBundle\Entity\Attribute')); - } - $this->assertEquals('code_path-code', $object->code_path); - $this->assertEquals('col1_path-val1', $object->col1_path); - $this->assertEquals('col2_path-val2', $object->col2_path); - $this->assertCount(6, $this->transformers); - } -} diff --git a/src/Pim/Bundle/TransformBundle/Transformer/AttributeTransformer.php b/src/Pim/Bundle/TransformBundle/Transformer/AttributeTransformer.php index 6d4aff9603ca..19c5b529f5fc 100644 --- a/src/Pim/Bundle/TransformBundle/Transformer/AttributeTransformer.php +++ b/src/Pim/Bundle/TransformBundle/Transformer/AttributeTransformer.php @@ -3,7 +3,7 @@ namespace Pim\Bundle\TransformBundle\Transformer; use Doctrine\Common\Persistence\ManagerRegistry; -use Pim\Bundle\CatalogBundle\Manager\AttributeManager; +use Pim\Bundle\CatalogBundle\Factory\AttributeFactory; use Pim\Bundle\CatalogBundle\Manager\AttributeOptionManager; use Pim\Bundle\TransformBundle\Cache\DoctrineCache; use Pim\Bundle\TransformBundle\Transformer\ColumnInfo\ColumnInfoTransformerInterface; @@ -22,8 +22,8 @@ */ class AttributeTransformer extends NestedEntityTransformer { - /** @var AttributeManager */ - protected $attributeManager; + /** @var AttributeFactory */ + protected $attributeFactory; /** @var AttributeOptionManager */ protected $optionManager; @@ -39,7 +39,7 @@ class AttributeTransformer extends NestedEntityTransformer * @param GuesserInterface $guesser * @param ColumnInfoTransformerInterface $colInfoTransformer * @param EntityTransformerInterface $transformerRegistry - * @param AttributeManager $attributeManager + * @param AttributeFactory $attributeFactory * @param AttributeOptionManager $optionManager * @param DoctrineCache $doctrineCache */ @@ -49,13 +49,13 @@ public function __construct( GuesserInterface $guesser, ColumnInfoTransformerInterface $colInfoTransformer, EntityTransformerInterface $transformerRegistry, - AttributeManager $attributeManager, + AttributeFactory $attributeFactory, AttributeOptionManager $optionManager, DoctrineCache $doctrineCache ) { parent::__construct($doctrine, $propertyAccessor, $guesser, $colInfoTransformer, $transformerRegistry); - $this->attributeManager = $attributeManager; + $this->attributeFactory = $attributeFactory; $this->optionManager = $optionManager; $this->doctrineCache = $doctrineCache; } @@ -104,6 +104,6 @@ protected function setOptions($class, AttributeInterface $attribute, array $opti */ protected function createEntity($class, array $data) { - return $this->attributeManager->createAttribute($data['type']); + return $this->attributeFactory->createAttribute($data['type']); } }