Skip to content

Commit

Permalink
Merge pull request #48 from flagbit/akeneo4
Browse files Browse the repository at this point in the history
Update bundle for Akeneo 4.0
  • Loading branch information
flagbird authored May 28, 2020
2 parents e91a84c + 13469f2 commit 41b70c4
Show file tree
Hide file tree
Showing 29 changed files with 484 additions and 309 deletions.
13 changes: 13 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
build:
nodes:
analysis:
environment:
apt_packages:
- libmagickwand-dev
- libmagickcore-dev
php:
version: 7.3
pecl_extensions:
- apcu
- imagick
- zip
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ cache:
matrix:
fast_finish: true
include:
- php: 7.2
- php: 7.3
allow_failures:
- php: 7.3

before_install:
Expand Down
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,17 @@ Enable the bundle in the kernel:

``` php
<?php
// app/AppKernel.php

protected function registerProjectBundles()
{
return [
// ...
new Flagbit\Bundle\TableAttributeBundle\FlagbitTableAttributeBundle(),
// ...
];
}
// config/bundles.php

return [
// ...
Flagbit\Bundle\TableAttributeBundle\FlagbitTableAttributeBundle::class => ['all' => true],
];
```

### Configuration

Add `mapping_overrides` in `app/config/config.yml`:
Add `mapping_overrides` in a new `config/packages/table.yml` file or an existing one:

