Skip to content

Commit

Permalink
Merge pull request #100 from akeneo/release/100.3.1
Browse files Browse the repository at this point in the history
Release/100.3.1
  • Loading branch information
Dnd-Gimix authored Dec 11, 2019
2 parents 6ba944f + 8ee1826 commit a9384e6
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 76 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@
* Remove Akeneo attribute group import from connector (https://help.akeneo.com/magento2-connector/v100/articles/where-attributes.html#where-to-find-my-attribute-groups-in-magento-2)
* Remove automatic mapping for attributes "price", "special_price" and "cost" (https://help.akeneo.com/magento2-connector/v100/articles/what-data.html#attribute-types)
* Add metric as product variant and unit concatenation feature (https://help.akeneo.com/magento2-connector/v100/articles/05-configure-products.html#metric-attributes)
* Update wording for configurable product attribute mapping
* Update wording for configurable product attribute mapping

### Version 100.3.1 :
* Fix product image name that should not exceed 90 characters since Magento 2.3.3

**Warning :** *After updating connector to this version, all image names will be renamed. To know more, please consult documentation (https://help.akeneo.com/magento2-connector/v100/articles/06-import-images-configuration.html)*

* Remove unused "file" column on log grid
* Move API client call from construct
* Fix category URL issue adding -1, -2 to url-key when category had same name but not same parent category
30 changes: 30 additions & 0 deletions Helper/Import/Entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,34 @@ public function formatUrlKeyColumn($tmpTable, $local = null) {
}
}
}

/**
* Format media filename, removing hash and stoppig at 90 characters
*
* @param string $filename
*
* @return string
*/
public function formatMediaName($filename)
{
/** @var string[] $filenameParts */
$filenameParts = explode('.', $filename);
// Get the extention
/** @var string $extension */
$extension = array_pop($filenameParts);
// Get the hash
$filename = implode('.', $filenameParts);
$filename = explode('_', $filename);
/** @var string $shortHash */
$shortHash = array_shift($filename);
$shortHash = substr($shortHash, 0, 4);
$filename = implode('_', $filename);
// Form the final file name
/** @var string $shortName */
$shortName = substr($filename, 0, 79);
/** @var string $finalName */
$finalName = $shortName . '_' . $shortHash . '.' . $extension;

return $finalName;
}
}
116 changes: 58 additions & 58 deletions Job/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,62 @@ public function matchEntities()
);
}

