Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated MediaGallery modules and marked as API #27499

Merged
merged 44 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c12201e
Updated MediaGallery modules and marked as API
sivaschenko Mar 30, 2020
abb4503
Fixed static tests
sivaschenko Mar 30, 2020
be2e695
magento/magento2#27499: Code review changes
sivaschenko Apr 1, 2020
e8eb3a9
magento/magento2#27499: Corrected DI configuration
sivaschenko Apr 1, 2020
e671db3
- Rename interface
VladimirZaets Apr 3, 2020
83e7e37
Test coverage
VladimirZaets Apr 3, 2020
df912e4
Merge branch '2.4-develop' of github.com:magento/magento2 into media-…
sivaschenko Apr 3, 2020
3784f92
magento/magento2#27499: Removed DataExtractor in favour to DataObject…
sivaschenko Apr 3, 2020
b77e66d
magento/magento2#27499: Code review changes
sivaschenko Apr 3, 2020
909ea3f
agento/magento2#27499: Updated blacklist patterns
sivaschenko Apr 4, 2020
0a57486
Add configuration for MediaGallery/Directory
VladimirZaets Apr 7, 2020
7a82782
Merge - Add configuration for MediaGallery/Directory
VladimirZaets Apr 7, 2020
90bf91d
Corrected blacklist patterns
sivaschenko Apr 7, 2020
7fd26a9
Added comments and strict types enabling
sivaschenko Apr 7, 2020
e1bea53
- Fix unit test
VladimirZaets Apr 8, 2020
2bd8609
- Fix unit test
VladimirZaets Apr 8, 2020
e69ee88
- Remove optional example attribute from xsd
VladimirZaets Apr 8, 2020
5aceeab
- Add rollback for media_asset fixture.
VladimirZaets Apr 8, 2020
a8ba203
magento/magento2#27499: Moved configuration xsd to MediaGalleryApi mo…
sivaschenko Apr 8, 2020
9f4bafc
magento/magento2#27499: MediaGallery bulk interfaces introduced
sivaschenko Apr 8, 2020
9106468
magento/magento2#27499: Extracted MediaGalleryCatalog module
sivaschenko Apr 9, 2020
96d3862
magento/magento2#27499: Corrected services implementation
sivaschenko Apr 9, 2020
e7a78fa
magento/magento2#27499: Fixed directory integration tests
sivaschenko Apr 9, 2020
f4d980a
magento/magento2#27499: Integration tests
sivaschenko Apr 9, 2020
ce08d34
magento/magento2#27499: Corrected comments and unit tests
sivaschenko Apr 9, 2020
6dfb2cc
magento/magento2#27499: Filtering data for insert
sivaschenko Apr 9, 2020
8e2337f
Merge remote-tracking branch 'mainline/2.4-develop' into sivaschenko/…
Apr 10, 2020
c13a5fb
magento/magento#227499: Intorduced ConfigInterface
sivaschenko Apr 14, 2020
30ce748
magento/magento2#27499: Code review fixes
Apr 14, 2020
9eecf12
Merge branch 'media-gallery-api' of github.com:sivaschenko/magento2 i…
Apr 14, 2020
6a94b59
magento/magento2#27499: Code review fixes
Apr 14, 2020
a77e990
Merge remote-tracking branch 'mainline/2.4-develop' into sivaschenko/…
Apr 14, 2020
e3ea27d
magento/magento2#27499: Code review fixes.
Apr 15, 2020
2e52006
Merge branch '2.4-develop' into media-gallery-api
lenaorobei Apr 16, 2020
024300a
Updated MediaGallery modules and marked as API
Apr 16, 2020
6e077c3
Merge branch 'media-gallery-api' of github.com:sivaschenko/magento2 i…
Apr 16, 2020
01ac38b
Updated MediaGallery modules and marked as API
Apr 16, 2020
1c7fd0a
Eliminate AbstractExtensibleModel usage
Apr 16, 2020
8919c70
Merge branch '2.4-develop' into media-gallery-api
sivaschenko Apr 17, 2020
c6c49b9
Merge branch '2.4-develop' of github.com:magento/magento2 into media-…
sivaschenko Apr 18, 2020
9a7a1c5
Fixed unit tests
sivaschenko Apr 18, 2020
21955c5
Fixed integration tests
sivaschenko Apr 18, 2020
c006590
Added blacklist to directory operations
sivaschenko Apr 18, 2020
8b3c9b1
Added MediaGalleryCatalog to composer.json
sivaschenko Apr 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 110 additions & 34 deletions app/code/Magento/MediaGallery/Model/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,123 +10,199 @@

