Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #11 from meanbee/9-m2.2-unserialize-error
Browse files Browse the repository at this point in the history
Use Json serializer to process custom strategies
  • Loading branch information
tgerulaitis authored Nov 28, 2017
2 parents 7e89c1c + d1df918 commit f228200
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ class Config extends \Magento\Framework\App\Helper\AbstractHelper
/** @var \Magento\Cms\Helper\Page $cmsPageHelper */
protected $cmsPageHelper;

/** @var \Magento\Framework\Serialize\Serializer\Json $serializer */
protected $serializer;

public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Cms\Helper\Page $cmsPageHelper
\Magento\Cms\Helper\Page $cmsPageHelper,
\Magento\Framework\Serialize\Serializer\Json $serializer
) {
parent::__construct($context);

$this->cmsPageHelper = $cmsPageHelper;
$this->serializer = $serializer;
}

/**
Expand Down Expand Up @@ -65,7 +70,7 @@ public function getCustomStrategies($store = null)
$custom_strategies = $this->scopeConfig->getValue(static::XML_PATH_CUSTOM_STRATEGIES, ScopeInterface::SCOPE_STORE, $store);

if (is_string($custom_strategies) && !empty($custom_strategies)) {
$custom_strategies = unserialize($custom_strategies);
$custom_strategies = $this->serializer->unserialize($custom_strategies);
}

if (!is_array($custom_strategies)) {
Expand Down
9 changes: 7 additions & 2 deletions src/Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ class InstallData implements InstallDataInterface
/** @var \Magento\Framework\App\Config\Storage\WriterInterface $configWriter */
protected $configWriter;

/** @var \Magento\Framework\Serialize\Serializer\Json $serializer */
protected $serializer;

public function __construct(
\Magento\Cms\Model\PageFactory $pageFactory,
\Magento\Cms\Model\PageRepository $pageRepository,
\Magento\Framework\App\Config\Storage\WriterInterface $configWriter
\Magento\Framework\App\Config\Storage\WriterInterface $configWriter,
\Magento\Framework\Serialize\Serializer\Json $serializer
) {
$this->pageFactory = $pageFactory;
$this->pageRepository = $pageRepository;
$this->configWriter = $configWriter;
$this->serializer = $serializer;
}

/**
Expand Down Expand Up @@ -74,7 +79,7 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface

$this->configWriter->save(
"web/serviceworker/custom_strategies",
serialize($strategies)
$this->serializer->serialize($strategies)
);

$setup->endSetup();
Expand Down
11 changes: 8 additions & 3 deletions src/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ class UpgradeData implements UpgradeDataInterface
/** @var \Magento\Framework\App\Config\Storage\WriterInterface $configWriter */
protected $configWriter;

/** @var \Magento\Framework\Serialize\Serializer\Json $serializer */
protected $serializer;

public function __construct(
\Magento\Framework\App\Config\ValueInterface $configReader,
\Magento\Framework\App\Config\Storage\WriterInterface $configWriter
\Magento\Framework\App\Config\Storage\WriterInterface $configWriter,
\Magento\Framework\Serialize\Serializer\Json $serializer
) {
$this->configReader = $configReader;
$this->configWriter = $configWriter;
$this->serializer = $serializer;
}

/**
Expand Down Expand Up @@ -63,7 +68,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface

$this->configWriter->save(
"web/serviceworker/custom_strategies",
serialize($value),
$this->serializer->serialize($value),
$config->getScope(),
$config->getScopeId()
);
Expand All @@ -87,7 +92,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface

$this->configWriter->save(
"web/serviceworker/custom_strategies",
serialize($strategies)
$this->serializer->serialize($strategies)
);
}
}
Expand Down

0 comments on commit f228200

Please sign in to comment.