/**
* Set Categories structure
*
* @return void
*/
public function setStructure()
{
/** @var AdapterInterface $connection */
$connection = $this->entitiesHelper->getConnection();
/** @var string $tableName */
$tmpTable = $this->entitiesHelper->getTableName($this->getCode());

$connection->addColumn($tmpTable, 'level', [
'type' => 'integer',
'length' => 11,
'default' => 0,
'COMMENT' => ' ',
'nullable' => false
]);
$connection->addColumn($tmpTable, 'path', [
'type' => 'text',
'length' => 255,
'default' => '',
'COMMENT' => ' ',
'nullable' => false
]);
$connection->addColumn($tmpTable, 'parent_id', [
'type' => 'integer',
'length' => 11,
'default' => 0,
'COMMENT' => ' ',
'nullable' => false
]);

/** @var array $values */
$values = [
'level' => 1,
'path' => new Expr('CONCAT(1, "/", `_entity_id`)'),
'parent_id' => 1,
];
$connection->update($tmpTable, $values, 'parent IS NULL');

/** @var int $depth */
$depth = self::MAX_DEPTH;
for ($i = 1; $i <= $depth; $i++) {
$connection->query('
UPDATE `' . $tmpTable . '` c1
INNER JOIN `' . $tmpTable . '` c2 ON c2.`code` = c1.`parent`
SET c1.`level` = c2.`level` + 1,
c1.`path` = CONCAT(c2.`path`, "/", c1.`_entity_id`),
c1.`parent_id` = c2.`_entity_id`
WHERE c1.`level` <= c2.`level` - 1
');
}
}

/**
* Set categories Url Key
*
Expand Down Expand Up @@ -237,11 +293,11 @@ public function setUrlKey()
$finalKey = $urlKey;
/** @var int $increment */
$increment = 1;
while (in_array($finalKey, $keys)) {
while (isset($keys[$row['parent_id']]) && in_array($finalKey, $keys[$row['parent_id']])) {
$finalKey = $urlKey . '-' . $increment++;
}

$keys[] = $finalKey;
$keys[$row['parent_id']][] = $finalKey;

$connection->update(
$tmpTable,
Expand All @@ -253,62 +309,6 @@ public function setUrlKey()
}
}

/**
* Set Categories structure
*
* @return void
*/
public function setStructure()
{
/** @var AdapterInterface $connection */
$connection = $this->entitiesHelper->getConnection();
/** @var string $tableName */
$tmpTable = $this->entitiesHelper->getTableName($this->getCode());

$connection->addColumn($tmpTable, 'level', [
'type' => 'integer',
'length' => 11,
'default' => 0,
'COMMENT' => ' ',
'nullable' => false
]);
$connection->addColumn($tmpTable, 'path', [
'type' => 'text',
'length' => 255,
'default' => '',
'COMMENT' => ' ',
'nullable' => false
]);
$connection->addColumn($tmpTable, 'parent_id', [
'type' => 'integer',
'length' => 11,
'default' => 0,
'COMMENT' => ' ',
'nullable' => false
]);

/** @var array $values */
$values = [
'level' => 1,
'path' => new Expr('CONCAT(1, "/", `_entity_id`)'),
'parent_id' => 1,
];
$connection->update($tmpTable, $values, 'parent IS NULL');

/** @var int $depth */
$depth = self::MAX_DEPTH;
for ($i = 1; $i <= $depth; $i++) {
$connection->query('
UPDATE `' . $tmpTable . '` c1
INNER JOIN `' . $tmpTable . '` c2 ON c2.`code` = c1.`parent`
SET c1.`level` = c2.`level` + 1,
c1.`path` = CONCAT(c2.`path`, "/", c1.`_entity_id`),
c1.`parent_id` = c2.`_entity_id`
WHERE c1.`level` <= c2.`level` - 1
');
}
}

/**
* Set categories position
*
Expand Down
33 changes: 28 additions & 5 deletions Job/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ abstract class Import extends DataObject implements ImportInterface
* @var OutputHelper $outputHelper
*/
protected $outputHelper;
/**
* This variable contains an Authenticator
*
* @var mixed $authenticator
*/
protected $authenticator;
/**
* This variable contains a mixed value
*
Expand Down Expand Up @@ -117,11 +123,7 @@ public function __construct(
) {
parent::__construct($data);

try {
$this->akeneoClient = $authenticator->getAkeneoApiClient();
} catch (\Exception $e) {
$this->akeneoClient = false;
}
$this->authenticator = $authenticator;
$this->outputHelper = $outputHelper;
$this->eventManager = $eventManager;
$this->step = 0;
Expand Down Expand Up @@ -426,6 +428,10 @@ public function execute()
return $this->outputHelper->getNoImportFoundResponse();
}

if (!$this->akeneoClient) {
$this->akeneoClient = $this->getAkeneoClient();
}

if (!$this->akeneoClient) {
return $this->outputHelper->getApiConnectionError();
}
Expand Down Expand Up @@ -595,4 +601,21 @@ public function checkLabelPerLocales(array $entity, array $lang, string $respons
}
return $response;
}

/**
* Get Akeneo Client instance
*
* @return AkeneoPimEnterpriseClientInterface|false
*/
public function getAkeneoClient()
{
try {
/** @var AkeneoPimEnterpriseClientInterface|false $akeneoClient */
$akeneoClient = $this->authenticator->getAkeneoApiClient();
} catch (\Exception $e) {
$akeneoClient = false;
}

return $akeneoClient;
}
}
9 changes: 9 additions & 0 deletions Job/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ public function createTable()
/** @var array $attribute */
foreach ($attributes as $attribute) {
if ($attribute['type'] == 'pim_catalog_multiselect' || $attribute['type'] == 'pim_catalog_simpleselect') {
if (!$this->akeneoClient) {
$this->akeneoClient = $this->getAkeneoClient();
}
/** @var PageInterface $options */
$options = $this->akeneoClient->getAttributeOptionApi()->listPerPage($attribute['code']);
if (empty($options->getItems())) {
Expand Down Expand Up @@ -377,6 +380,9 @@ public function cleanCache()
*/
protected function processAttributeOption($attributeCode, $paginationSize)
{
if (!$this->akeneoClient) {
$this->akeneoClient = $this->getAkeneoClient();
}
/** @var ResourceCursorInterface $options */
$options = $this->akeneoClient->getAttributeOptionApi()->all($attributeCode, $paginationSize);
/** @var int $index */
Expand All @@ -398,6 +404,9 @@ protected function processAttributeOption($attributeCode, $paginationSize)
public function getAllAttributes()
{
if (!$this->attributes) {
if (!$this->akeneoClient) {
$this->akeneoClient = $this->getAkeneoClient();
}
$this->attributes = $this->akeneoClient->getAttributeApi()->all();
}

Expand Down
2 changes: 1 addition & 1 deletion Job/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,7 @@ public function importMedia()
/** @var array $media */
$media = $this->akeneoClient->getProductMediaFileApi()->get($row[$image]);
/** @var string $name */
$name = basename($media['code']);
$name = $this->entitiesHelper->formatMediaName(basename($media['code']));

if (!$this->configHelper->mediaFileExists($name)) {
$binary = $this->akeneoClient->getProductMediaFileApi()->download($row[$image]);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"php-http/guzzle6-adapter": "^1.1"
},
"type": "magento2-module",
"version": "100.3.0",
"version": "100.3.1",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
8 changes: 4 additions & 4 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
<item name="comment" xsi:type="string">Match code with Magento ID</item>
</item>
<item name="4" xsi:type="array">
<item name="method" xsi:type="string">setUrlKey</item>
<item name="comment" xsi:type="string">Create URL key</item>
</item>
<item name="5" xsi:type="array">
<item name="method" xsi:type="string">setStructure</item>
<item name="comment" xsi:type="string">Create structure</item>
</item>
<item name="5" xsi:type="array">
<item name="method" xsi:type="string">setUrlKey</item>
<item name="comment" xsi:type="string">Create URL key</item>
</item>
<item name="6" xsi:type="array">
<item name="method" xsi:type="string">removeCategoriesByFilter</item>
<item name="comment" xsi:type="string">Remove Categories By Filter</item>
Expand Down
6 changes: 0 additions & 6 deletions view/adminhtml/layout/akeneo_connector_log_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@
<argument name="index" xsi:type="string">name</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="file">
<arguments>
<argument name="header" xsi:type="string" translate="true">File</argument>
<argument name="index" xsi:type="string">file</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="status">
<arguments>
<argument name="header" xsi:type="string" translate="true">Status</argument>
Expand Down

0 comments on commit a9384e6

Please sign in to comment.