Skip to content

Commit

Permalink
create a mechanism, added a warning on adminhtml panel
Browse files Browse the repository at this point in the history
  • Loading branch information
makso8makso committed Nov 27, 2024
1 parent 46d50b4 commit 4c0dde8
Show file tree
Hide file tree
Showing 12 changed files with 348 additions and 52 deletions.
54 changes: 49 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ class Data extends AbstractHelper
public const XML_PATH_MULTI_CURRENCY = 'nosto/multicurrency/method';

/**
* Path to the configuration object for light indexer
* Path to the configuration object for multi currency
*/
public const XML_PATH_USE_LIGHT_INDEXER = 'nosto/flags/use_light_indexer';
public const XML_PATH_MULTI_INDEXER = 'nosto/product_sync/indexer_method';

/**
* @var string Nosto customer reference attribute name
Expand All @@ -203,6 +203,14 @@ class Data extends AbstractHelper
public const SETTING_VALUE_MC_DISABLED = 'disabled';
public const SETTING_VALUE_MC_UNDEFINED = 'undefined';

/**
* Values of the multi indexer settings
*/
public const SETTING_VALUE_MI_PRODUCT_INDEXER = 'productindexer';
public const SETTING_VALUE_MI_PRODUCT_LIGHT_INDEXER = 'productlightindexer';
public const SETTING_VALUE_MI_PRODUCT_DISABLED = 'disabled';
public const SETTING_VALUE_MI_UNDEFINDED = 'undefined';

/**
* Name of the module
*/
Expand Down Expand Up @@ -542,14 +550,50 @@ public function getMultiCurrencyMethod(StoreInterface $store = null)
}

/**
* Returns if the light indexer should be used
* Returns if multi indexer is disabled
*
* @param StoreInterface|null $store the store model or null.
* @return bool the configuration value
*/
public function isMultiIndexerDisabled(StoreInterface $store = null)
{
$storeConfig = $this->getMultiIndexerMethod($store);
return ($storeConfig === self::SETTING_VALUE_MI_PRODUCT_DISABLED);
}

/**
* Returns if multi indexer is enabled
*
* @param StoreInterface|null $store the store model or null.
* @return bool the configuration value
*/
public function isMultiIndexerMainIndexerEnabled(StoreInterface $store = null)
{
$storeConfig = $this->getMultiIndexerMethod($store);
return ($storeConfig === self::SETTING_VALUE_MI_PRODUCT_INDEXER);
}

/**
* Returns if multi indexer is enabled
*
* @param StoreInterface|null $store the store model or null.
* @return bool the configuration value
*/
public function isMultiIndexerLightIndexerEnabled(StoreInterface $store = null)
{
$storeConfig = $this->getMultiIndexerMethod($store);
return ($storeConfig === self::SETTING_VALUE_MI_PRODUCT_LIGHT_INDEXER);
}

/**
* Returns the multi indexer setup value / multi indexer_method
*
* @param StoreInterface|null $store the store model or null.
* @return string the configuration value
*/
public function getUseLightIndexer(StoreInterface $store = null)
public function getMultiIndexerMethod(StoreInterface $store = null)
{
return $this->getStoreConfig(self::XML_PATH_USE_LIGHT_INDEXER, $store);
return $this->getStoreConfig(self::XML_PATH_MULTI_INDEXER, $store);
}

/**
Expand Down
100 changes: 100 additions & 0 deletions Model/Config/Backend/MultiIndexer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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\Config\Backend;

use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Config\Value;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
use Nosto\Tagging\Helper\Data as NostoHelperData;

class MultiIndexer extends Value
{
private WriterInterface $configWriter;

/**
* MultiCurrency constructor.
* @param Context $context
* @param Registry $registry
* @param ScopeConfigInterface $config
* @param TypeListInterface $cacheTypeList
* @param WriterInterface $configWriter
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
ScopeConfigInterface $config,
TypeListInterface $cacheTypeList,
WriterInterface $configWriter,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = []
) {
$this->configWriter = $configWriter;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
}

/**
* @return Value
*/
public function beforeSave() //@codingStandardsIgnoreLine
{
$value = $this->getValue();
$scopeType = $this->getScope();
$scopeId = $this->getScopeId();

if ($value == NostoHelperData::SETTING_VALUE_MI_PRODUCT_INDEXER
|| $value == NostoHelperData::SETTING_VALUE_MI_PRODUCT_LIGHT_INDEXER
) {
// $this->configWriter->save(
// NostoHelperData::XML_PATH_PRICING_VARIATION,
// '0',
// $scopeType,
// $scopeId
// );
}

return parent::beforeSave();
}
}
62 changes: 62 additions & 0 deletions Model/Config/Source/MultiIndexer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\Phrase;
use Nosto\Tagging\Helper\Data;

/**
* Option array class to generate a list of selectable options that allows the merchant to choose
* any image attribute for his image tag.
*/
class MultiIndexer implements OptionSourceInterface
{
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
return [
['value' => Data::SETTING_VALUE_MI_PRODUCT_INDEXER, 'label' => new Phrase('Product Indexer')],
['value' => Data::SETTING_VALUE_MI_PRODUCT_LIGHT_INDEXER, 'label' => new Phrase('Product light indexer')],
['value' => Data::SETTING_VALUE_MI_PRODUCT_DISABLED, 'label' => new Phrase('Disabled')]
];
}
}
33 changes: 33 additions & 0 deletions Model/Config/Source/WebsitePublicity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Nosto\Tagging\Model\Config\Source;

