-
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
11 changed files
with
176 additions
and
4 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
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AkeneoDAMConnector\Infrastructure\DAM\Cloudinary; | ||
|
||
use AkeneoDAMConnector\Application\DamAdapter\FetchAssets as FetchAssetsInterface; | ||
use AkeneoDAMConnector\Domain\Asset\DamAsset; | ||
use AkeneoDAMConnector\Domain\Asset\DamAssetCollection; | ||
use AkeneoDAMConnector\Domain\Asset\DamAssetIdentifier; | ||
use AkeneoDAMConnector\Domain\AssetFamilyCode; | ||
use AkeneoDAMConnector\Domain\Locale; | ||
use AkeneoDAMConnector\Domain\ResourceType; | ||
|
||
class FetchAssets implements FetchAssetsInterface | ||
{ | ||
/** @var Search */ | ||
private $search; | ||
|
||
public function __construct(Search $search) | ||
{ | ||
$this->search = $search; | ||
} | ||
|
||
public function fetch(\DateTime $lastFetchDate, AssetFamilyCode $assetFamilyCode): DamAssetCollection | ||
{ | ||
$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 = new DamAssetCollection(); | ||
$assets = $response['resources'] ?? []; | ||
foreach ($assets as $asset) { | ||
$damAsset = new DamAsset( | ||
new DamAssetIdentifier($asset['filename']), | ||
$assetFamilyCode, | ||
new Locale('en_US'), | ||
new ResourceType($asset['resource_type']) | ||
); | ||
|
||
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->addAsset($damAsset); | ||
} | ||
|
||
return $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