Skip to content

Commit

Permalink
Merge pull request #316 from Inchoo/bugfix/#251-magento-marketplace-s…
Browse files Browse the repository at this point in the history
…ubmission-errors-additional

Bugfix/#251 magento marketplace submission errors additional
  • Loading branch information
vvuksan authored Oct 8, 2019
2 parents ebe6feb + 1b49fd1 commit c1cfd90
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Console/Command/SerializeToJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // @c
$oldData = $this->scopeConfig->getValue($path);

try {
$oldData = unserialize($oldData); // @codingStandardsIgnoreLine - used for conversion of old Magento format to json_decode
$oldData = $this->productMetadata->unserialize($oldData);
} catch (\Exception $e) {
$oldData = false;
}
Expand Down
11 changes: 10 additions & 1 deletion Controller/Adminhtml/FastlyCdn/RateLimiting/UpdatePaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ public function execute()
unset($paths[$key]);
continue;
}
$pregMatch = @preg_match('{' . $value['path'] . '}', null); // @codingStandardsIgnoreLine - silencing errors

if (substr($value['path'], -1) === '\\') {
return $result->setData([
'status' => false,
'msg' => $value['path'] . ' is not a valid regular expression'
]);
}

$pregMatch = preg_match('{' . $value['path'] . '}', null);

if ($pregMatch === false) {
return $result->setData([
'status' => false,
Expand Down
37 changes: 35 additions & 2 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
*/
namespace Fastly\Cdn\Model;

use Magento\Framework\App\Cache\StateInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\Module\Dir;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\PageCache\Model\Varnish\VclGeneratorFactory;
use Magento\Framework\Serialize\SerializerInterface;

/**
* Model is responsible for replacing default vcl template
Expand Down Expand Up @@ -508,6 +514,33 @@ class Config extends \Magento\PageCache\Model\Config
*/
const UPDATED_VCL_FLAG = 'Fastly/Cdn/updated_VCL_to_Fastly_flag';

/**
* @var SerializerInterface
*/
private $serializerInterface;
/**
* Config constructor.
* @param ReadFactory $readFactory
* @param ScopeConfigInterface $scopeConfig
* @param StateInterface $cacheState
* @param Dir\Reader $reader
* @param VclGeneratorFactory $vclGeneratorFactory
* @param SerializerInterface $serializerInterface
* @param Json|null $serializer
*/
public function __construct(
ReadFactory $readFactory,
ScopeConfigInterface $scopeConfig,
StateInterface $cacheState,
Dir\Reader $reader,
VclGeneratorFactory $vclGeneratorFactory,
SerializerInterface $serializerInterface,
Json $serializer = null
) {
$this->serializerInterface = $serializerInterface;
parent::__construct($readFactory, $scopeConfig, $cacheState, $reader, $vclGeneratorFactory, $serializer);
}

/**
* Check if Fastly is selected for Caching Application
*
Expand Down Expand Up @@ -1016,7 +1049,7 @@ private function extractMapping($mapping, $countryCode)
$extractMapping = json_decode($mapping, true);
if (!$extractMapping) {
try {
$extractMapping = unserialize($mapping); // @codingStandardsIgnoreLine
$extractMapping = $this->serializerInterface->unserialize($mapping);
} catch (\Exception $e) {
$extractMapping = [];
}
Expand Down Expand Up @@ -1203,7 +1236,7 @@ private function getDesignExceptions()
);
if ($expressions) {
try {
$expressions = unserialize($expressions); // @codingStandardsIgnoreLine - used for conversion of old Magento format to json_decode
$expressions = $this->serializerInterface->unserialize($expressions);
} catch (\Exception $e) {
$expressions = [];
}
Expand Down
50 changes: 49 additions & 1 deletion Model/Config/Backend/Geoipcountry.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
namespace Fastly\Cdn\Model\Config\Backend;

use Magento\Config\Model\Config\Backend\Serialized\ArraySerialized;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Serialize\SerializerInterface;

/**
* Class Geoipcountry
Expand All @@ -30,14 +38,54 @@
*/
class Geoipcountry extends ArraySerialized
{
/**
* @var SerializerInterface
*/
private $serializerInterface;
/**
* Geoipcountry constructor.
* @param Context $context
* @param Registry $registry
* @param ScopeConfigInterface $config
* @param TypeListInterface $cacheTypeList
* @param SerializerInterface $serializerInterface
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param array $data
* @param Json|null $serializer
*/
public function __construct(
Context $context,
Registry $registry,
ScopeConfigInterface $config,
TypeListInterface $cacheTypeList,
SerializerInterface $serializerInterface,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
array $data = [],
Json $serializer = null
) {
$this->serializerInterface = $serializerInterface;
parent::__construct(
$context,
$registry,
$config,
$cacheTypeList,
$resource,
$resourceCollection,
$data,
$serializer
);
}

protected function _afterLoad() // @codingStandardsIgnoreLine - required by parent class
{
$value = $this->getValue();

$oldData = json_decode($value, true);
if (!$oldData) {
try {
$oldData = unserialize($value); // @codingStandardsIgnoreLine - fallback to prior magento versions
$oldData = $this->serializerInterface->unserialize($value);
} catch (\Exception $e) {
$oldData = false;
}
Expand Down
14 changes: 11 additions & 3 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Fastly\Cdn\Model\Statistic;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Serialize\SerializerInterface;
use Fastly\Cdn\Model\Statistic;

/**
* Class UpgradeData
Expand Down Expand Up @@ -68,6 +69,10 @@ class UpgradeData implements UpgradeDataInterface
* @var ProductMetadataInterface
*/
private $productMetadata;
/**
* @var SerializerInterface
*/
private $serializeInterface;

/**
* UpgradeData constructor.
Expand All @@ -78,6 +83,7 @@ class UpgradeData implements UpgradeDataInterface
* @param Manager $cacheManager
* @param Data $helper
* @param ProductMetadataInterface $productMetadata
* @param SerializerInterface $serializeInterface
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
Expand All @@ -86,7 +92,8 @@ public function __construct(
DateTime $date,
Manager $cacheManager,
Data $helper,
ProductMetadataInterface $productMetadata
ProductMetadataInterface $productMetadata,
SerializerInterface $serializeInterface
) {
$this->date = $date;
$this->scopeConfig = $scopeConfig;
Expand All @@ -95,6 +102,7 @@ public function __construct(
$this->helper = $helper;
$this->productMetadata = $productMetadata;
$this->cacheManager = $cacheManager;
$this->serializeInterface = $serializeInterface;
}

/**
Expand Down Expand Up @@ -221,7 +229,7 @@ private function upgrade1010($newConfigPaths)
{
$oldData = $this->scopeConfig->getValue($newConfigPaths['geoip_country_mapping']);
try {
$oldData = unserialize($oldData); // @codingStandardsIgnoreLine - used for conversion of old Magento format to json_decode
$oldData = $this->serializeInterface->unserialize($oldData);
} catch (\Exception $e) {
$oldData = [];
}
Expand Down

0 comments on commit c1cfd90

Please sign in to comment.