``` yml
akeneo_storage_utils:
Expand All @@ -99,8 +95,7 @@ php bin/console --env=prod doctrine:schema:update --force
Build and install the new front-end dependencies (new icon, etc.)

``` bash
php bin/console --env=prod pim:installer:assets --symlink --clean
yarn run webpack
make cache assets css javascript-prod
```

In case you're using Doctrine migrations, you have to create a new migration class
Expand All @@ -119,6 +114,7 @@ php bin/console --env=prod doctrine:migrations:migrate

This extension supports the latest Akeneo PIM CE/EE stable versions:

* 4.0
* 3.2 (LTS)
* 3.0 (LTS)
* 2.3 (LTS)
Expand Down
21 changes: 8 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,17 @@
"Flagbit\\Bundle\\TableAttributeBundle\\Test\\": "tests/"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/akeneo/pim-community-dev.git",
"branch": "master",
"no-api": true
}
],
"require": {
"ext-json": "*",
"akeneo/pim-community-dev": "^3.2"
"akeneo/pim-community-dev": "^4.0"
},
"require-dev": {
"phpspec/phpspec": "^5.1",
"phpunit/phpunit": "^7.1",
"squizlabs/php_codesniffer": "*",
"overtrue/phplint": "*"
"phpspec/phpspec": "^6.1",
"phpunit/phpunit": "^8.0",
"squizlabs/php_codesniffer": "^3.5",
"overtrue/phplint": "^1.2",
"symfony/debug-bundle": "^4.4",
"symfony/web-profiler-bundle": "^4.4",
"symfony/web-server-bundle": "^4.4"
}
}
8 changes: 8 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@

<php>
<env name="KERNEL_CLASS" value="Flagbit\Bundle\TableAttributeBundle\Test\Kernel\TestKernel"/>
<env name="APP_ENV" value="test"/>
<env name="APP_INDEX_HOSTS" value="elasticsearch:9200"/>
<env name="APP_DATABASE_HOST" value="mysql"/>
<env name="APP_DATABASE_PORT" value=""/>
<env name="APP_DATABASE_NAME" value="akeneo_pim"/>
<env name="APP_DATABASE_USER" value="akeneo_pim"/>
<env name="APP_DATABASE_PASSWORD" value="akeneo_pim"/>
<env name="APP_DEFAULT_LOCALE" value="en"/>
</php>

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

namespace spec\Flagbit\Bundle\TableAttributeBundle\Component\Product\Completeness\MaskItemGenerator;

use Flagbit\Bundle\TableAttributeBundle\Component\Product\Completeness\MaskItemGenerator\TableMaskItem;
use PhpSpec\ObjectBehavior;

class TableMaskItemSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType(TableMaskItem::class);
}

public function it_masks_for_raw_value()
{
$this->forRawValue('a', 'b', 'c', 'd')->shouldBe(['a-b-c']);
}

public function it_supports_attribute_types()
{
$this->supportedAttributeTypes()->shouldBe(['flagbit_catalog_table']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace spec\Flagbit\Bundle\TableAttributeBundle\Component\Product\Factory\Value;

use Akeneo\Pim\Enrichment\Component\Product\Value\ScalarValue;
use Akeneo\Pim\Structure\Component\Query\PublicApi\AttributeType\Attribute;
use Akeneo\Tool\Component\StorageUtils\Exception\InvalidPropertyTypeException;
use EmptyIterator;
use Flagbit\Bundle\TableAttributeBundle\Component\Product\Factory\Value\TableValueFactory;
use PhpSpec\ObjectBehavior;

class TableValueFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(TableValueFactory::class);
}

public function it_creates_scopable_and_localizable_table_value()
{
$attribute = $this->createAttribute(true, true);

$this->createByCheckingData($attribute, 'channelCode', 'de_DE', 'data')
->shouldBeLike(ScalarValue::scopableLocalizableValue('code', 'data', 'channelCode', 'de_DE'));
}

public function it_creates_scopable_table_value()
{
$attribute = $this->createAttribute(true, false);

$this->createByCheckingData($attribute, 'channelCode', null, 'data')
->shouldBeLike(ScalarValue::scopableValue('code', 'data', 'channelCode'));
}

public function it_creates_localizable_table_value()
{
$attribute = $this->createAttribute(false, true);

$this->createByCheckingData($attribute, null, 'de_DE', 'data')
->shouldBeLike(ScalarValue::localizableValue('code', 'data', 'de_DE'));
}

public function it_creates_table_value()
{
$attribute = $this->createAttribute(false, false);

$this->createByCheckingData($attribute, null, null, 'data')
->shouldBeLike(ScalarValue::value('code', 'data'));
}

public function it_throws_exception_on_nonscalar_data()
{
$attribute = $this->createAttribute(false, false);

$this->shouldThrow()->during('createByCheckingData', [$attribute, null, null, new EmptyIterator()]);
}

public function it_throws_exception_on_empty_data()
{
$attribute = $this->createAttribute(false, false);

$this->shouldThrow(InvalidPropertyTypeException::class)->during('createByCheckingData', [$attribute, null, null, "\0\n "]);
}

private function createAttribute(bool $isScopable, bool $isLocalizable): Attribute
{
return new Attribute('code', 'flagbit_catalog_table', [], $isLocalizable, $isScopable, null, false, 'backend', ['de_DE', 'en_US']);
}

public function it_supports_attribute_type()
{
$this->supportedAttributeType()->shouldBe('flagbit_catalog_table');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Flagbit\Bundle\TableAttributeBundle\Component\Product\Completeness\MaskItemGenerator;

use Akeneo\Pim\Enrichment\Component\Product\Completeness\MaskItemGenerator\MaskItemGeneratorForAttributeType;
use Flagbit\Bundle\TableAttributeBundle\AttributeType\TableType;

class TableMaskItem implements MaskItemGeneratorForAttributeType
{
public function forRawValue(string $attributeCode, string $channelCode, string $localeCode, $value): array
{
return [
sprintf(
'%s-%s-%s',
$attributeCode,
$channelCode,
$localeCode
)
];
}

public function supportedAttributeTypes(): array
{
return [
TableType::FLAGBIT_CATALOG_TABLE,
];
}
}
34 changes: 34 additions & 0 deletions src/Component/Product/Factory/Value/TableValueFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Flagbit\Bundle\TableAttributeBundle\Component\Product\Factory\Value;

use Akeneo\Pim\Enrichment\Component\Product\Factory\Value\ScalarValueFactory;
use Akeneo\Pim\Enrichment\Component\Product\Model\ValueInterface;
use Akeneo\Pim\Structure\Component\Query\PublicApi\AttributeType\Attribute;
use Akeneo\Tool\Component\StorageUtils\Exception\InvalidPropertyTypeException;
use Flagbit\Bundle\TableAttributeBundle\AttributeType\TableType;

final class TableValueFactory extends ScalarValueFactory
{
public function createByCheckingData(
Attribute $attribute,
?string $channelCode,
?string $localeCode,
$data
): ValueInterface {
if (!is_scalar($data) || (is_string($data) && '' === trim($data))) {
throw InvalidPropertyTypeException::stringExpected(
$attribute->code(),
static::class,
$data
);
}

return parent::createWithoutCheckingData($attribute, $channelCode, $localeCode, $data);
}

public function supportedAttributeType(): string
{
return TableType::FLAGBIT_CATALOG_TABLE;
}
}
6 changes: 2 additions & 4 deletions src/Resources/config/factories.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="flagbit_catalog_table.factory.value.table" class="%pim_catalog.factory.value.scalar.class%"
<service id="flagbit_table_attribute.factory.value.table" class="Flagbit\Bundle\TableAttributeBundle\Component\Product\Factory\Value\TableValueFactory"
public="false">
<tag name="pim_catalog.factory.value"/>
<argument>%pim_catalog.entity.value.scalar.class%</argument>
<argument>flagbit_catalog_table</argument>
<tag name="akeneo.pim.enrichment.factory.product_value"/>
</service>
</services>
</container>
2 changes: 2 additions & 0 deletions src/Resources/config/query_builders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<tag name="pim_catalog.elasticsearch.query.product_filter" priority="30"/>
<tag name="pim_catalog.elasticsearch.query.product_model_filter" priority="30"/>
<tag name="pim_catalog.elasticsearch.query.product_and_product_model_filter" priority="30"/>
<tag name="pimee_workflow.elasticsearch.query.published_product_filter" priority="50"/>
<tag name="pimee_workflow.elasticsearch.query.product_proposal_filter" priority="50"/>
</service>
</services>
</container>
16 changes: 10 additions & 6 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="flagbit_table_attribute.provider.field.Table.class">Flagbit\Bundle\TableAttributeBundle\Provider\Field\TableFieldProvider</parameter>
<parameter key="flagbit_table_attribute.provider.field.table.class">Flagbit\Bundle\TableAttributeBundle\Provider\Field\TableFieldProvider</parameter>
<parameter key="pim_catalog.validator.constraint.attribute_type_for_option.class">Flagbit\Bundle\TableAttributeBundle\Validator\Constraints\AttributeTypeForOptionValidator</parameter>
<parameter key="flagbit_table_attribute.form.extension.attribute_option.class">Flagbit\Bundle\TableAttributeBundle\Form\Extension\AttributeOptionTypeExtension</parameter>
<parameter key="pim_enrich.view_element.attribute.tab.value.template">FlagbitTableAttributeBundle:Attribute:Tab/value.html.twig</parameter>
</parameters>

<services>
<service
id="flagbit_table_attribute.normalizer.structured.attribute_option"
class="Flagbit\Bundle\TableAttributeBundle\Normalizer\AttributeOptionNormalizer"
decorates="pim_enrich.normalizer.structured.attribute_option" decoration-inner-name="pim_enrich.normalizer.structured.attribute_option_base">
id="flagbit_table_attribute.normalizer.structured.attribute_option"
class="Flagbit\Bundle\TableAttributeBundle\Normalizer\AttributeOptionNormalizer"
decorates="pim_enrich.normalizer.structured.attribute_option" decoration-inner-name="pim_enrich.normalizer.structured.attribute_option_base">
<argument type="service" id="pim_enrich.normalizer.structured.attribute_option_base"/>
<tag name="pim_internal_api_serializer.normalizer"/>
</service>

<service
id="flagbit_table_attribute.normalizer.attribute_option"
class="Flagbit\Bundle\TableAttributeBundle\Normalizer\AttributeOptionNormalizer">
id="flagbit_table_attribute.normalizer.attribute_option"
class="Flagbit\Bundle\TableAttributeBundle\Normalizer\AttributeOptionNormalizer">
<argument type="service" id="pim_enrich.normalizer.attribute_option"/>
<tag name="pim_internal_api_serializer.normalizer" priority="200"/>
</service>
Expand All @@ -35,5 +35,9 @@
<service id="flagbit_table_attribute.provider.field.table" class="%flagbit_table_attribute.provider.field.table.class%">
<tag name="pim_enrich.provider.field" priority="90"/>
</service>

<service id="flagbit_table_attribute.mask_item.table" class="Flagbit\Bundle\TableAttributeBundle\Component\Product\Completeness\MaskItemGenerator\TableMaskItem">
<tag name="akeneo.pim.enrichment.completeness.mask_item_generator"/>
</service>
</services>
</container>
2 changes: 1 addition & 1 deletion src/Resources/public/less/index.less
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@import "./web/bundles/flagbittableattribute/less/tableattribute.less";
@import "./public/bundles/flagbittableattribute/less/tableattribute.less";
2 changes: 1 addition & 1 deletion tests/AttributeType/TableTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TableTypeTest extends KernelTestCase
public function testAttributeTypeIsRegisteredCorrect()
{
self::bootKernel();
$container = self::$kernel->getContainer();
$container = self::$container;

$attributeTypeRegistry = $container->get('pim_catalog.registry.attribute_type');

Expand Down
2 changes: 1 addition & 1 deletion tests/Form/Extension/AttributeOptionTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AttributeOptionTypeExtensionTest extends KernelTestCase
public function testAttributeOptionTypeExtended()
{
self::bootKernel();
$container = self::$kernel->getContainer();
$container = self::$container;

$formExtension = $container->get('form.extension');

Expand Down
Loading

0 comments on commit 41b70c4

Please sign in to comment.