-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feature/collect-ca…
…tegory-listing
- Loading branch information
Showing
16 changed files
with
431 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2020, Nosto Solutions Ltd | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @author Nosto Solutions Ltd <[email protected]> | ||
* @copyright 2020 Nosto Solutions Ltd | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause | ||
* | ||
*/ | ||
|
||
namespace Nosto\Tagging\Model\Service\Sync\Delete; | ||
|
||
use Nosto\NostoException; | ||
use Nosto\Tagging\Model\Service\Sync\AbstractBulkConsumer; | ||
use Nosto\Tagging\Helper\Scope as NostoHelperScope; | ||
use Magento\Framework\EntityManager\EntityManager; | ||
use Magento\Framework\Json\Helper\Data as JsonHelper; | ||
use Nosto\Tagging\Logger\Logger; | ||
use Magento\Store\Model\App\Emulation; | ||
|
||
class AsyncBulkConsumer extends AbstractBulkConsumer | ||
{ | ||
/** @var DeleteService */ | ||
private DeleteService $deleteService; | ||
|
||
/** @var NostoHelperScope */ | ||
private NostoHelperScope $nostoHelperScope; | ||
|
||
/** | ||
* AsyncBulkConsumer constructor. | ||
* @param DeleteService $deleteService | ||
* @param NostoHelperScope $nostoHelperScope | ||
* @param JsonHelper $jsonHelper | ||
* @param EntityManager $entityManager | ||
* @param Emulation $storeEmulation | ||
* @param Logger $logger | ||
*/ | ||
public function __construct( | ||
DeleteService $deleteService, | ||
NostoHelperScope $nostoHelperScope, | ||
JsonHelper $jsonHelper, | ||
EntityManager $entityManager, | ||
Emulation $storeEmulation, | ||
Logger $logger | ||
) { | ||
$this->deleteService = $deleteService; | ||
$this->nostoHelperScope = $nostoHelperScope; | ||
parent::__construct( | ||
$logger, | ||
$jsonHelper, | ||
$entityManager, | ||
$storeEmulation | ||
); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* @param array $productIds | ||
* @param string $storeId | ||
* @throws NostoException | ||
*/ | ||
public function doOperation(array $productIds, string $storeId) | ||
{ | ||
$store = $this->nostoHelperScope->getStore($storeId); | ||
$this->deleteService->delete($productIds, $store); | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2020, Nosto Solutions Ltd | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @author Nosto Solutions Ltd <[email protected]> | ||
* @copyright 2020 Nosto Solutions Ltd | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause | ||
* | ||
*/ | ||
|
||
namespace Nosto\Tagging\Model\Service\Sync\Delete; | ||
|
||
use Nosto\Tagging\Model\Service\Sync\AbstractBulkPublisher; | ||
|
||
class AsyncBulkPublisher extends AbstractBulkPublisher | ||
{ | ||
public const NOSTO_DELETE_MESSAGE_QUEUE = 'nosto_product_sync.delete'; | ||
public const BULK_SIZE = 100; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getTopicName(): string | ||
{ | ||
return self::NOSTO_DELETE_MESSAGE_QUEUE; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getBulkSize(): int | ||
{ | ||
return self::BULK_SIZE; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getBulkDescription(): string | ||
{ | ||
return sprintf('Delete %d Nosto products', 2); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getMetaData(): string | ||
{ | ||
return 'Delete Nosto products'; | ||
} | ||
} |
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,134 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2020, Nosto Solutions Ltd | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* @author Nosto Solutions Ltd <[email protected]> | ||
* @copyright 2020 Nosto Solutions Ltd | ||
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause | ||
* | ||
*/ | ||
|
||
namespace Nosto\Tagging\Model\Service\Sync\Delete; | ||
|
||
use Exception; | ||
use Magento\Store\Model\Store; | ||
use Nosto\Model\Signup\Account as NostoSignupAccount; | ||
use Nosto\NostoException; | ||
use Nosto\Operation\DeleteProduct; | ||
use Nosto\Tagging\Helper\Account as NostoHelperAccount; | ||
use Nosto\Tagging\Helper\Data as NostoHelperData; | ||
use Nosto\Tagging\Helper\Url as NostoHelperUrl; | ||
use Nosto\Tagging\Logger\Logger as NostoLogger; | ||
use Nosto\Tagging\Model\Service\AbstractService; | ||
use Nosto\Tagging\Model\Service\Cache\CacheService; | ||
|
||
class DeleteService extends AbstractService | ||
{ | ||
|
||
public const BENCHMARK_DELETE_NAME = 'nosto_product_delete'; | ||
public const BENCHMARK_DELETE_BREAKPOINT = 1; | ||
public const PRODUCT_DELETION_BATCH_SIZE = 100; | ||
|
||
/** @var CacheService */ | ||
private CacheService $cacheService; | ||
|
||
/** @var NostoHelperAccount */ | ||
private NostoHelperAccount $nostoHelperAccount; | ||
|
||
/** @var NostoHelperUrl */ | ||
private NostoHelperUrl $nostoHelperUrl; | ||
|
||
/** @var int */ | ||
private int $deleteBatchSize; | ||
|
||
/** | ||
* DeleteService constructor. | ||
* @param CacheService $cacheService | ||
* @param NostoHelperAccount $nostoHelperAccount | ||
* @param NostoHelperData $nostoHelperData | ||
* @param NostoHelperUrl $nostoHelperUrl | ||
* @param NostoLogger $logger | ||
* @param $deleteBatchSize | ||
*/ | ||
public function __construct( | ||
CacheService $cacheService, | ||
NostoHelperAccount $nostoHelperAccount, | ||
NostoHelperData $nostoHelperData, | ||
NostoHelperUrl $nostoHelperUrl, | ||
NostoLogger $logger, | ||
$deleteBatchSize | ||
) { | ||
$this->cacheService = $cacheService; | ||
$this->nostoHelperAccount = $nostoHelperAccount; | ||
$this->nostoHelperUrl = $nostoHelperUrl; | ||
$this->deleteBatchSize = $deleteBatchSize; | ||
parent::__construct($nostoHelperData, $nostoHelperAccount, $logger); | ||
} | ||
|
||
/** | ||
* Discontinues products in Nosto and removes indexed products from Nosto product index | ||
* | ||
* @param array $productIds | ||
* @param Store $store | ||
* @throws NostoException | ||
*/ | ||
public function delete(array $productIds, Store $store) | ||
{ | ||
if (count($productIds) === 0) { | ||
return; | ||
} | ||
$account = $this->nostoHelperAccount->findAccount($store); | ||
if ($account instanceof NostoSignupAccount === false) { | ||
throw new NostoException(sprintf('Store view %s does not have Nosto installed', $store->getName())); | ||
} | ||
$this->startBenchmark(self::BENCHMARK_DELETE_NAME, self::BENCHMARK_DELETE_BREAKPOINT); | ||
$productIdBatches = array_chunk($productIds, $this->deleteBatchSize); | ||
$this->logDebugWithStore( | ||
sprintf( | ||
'Deleting total of %d products in batches of %d', | ||
count($productIds), | ||
count($productIdBatches) | ||
), | ||
$store | ||
); | ||
foreach ($productIdBatches as $ids) { | ||
try { | ||
$op = new DeleteProduct($account, $this->nostoHelperUrl->getActiveDomain($store)); | ||
$op->setResponseTimeout(30); | ||
$op->setProductIds($ids); | ||
$op->delete(); // @codingStandardsIgnoreLine | ||
$this->cacheService->removeByProductIds($store, $ids); | ||
$this->tickBenchmark(self::BENCHMARK_DELETE_NAME); | ||
} catch (Exception $e) { | ||
$this->getLogger()->exception($e); | ||
} | ||
} | ||
$this->logBenchmarkSummary(self::BENCHMARK_DELETE_NAME, $store); | ||
} | ||
} |
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.