Skip to content

Commit

Permalink
Pedror/unplugged 850 update scope in update (#275)
Browse files Browse the repository at this point in the history
* Fix json serialization

* Add data patch for magento 2.3
  • Loading branch information
frobs committed May 29, 2023
1 parent b896728 commit d00fede
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 92 deletions.
3 changes: 1 addition & 2 deletions Controller/Adminhtml/Integration/CreateStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Magento\Integration\Block\Adminhtml\Integration\Tokens;
use Magento\Store\Api\Data\StoreInterface;
use Psr\Log\LoggerInterface;
use Doofinder\Feed\Helper\JsonSerialization;

class CreateStore extends Action implements HttpGetActionInterface
{
Expand Down Expand Up @@ -234,7 +233,7 @@ private function setCustomAttributes()
];
}

$customAttributes = JsonSerialization::encode($attributes);
$customAttributes = json_encode($attributes);
$this->storeConfig->setCustomAttributes($customAttributes);
}

Expand Down
7 changes: 3 additions & 4 deletions Cron/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Doofinder\Feed\Model\ResourceModel\ChangedProduct\CollectionFactory as ChangedProductCollectionFactory;
use Magento\Framework\Indexer\SaveHandler\Batch;
use Psr\Log\LoggerInterface;
use Doofinder\Feed\Helper\JsonSerialization;

class Processor
{
Expand Down Expand Up @@ -100,7 +99,7 @@ private function createProducts($store, $indice)
if (count($items)) {
try {
$this->logger->debug('[CreateInBulk]');
$this->logger->debug(JsonSerialization::encode($items));
$this->logger->debug(json_encode($items));
$this->itemHelper->createItemsInBulk($items, $store, $indice);
} catch (\Exception $e) {
$this->logger->error(
Expand Down Expand Up @@ -129,7 +128,7 @@ private function updateProducts($store, $indice)
if (count($items)) {
try {
$this->logger->debug('[UpdateInBulk]');
$this->logger->debug(JsonSerialization::encode($items));
$this->logger->debug(json_encode($items));
$this->itemHelper->updateItemsInBulk($items, $store, $indice);
} catch (\Exception $e) {
$this->logger->error(
Expand Down Expand Up @@ -157,7 +156,7 @@ private function deleteProducts($store, $indice)
if (count($items)) {
try {
$this->logger->debug('[DeleteInBulk]');
$this->logger->debug(JsonSerialization::encode($items));
$this->logger->debug(json_encode($items));
$this->itemHelper->deleteItemsInBulk($items, $store, $indice);
} catch (\Exception $e) {
$this->logger->error(
Expand Down
27 changes: 0 additions & 27 deletions Helper/JsonSerialization.php

This file was deleted.

3 changes: 1 addition & 2 deletions Helper/StoreConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Magento\Eav\Model\Config;
use Doofinder\Feed\Errors\NotFound;
use Magento\Backend\Helper\Data;
use Doofinder\Feed\Helper\JsonSerialization;

/**
* Store config helper
Expand Down Expand Up @@ -912,7 +911,7 @@ public function getIndexationStatus(int $storeId): array {
*/
public function setIndexationStatus(array $status, int $storeId){
$status = $this->indexationHelper->sanitizeProcessTaskStatus($status);
$status = JsonSerialization::encode($status);
$status = json_encode($status);
$this->configWriter->save(self::INDEXATION_STATUS, $status, ScopeInterface::SCOPE_STORES, $storeId);
}

Expand Down
74 changes: 74 additions & 0 deletions Setup/Patch/Data/UpgradeToStoreGroupPatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Doofinder\Feed\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\ResourceModel\Group\CollectionFactory as GroupCollectionFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;

class UpgradeToStoreGroupPatch implements DataPatchInterface, PatchVersionInterface
{
private $moduleDataSetup;
private $storeManager;
private $configWriter;
private $scopeConfig;
private $groupCollectionFactory;

public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
StoreManagerInterface $storeManager,
WriterInterface $configWriter,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
GroupCollectionFactory $groupCollectionFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->storeManager = $storeManager;
$this->configWriter = $configWriter;
$this->scopeConfig = $scopeConfig;
$this->groupCollectionFactory = $groupCollectionFactory;
}

public function apply()
{
$this->moduleDataSetup->startSetup();

$groupCollection = $this->groupCollectionFactory->create();
$scriptIdPath = 'doofinder_config_config/doofinder_layer/script';
$installationIdPath = 'doofinder_config_config/doofinder_layer/installation_id';

foreach ($groupCollection as $group) {
$websiteId = $group->getWebsiteId();
$script = $this->scopeConfig->getValue($scriptIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
if(!empty($script)) {
$this->configWriter->save($scriptIdPath, $script, ScopeInterface::SCOPE_GROUP, $group->getId());
$this->configWriter->delete($scriptIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
}

$installationId = $this->scopeConfig->getValue($installationIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
if(!empty($installationId)) {
$this->configWriter->save($installationIdPath, $installationId, ScopeInterface::SCOPE_GROUP, $group->getId());
$this->configWriter->delete($installationIdPath, ScopeInterface::SCOPE_WEBSITES, $websiteId);
}
}
$this->moduleDataSetup->endSetup();
}

public static function getDependencies()
{
return [];
}

public function getAliases()
{
return [];
}

public static function getVersion()
{
return '0.11.1';
}
}
57 changes: 0 additions & 57 deletions Setup/UpgradeData.php

This file was deleted.

0 comments on commit d00fede

Please sign in to comment.