use Magento\MediaGalleryApi\Api\Data\AssetExtensionInterface;
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
use Magento\Framework\Model\AbstractExtensibleModel;

/**
* Media Gallery Asset
*/
class Asset extends AbstractExtensibleModel implements AssetInterface
class Asset implements AssetInterface
{
private const ID = 'id';
private const PATH = 'path';
private const TITLE = 'title';
private const SOURCE = 'source';
private const CONTENT_TYPE = 'content_type';
private const WIDTH = 'width';
private const HEIGHT = 'height';
private const SIZE = 'size';
private const CREATED_AT = 'created_at';
private const UPDATED_AT = 'updated_at';
/**
* @var int|null
*/
private $id;

/**
* @var string
*/
private $path;

/**
* @var string|null
*/
private $title;

/**
* @var string|null
*/
private $source;

/**
* @var string
*/
private $contentType;

/**
* @var int
*/
private $width;

/**
* @var int
*/
private $height;

/**
* @var int
*/
private $size;

/**
* @var string|null
*/
private $createdAt;

/**
* @var string|null
*/
private $updatedAt;

/**
* @var AssetExtensionInterface|null
*/
private $extensionAttributes;

/**
* @param string $path
* @param string $contentType
* @param int $width
* @param int $height
* @param int $size
* @param int|null $id
* @param string|null $title
* @param string|null $source
* @param string|null $createdAt
* @param string|null $updatedAt
* @param AssetExtensionInterface|null $extensionAttributes
*/
public function __construct(
string $path,
string $contentType,
int $width,
int $height,
int $size,
?int $id = null,
?string $title = null,
?string $source = null,
?string $createdAt = null,
?string $updatedAt = null,
?AssetExtensionInterface $extensionAttributes = null
) {
$this->path = $path;
$this->contentType = $contentType;
$this->width = $width;
$this->height = $height;
$this->size = $size;
$this->id = $id;
$this->title = $title;
$this->source = $source;
$this->createdAt = $createdAt;
$this->updatedAt = $updatedAt;
$this->extensionAttributes = $extensionAttributes;
}

/**
* @inheritdoc
*/
public function getId(): ?int
{
$id = $this->getData(self::ID);

if (!$id) {
return null;
}

return (int) $id;
return $this->id;
}

/**
* @inheritdoc
*/
public function getPath(): string
{
return (string) $this->getData(self::PATH);
return $this->path;
}

/**
* @inheritdoc
*/
public function getTitle(): ?string
{
return $this->getData(self::TITLE);
return $this->title;
}

/**
* @inheritdoc
*/
public function getSource(): ?string
{
return $this->getData(self::SOURCE);
return $this->source;
}

/**
* @inheritdoc
*/
public function getContentType(): string
{
return (string) $this->getData(self::CONTENT_TYPE);
return $this->contentType;
}

/**
* @inheritdoc
*/
public function getWidth(): int
{
return (int) $this->getData(self::WIDTH);
return $this->width;
}

/**
* @inheritdoc
*/
public function getHeight(): int
{
return (int) $this->getData(self::HEIGHT);
return $this->height;
}

/**
* @inheritdoc
*/
public function getSize(): int
{
return (int) $this->getData(self::SIZE);
return $this->size;
}

/**
* @inheritdoc
*/
public function getCreatedAt(): string
public function getCreatedAt(): ?string
{
return (string) $this->getData(self::CREATED_AT);
return $this->createdAt;
}

/**
* @inheritdoc
*/
public function getUpdatedAt(): string
public function getUpdatedAt(): ?string
{
return (string) $this->getData(self::UPDATED_AT);
return $this->updatedAt;
}

/**
* @inheritdoc
*/
public function getExtensionAttributes(): AssetExtensionInterface
public function getExtensionAttributes(): ?AssetExtensionInterface
{
return $this->_getExtensionAttributes();
return $this->extensionAttributes;
}

/**
* @inheritdoc
*/
public function setExtensionAttributes(AssetExtensionInterface $extensionAttributes): void
public function setExtensionAttributes(?AssetExtensionInterface $extensionAttributes): void
{
$this->_setExtensionAttributes($extensionAttributes);
$this->extensionAttributes = $extensionAttributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use Psr\Log\LoggerInterface;

/**
* Class DeleteByDirectoryPath
*
* Remove asset(s) that correspond the provided directory path
* @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead
* @see \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterfac
*/
class DeleteByDirectoryPath implements DeleteByDirectoryPathInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
use Psr\Log\LoggerInterface;

/**
* Class DeleteByPath
* Delete media asset by path
*
* @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead
* @see \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface
*/
class DeleteByPath implements DeleteByPathInterface
{
Expand Down
21 changes: 18 additions & 3 deletions app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
use Psr\Log\LoggerInterface;

/**
* Class GetById
* Get media asset by id
* @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface instead
* @see \Magento\MediaGalleryApi\Api\GetAssetsByIdsInterface
*/
class GetById implements GetByIdInterface
{
Expand All @@ -28,7 +30,7 @@ class GetById implements GetByIdInterface
private $resourceConnection;

/**
* @var AssetInterface
* @var AssetInterfaceFactory
*/
private $assetFactory;

Expand Down Expand Up @@ -87,7 +89,20 @@ public function execute(int $mediaAssetId): AssetInterface
}

try {
return $this->assetFactory->create(['data' => $mediaAssetData]);
return $this->assetFactory->create(
[
'id' => $mediaAssetData['id'],
'path' => $mediaAssetData['path'],
'title' => $mediaAssetData['title'],
'source' => $mediaAssetData['source'],
'contentType' => $mediaAssetData['content_type'],
'width' => $mediaAssetData['width'],
'height' => $mediaAssetData['height'],
'size' => $mediaAssetData['size'],
'createdAt' => $mediaAssetData['created_at'],
'updatedAt' => $mediaAssetData['updated_at'],
]
);
} catch (\Exception $exception) {
$this->logger->critical($exception);
$message = __(
Expand Down
34 changes: 24 additions & 10 deletions app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
use Psr\Log\LoggerInterface;

/**
* Class GetListByIds
* Provide media asset by path
*
* @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface instead
* @see \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface
*/
class GetByPath implements GetByPathInterface
{
Expand All @@ -30,7 +33,7 @@ class GetByPath implements GetByPathInterface
private $resourceConnection;

/**
* @var AssetInterface
* @var AssetInterfaceFactory
*/
private $mediaAssetFactory;

Expand All @@ -57,30 +60,41 @@ public function __construct(
}

/**
* Return media asset asset list
* Return media asset
*
* @param string $mediaFilePath
* @param string $path
*
* @return AssetInterface
* @throws IntegrationException
*/
public function execute(string $mediaFilePath): AssetInterface
public function execute(string $path): AssetInterface
{
try {
sivaschenko marked this conversation as resolved.
Show resolved Hide resolved
$connection = $this->resourceConnection->getConnection();
$select = $connection->select()
->from($this->resourceConnection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET))
->where(self::MEDIA_GALLERY_ASSET_PATH . ' = ?', $mediaFilePath);
->where(self::MEDIA_GALLERY_ASSET_PATH . ' = ?', $path);
$data = $connection->query($select)->fetch();

if (empty($data)) {
$message = __('There is no such media asset with path "%1"', $mediaFilePath);
$message = __('There is no such media asset with path "%1"', $path);
throw new NoSuchEntityException($message);
}

$mediaAssets = $this->mediaAssetFactory->create(['data' => $data]);

return $mediaAssets;
return $this->mediaAssetFactory->create(
[
'id' => $data['id'],
'path' => $data['path'],
'title' => $data['title'],
'source' => $data['source'],
'contentType' => $data['content_type'],
'width' => $data['width'],
'height' => $data['height'],
'size' => $data['size'],
'createdAt' => $data['created_at'],
'updatedAt' => $data['updated_at'],
]
);
} catch (\Exception $exception) {
$this->logger->critical($exception);
$message = __('An error occurred during get media asset list: %1', $exception->getMessage());
Expand Down
Loading