/**
* @api
* @since 100.0.2
*/
class WebsitePublicity implements \Magento\Framework\Option\ArrayInterface
{
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
return [['value' => 1, 'label' => __('Yes')], ['value' => 0, 'label' => __('No')]];
}

/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return [0 => __('No'), 1 => __('Yes')];
}
}
13 changes: 10 additions & 3 deletions Model/Indexer/LightProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use Nosto\Tagging\Model\Service\Indexer\IndexerStatusServiceInterface;
use Symfony\Component\Console\Input\InputInterface;
use Nosto\Tagging\Model\Service\Sync\Recrawl\RecrawlService;
use Nosto\Tagging\Helper\Data as NostoHelperData;

/**
* Class ProductIndexer
Expand All @@ -66,6 +67,9 @@ class LightProductIndexer extends AbstractIndexer
/** @var ProductModeSwitcher */
private ProductModeSwitcher $modeSwitcher;

/** @var NostoHelperData */
protected NostoHelperData $nostoHelperData;

/** @var RecrawlService */
private RecrawlService $recrawlService;

Expand All @@ -81,6 +85,7 @@ class LightProductIndexer extends AbstractIndexer
* @param InputInterface $input
* @param IndexerStatusServiceInterface $indexerStatusService
* @param RecrawlService $recrawlService
* @param NostoHelperData $nostoHelperData
*/
public function __construct(
NostoHelperScope $nostoHelperScope,
Expand All @@ -92,11 +97,13 @@ public function __construct(
ProcessManager $processManager,
InputInterface $input,
IndexerStatusServiceInterface $indexerStatusService,
RecrawlService $recrawlService
RecrawlService $recrawlService,
NostoHelperData $nostoHelperData
) {
$this->productCollectionBuilder = $productCollectionBuilder;
$this->modeSwitcher = $modeSwitcher;
$this->recrawlService = $recrawlService;
$this->nostoHelperData = $nostoHelperData;
parent::__construct(
$nostoHelperScope,
$logger,
Expand All @@ -123,10 +130,10 @@ public function getModeSwitcher(): ModeSwitcherInterface
*/
public function doIndex(Store $store, array $ids = [])
{
// if ($this->nostoHelperData->getUseLightIndexer($store)) {
if ($this->nostoHelperData->isMultiIndexerLightIndexerEnabled($store)) {
$collection = $this->getCollection($store, $ids);
$this->recrawlService->recrawl($collection, $store);
// }
}
}

/**
Expand Down
22 changes: 16 additions & 6 deletions Model/Indexer/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Magento\Store\Model\App\Emulation;
use Magento\Store\Model\Store;
use Nosto\NostoException;
use Nosto\Tagging\Helper\Data as NostoHelperData;
use Nosto\Tagging\Helper\Scope as NostoHelperScope;
use Nosto\Tagging\Logger\Logger as NostoLogger;
use Nosto\Tagging\Model\Indexer\Dimensions\Product\ModeSwitcher as ProductModeSwitcher;
Expand Down Expand Up @@ -69,6 +70,9 @@ class ProductIndexer extends AbstractIndexer
/** @var ProductModeSwitcher */
private ProductModeSwitcher $modeSwitcher;

/** @var NostoHelperData */
protected NostoHelperData $nostoHelperData;

/**
* Invalidate constructor.
* @param NostoHelperScope $nostoHelperScope
Expand All @@ -92,11 +96,13 @@ public function __construct(
Emulation $storeEmulation,
ProcessManager $processManager,
InputInterface $input,
IndexerStatusServiceInterface $indexerStatusService
IndexerStatusServiceInterface $indexerStatusService,
NostoHelperData $nostoHelperData
) {
$this->productUpdateService = $productUpdateService;
$this->productCollectionBuilder = $productCollectionBuilder;
$this->modeSwitcher = $modeSwitcher;
$this->nostoHelperData = $nostoHelperData;
parent::__construct(
$nostoHelperScope,
$logger,
Expand All @@ -123,11 +129,15 @@ public function getModeSwitcher(): ModeSwitcherInterface
*/
public function doIndex(Store $store, array $ids = [])
{
$collection = $this->getCollection($store, $ids);
$this->productUpdateService->addCollectionToUpdateMessageQueue(
$collection,
$store
);
if ($this->nostoHelperData->isMultiIndexerMainIndexerEnabled($store)) {
$collection = $this->getCollection($store, $ids);
$this->productUpdateService->addCollectionToUpdateMessageQueue(
$collection,
$store
);
} else {
$this->nostoLogger->debugWithSource();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Model/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
abstract class AbstractService
{
/** @var NostoDataHelper */
private NostoDataHelper $nostoDataHelper;
protected NostoDataHelper $nostoDataHelper;

/** @var NostoLogger */
private NostoLogger $nostoLogger;
Expand Down
Loading

0 comments on commit 4c0dde8

Please sign in to comment.