-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
parameters: | ||
app.pim_structure.config_path: '%kernel.project_dir%/config/resources/cloudinary/structure.yaml' | ||
app.dam_to_pim_mapping.config_path: '%kernel.project_dir%/config/resources/cloudinary/mapping.yaml' | ||
|
||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
AkeneoDAMConnector\Infrastructure\DAM\Cloudinary\: | ||
resource: '../../src/Infrastructure/DAM/Cloudinary/*' | ||
|
||
AkeneoDAMConnector\Infrastructure\DAM\Cloudinary\Search: | ||
arguments: | ||
$cloudName: '%env(CLOUDINARY_CLOUD_NAME)%' | ||
$apiKey: '%env(CLOUDINARY_API_KEY)%' | ||
$apiSecret: '%env(CLOUDINARY_API_SECRET)%' | ||
|
||
AkeneoDAMConnector\Application\DamAdapter\FetchAssets: '@AkeneoDAMConnector\Infrastructure\DAM\Cloudinary\FetchAssets' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AkeneoDAMConnector\Infrastructure\DAM\Cloudinary; | ||
|
||
use AkeneoDAMConnector\Application\DamAdapter\FetchAssets as FetchAssetsInterface; | ||
use AkeneoDAMConnector\Domain\Model\Dam\DamAsset; | ||
use AkeneoDAMConnector\Domain\Model\Dam\DamAssetIdentifier; | ||
use AkeneoDAMConnector\Domain\Model\FamilyCode; | ||
use AkeneoDAMConnector\Domain\Model\Locale; | ||
|
||
/** | ||
* This class is not scalable for an high volume of assets | ||
* | ||
* Cloudinary does not provide any delta to fetch assets from a last update date | ||
* They use a queuing system for that | ||
*/ | ||
class FetchAssets implements FetchAssetsInterface | ||
{ | ||
/** @var Search */ | ||
private $search; | ||
|
||
public function __construct(Search $search) | ||
{ | ||
$this->search = $search; | ||
} | ||
|
||
public function fetch(FamilyCode $assetFamilyCode, ?\DateTimeInterface $lastFetchDate): \Iterator | ||
{ | ||
$expression = sprintf('tags:akeneo AND folder="%s"', (string) $assetFamilyCode); | ||
$response = $this->search->search($expression, ['tags', 'context']); | ||
|
||
$staticAttributes = ['filename', 'url', 'secure_url', 'status', 'public_id']; | ||
|
||
$damAssets = []; | ||
|
||
$assets = $response['resources'] ?? []; | ||
foreach ($assets as $asset) { | ||
$damAsset = new DamAsset( | ||
new DamAssetIdentifier($asset['filename']), | ||
$assetFamilyCode, | ||
new Locale('en_US') | ||
); | ||
|
||
foreach ($staticAttributes as $staticAttribute) { | ||
$damAsset->addValue($staticAttribute, $asset[$staticAttribute]); | ||
} | ||
|
||
foreach ($asset['context'] as $property => $value) { | ||
$damAsset->addValue($property, $value); | ||
} | ||
$damAsset->addValue('tags', implode(', ', $asset['tags'])); | ||
|
||
$damAssets[] = $damAsset; | ||
} | ||
|
||
return new \ArrayIterator($damAssets); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AkeneoDAMConnector\Infrastructure\DAM\Cloudinary; | ||
|
||
class Search | ||
{ | ||
public function __construct(string $cloudName, string $apiKey, string $apiSecret) | ||
{ | ||
\Cloudinary::config(array( | ||
'cloud_name' => $cloudName, | ||
'api_key' => $apiKey, | ||
'api_secret' => $apiSecret, | ||
'secure' => true | ||
)); | ||
} | ||
|
||
public function search(string $expression, array $withFields) | ||
{ | ||
$searchEngine = new \Cloudinary\Search(); | ||
$searchEngine->expression($expression); | ||
if (!empty($withFields)) { | ||
foreach ($withFields as $field) { | ||
$searchEngine->with_field($field); | ||
} | ||
} | ||
|
||
return $searchEngine->execute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters