-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
- Loading branch information
Showing
16 changed files
with
940 additions
and
125 deletions.
There are no files selected for viewing
26 changes: 0 additions & 26 deletions
26
app/code/Magento/AdminAnalytics/Test/Mftf/Test/TrackingScriptTest.xml
This file was deleted.
Oops, something went wrong.
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
120 changes: 120 additions & 0 deletions
120
app/code/Magento/MediaContentCatalog/Observer/CategoryDelete.php
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,120 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaContentCatalog\Observer; | ||
|
||
use Magento\Catalog\Model\Category as CatalogCategory; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory; | ||
use Magento\MediaContentApi\Api\Data\ContentAssetLinkInterfaceFactory; | ||
use Magento\MediaContentApi\Api\DeleteContentAssetLinksInterface; | ||
use Magento\MediaContentApi\Model\GetEntityContentsInterface; | ||
use Magento\MediaContentApi\Api\ExtractAssetsFromContentInterface; | ||
|
||
/** | ||
* Observe the catalog_category_delete_after event and deletes relation between category content and media asset. | ||
*/ | ||
class CategoryDelete implements ObserverInterface | ||
{ | ||
private const CONTENT_TYPE = 'catalog_category'; | ||
private const TYPE = 'entityType'; | ||
private const ENTITY_ID = 'entityId'; | ||
private const FIELD = 'field'; | ||
|
||
/** | ||
* @var ContentIdentityInterfaceFactory | ||
*/ | ||
private $contentIdentityFactory; | ||
|
||
/** | ||
* @var ContentAssetLinkInterfaceFactory | ||
*/ | ||
private $contentAssetLinkFactory; | ||
|
||
/** | ||
* @var DeleteContentAssetLinksInterface | ||
*/ | ||
private $deleteContentAssetLinks; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $fields; | ||
|
||
/** | ||
* @var GetEntityContentsInterface | ||
*/ | ||
private $getContent; | ||
|
||
/** | ||
* @var ExtractAssetsFromContentInterface | ||
*/ | ||
private $extractAssetsFromContent; | ||
|
||
/** | ||
* @param ExtractAssetsFromContentInterface $extractAssetsFromContent | ||
* @param GetEntityContentsInterface $getContent | ||
* @param DeleteContentAssetLinksInterface $deleteContentAssetLinks | ||
* @param ContentIdentityInterfaceFactory $contentIdentityFactory | ||
* @param ContentAssetLinkInterfaceFactory $contentAssetLinkFactory | ||
* @param array $fields | ||
*/ | ||
public function __construct( | ||
ExtractAssetsFromContentInterface $extractAssetsFromContent, | ||
GetEntityContentsInterface $getContent, | ||
DeleteContentAssetLinksInterface $deleteContentAssetLinks, | ||
ContentIdentityInterfaceFactory $contentIdentityFactory, | ||
ContentAssetLinkInterfaceFactory $contentAssetLinkFactory, | ||
array $fields | ||
) { | ||
$this->extractAssetsFromContent = $extractAssetsFromContent; | ||
$this->getContent = $getContent; | ||
$this->deleteContentAssetLinks = $deleteContentAssetLinks; | ||
$this->contentAssetLinkFactory = $contentAssetLinkFactory; | ||
$this->contentIdentityFactory = $contentIdentityFactory; | ||
$this->fields = $fields; | ||
} | ||
|
||
/** | ||
* Retrieve the deleted category and remove relation betwen category and asset | ||
* | ||
* @param Observer $observer | ||
* @throws \Exception | ||
*/ | ||
public function execute(Observer $observer): void | ||
{ | ||
$category = $observer->getEvent()->getData('category'); | ||
$contentAssetLinks = []; | ||
|
||
if ($category instanceof CatalogCategory) { | ||
foreach ($this->fields as $field) { | ||
$contentIdentity = $this->contentIdentityFactory->create( | ||
[ | ||
self::TYPE => self::CONTENT_TYPE, | ||
self::FIELD => $field, | ||
self::ENTITY_ID => (string) $category->getEntityId(), | ||
] | ||
); | ||
$content = implode(PHP_EOL, $this->getContent->execute($contentIdentity)); | ||
$assets = $this->extractAssetsFromContent->execute($content); | ||
|
||
foreach ($assets as $asset) { | ||
$contentAssetLinks[] = $this->contentAssetLinkFactory->create( | ||
[ | ||
'assetId' => $asset->getId(), | ||
'contentIdentity' => $contentIdentity | ||
] | ||
); | ||
} | ||
} | ||
if (!empty($contentAssetLinks)) { | ||
$this->deleteContentAssetLinks->execute($contentAssetLinks); | ||
} | ||
} | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
app/code/Magento/MediaContentCatalog/Observer/ProductDelete.php
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,120 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaContentCatalog\Observer; | ||
|
||
use Magento\Catalog\Model\Product as CatalogProduct; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory; | ||
use Magento\MediaContentApi\Api\Data\ContentAssetLinkInterfaceFactory; | ||
use Magento\MediaContentApi\Api\DeleteContentAssetLinksInterface; | ||
use Magento\MediaContentApi\Model\GetEntityContentsInterface; | ||
use Magento\MediaContentApi\Api\ExtractAssetsFromContentInterface; | ||
|
||
/** | ||
* Observe the catalog_product_delete_before event and deletes relation between category content and media asset. | ||
*/ | ||
class ProductDelete implements ObserverInterface | ||
{ | ||
private const CONTENT_TYPE = 'catalog_product'; | ||
private const TYPE = 'entityType'; | ||
private const ENTITY_ID = 'entityId'; | ||
private const FIELD = 'field'; | ||
|
||
/** | ||
* @var ContentIdentityInterfaceFactory | ||
*/ | ||
private $contentIdentityFactory; | ||
|
||
/** | ||
* @var ContentAssetLinkInterfaceFactory | ||
*/ | ||
private $contentAssetLinkFactory; | ||
|
||
/** | ||
* @var DeleteContentAssetLinksInterface | ||
*/ | ||
private $deleteContentAssetLinks; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $fields; | ||
|
||
/** | ||
* @var GetEntityContentsInterface | ||
*/ | ||
private $getContent; | ||
|
||
/** | ||
* @var ExtractAssetsFromContentInterface | ||
*/ | ||
private $extractAssetsFromContent; | ||
|
||
/** | ||
* @param ExtractAssetsFromContentInterface $extractAssetsFromContent | ||
* @param GetEntityContentsInterface $getContent | ||
* @param DeleteContentAssetLinksInterface $deleteContentAssetLinks | ||
* @param ContentIdentityInterfaceFactory $contentIdentityFactory | ||
* @param ContentAssetLinkInterfaceFactory $contentAssetLinkFactory | ||
* @param array $fields | ||
*/ | ||
public function __construct( | ||
ExtractAssetsFromContentInterface $extractAssetsFromContent, | ||
GetEntityContentsInterface $getContent, | ||
DeleteContentAssetLinksInterface $deleteContentAssetLinks, | ||
ContentIdentityInterfaceFactory $contentIdentityFactory, | ||
ContentAssetLinkInterfaceFactory $contentAssetLinkFactory, | ||
array $fields | ||
) { | ||
$this->extractAssetsFromContent = $extractAssetsFromContent; | ||
$this->getContent = $getContent; | ||
$this->deleteContentAssetLinks = $deleteContentAssetLinks; | ||
$this->contentAssetLinkFactory = $contentAssetLinkFactory; | ||
$this->contentIdentityFactory = $contentIdentityFactory; | ||
$this->fields = $fields; | ||
} | ||
|
||
/** | ||
* Retrieve the deleted product and remove relation betwen product and asset | ||
* | ||
* @param Observer $observer | ||
* @throws \Exception | ||
*/ | ||
public function execute(Observer $observer): void | ||
{ | ||
$product = $observer->getEvent()->getData('product'); | ||
$contentAssetLinks = []; | ||
|
||
if ($product instanceof CatalogProduct) { | ||
foreach ($this->fields as $field) { | ||
$contentIdentity = $this->contentIdentityFactory->create( | ||
[ | ||
self::TYPE => self::CONTENT_TYPE, | ||
self::FIELD => $field, | ||
self::ENTITY_ID => (string) $product->getEntityId(), | ||
] | ||
); | ||
$productContent = implode(PHP_EOL, $this->getContent->execute($contentIdentity)); | ||
$assets = $this->extractAssetsFromContent->execute($productContent); | ||
|
||
foreach ($assets as $asset) { | ||
$contentAssetLinks[] = $this->contentAssetLinkFactory->create( | ||
[ | ||
'assetId' => $asset->getId(), | ||
'contentIdentity' => $contentIdentity | ||
] | ||
); | ||
} | ||
} | ||
if (!empty($contentAssetLinks)) { | ||
$this->deleteContentAssetLinks->execute($contentAssetLinks); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.