Skip to content

Commit

Permalink
Quickfix/remove serialize (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
damcou authored Feb 17, 2020
1 parent da0f491 commit 0b7145a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 16 deletions.
92 changes: 79 additions & 13 deletions app/code/community/Algolia/Algoliasearch/Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ public function isPartialUpdateEnabled($storeId = null)

public function getAutocompleteSections($storeId = null)
{
$attrs = unserialize(Mage::getStoreConfig(self::AUTOCOMPLETE_SECTIONS, $storeId));
$attrs = array();
$config = Mage::getStoreConfig(self::AUTOCOMPLETE_SECTIONS, $storeId);

if ($config !== null && $config !== '') {
$attrs = \Zend_Serializer::unserialize($config);
}

if (is_array($attrs)) {
return array_values($attrs);
Expand Down Expand Up @@ -358,7 +363,12 @@ public function getInstantSelector($storeId = null)

public function getExcludedPages($storeId = null)
{
$attrs = unserialize(Mage::getStoreConfig(self::EXCLUDED_PAGES, $storeId));
$attrs = array();
$config = Mage::getStoreConfig(self::EXCLUDED_PAGES, $storeId);

if ($config !== null && $config !== '') {
$attrs = \Zend_Serializer::unserialize($config);
}

if (is_array($attrs)) {
return $attrs;
Expand All @@ -382,7 +392,12 @@ public function getSortingIndices($storeId = null)
/** @var Algolia_Algoliasearch_Helper_Entity_Producthelper $product_helper */
$product_helper = Mage::helper('algoliasearch/entity_producthelper');

$attrs = unserialize(Mage::getStoreConfig(self::SORTING_INDICES, $storeId));
$attrs = array();
$config = Mage::getStoreConfig(self::SORTING_INDICES, $storeId);

if ($config !== null && $config !== '') {
$attrs = \Zend_Serializer::unserialize($config);
}

/** @var Mage_Customer_Model_Session $customerSession */
$customerSession = Mage::getSingleton('customer/session');
Expand Down Expand Up @@ -503,7 +518,12 @@ public function getAttributesToRetrieve($groupId, $store)

public function getCategoryAdditionalAttributes($storeId = null)
{
$attrs = unserialize(Mage::getStoreConfig(self::CATEGORY_ATTRIBUTES, $storeId));
$attrs = array();
$config = Mage::getStoreConfig(self::CATEGORY_ATTRIBUTES, $storeId);

if ($config !== null && $config !== '') {
$attrs = \Zend_Serializer::unserialize($config);
}

if (is_array($attrs)) {
return $attrs;
Expand All @@ -514,20 +534,41 @@ public function getCategoryAdditionalAttributes($storeId = null)

public function getProductAdditionalAttributes($storeId = null)
{
$attributes = unserialize(Mage::getStoreConfig(self::PRODUCT_ATTRIBUTES, $storeId));
$attributes = array();
$config = Mage::getStoreConfig(self::PRODUCT_ATTRIBUTES, $storeId);

if ($config !== null && $config !== '') {
$attributes = \Zend_Serializer::unserialize($config);
}

$facets = array();
$config = Mage::getStoreConfig(self::FACETS, $storeId);

$facets = unserialize(Mage::getStoreConfig(self::FACETS, $storeId));
if ($config !== null && $config !== '') {
$facets = \Zend_Serializer::unserialize($config);
}
$attributes = $this->addIndexableAttributes($attributes, $facets, '0');

$sorts = unserialize(Mage::getStoreConfig(self::SORTING_INDICES, $storeId));
$sorts = array();
$config = Mage::getStoreConfig(self::SORTING_INDICES, $storeId);

if ($config !== null && $config !== '') {
$sorts = \Zend_Serializer::unserialize($config);
}
$attributes = $this->addIndexableAttributes($attributes, $sorts, '0');

$customRankings = unserialize(Mage::getStoreConfig(self::PRODUCT_CUSTOM_RANKING, $storeId));
$customRankings = array();
$config = Mage::getStoreConfig(self::PRODUCT_CUSTOM_RANKING, $storeId);

if ($config !== null && $config !== '') {
$customRankings = \Zend_Serializer::unserialize($config);
}
$customRankings = array_filter($customRankings, function ($customRanking) {
return $customRanking['attribute'] != 'custom_attribute';
});
$attributes = $this->addIndexableAttributes($attributes, $customRankings, '0', '0');


if (is_array($attributes)) {
return $attributes;
}
Expand All @@ -537,7 +578,13 @@ public function getProductAdditionalAttributes($storeId = null)

public function getFacets($storeId = null)
{
$attrs = unserialize(Mage::getStoreConfig(self::FACETS, $storeId));
$attrs = array();
$config = Mage::getStoreConfig(self::FACETS, $storeId);

if ($config !== null && $config !== '') {
$attrs = \Zend_Serializer::unserialize($config);
}

foreach ($attrs as &$attr) {
if ($attr['type'] == 'other') {
$attr['type'] = $attr['other_type'];
Expand Down Expand Up @@ -660,7 +707,12 @@ public function isEnabledSynonyms($storeId = null)

public function getSynonyms($storeId = null)
{
$synonyms = unserialize(Mage::getStoreConfig(self::SYNONYMS, $storeId));
$synonyms = array();
$config = Mage::getStoreConfig(self::SYNONYMS, $storeId);

if ($config !== null && $config !== '') {
$synonyms = \Zend_Serializer::unserialize($config);
}

if (is_array($synonyms)) {
return $synonyms;
Expand All @@ -671,7 +723,12 @@ public function getSynonyms($storeId = null)

public function getOnewaySynonyms($storeId = null)
{
$onewaySynonyms = unserialize(Mage::getStoreConfig(self::ONEWAY_SYNONYMS, $storeId));
$onewaySynonyms = array();
$config = Mage::getStoreConfig(self::ONEWAY_SYNONYMS, $storeId);

if ($config !== null && $config !== '') {
$onewaySynonyms = \Zend_Serializer::unserialize($config);
}

if (is_array($onewaySynonyms)) {
return $onewaySynonyms;
Expand Down Expand Up @@ -734,7 +791,11 @@ public function getBackendRenderingDisplayMode($storeId = null)
public function getNonCastableAttributes($storeId = null)
{
$nonCastableAttributes = array();
$config = unserialize(Mage::getStoreConfig(self::NON_CASTABLE_ATTRIBUTES, $storeId));
$config = Mage::getStoreConfig(self::NON_CASTABLE_ATTRIBUTES, $storeId);

if ($config !== null && $config !== '') {
$config = \Zend_Serializer::unserialize($config);
}

if (is_array($config)) {
foreach ($config as $attributeData) {
Expand All @@ -749,7 +810,12 @@ public function getNonCastableAttributes($storeId = null)

private function getCustomRanking($configName, $storeId = null)
{
$attrs = unserialize(Mage::getStoreConfig($configName, $storeId));
$attrs = array();
$config = Mage::getStoreConfig($configName, $storeId);

if ($config !== null && $config !== '') {
$attrs = \Zend_Serializer::unserialize($config);
}

if (is_array($attrs)) {
foreach ($attrs as $index => $attr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getPopularQueries($storeId)
// load from cache if we can
$cachedPopularQueries = Mage::app()->loadCache($this->_popularQueriesCacheId);
if ($cachedPopularQueries) {
$this->_popularQueries = unserialize($cachedPopularQueries);
$this->_popularQueries = \Zend_Serializer::unserialize((string) $cachedPopularQueries);
} else {
$collection = Mage::getResourceModel('catalogsearch/query_collection');
$collection->getSelect()->where('num_results >= '.$this->config->getMinNumberOfResults().' AND popularity >= '.$this->config->getMinPopularity().' AND query_text != "__empty__"');
Expand All @@ -77,7 +77,7 @@ public function getPopularQueries($storeId)

$this->_popularQueries = array_slice($suggestions, 0, 9);
try { //save to cache
$cacheContent = serialize($this->_popularQueries);
$cacheContent = \Zend_Serializer::serialize($this->_popularQueries);
$tags = array(
Mage_CatalogSearch_Model_Query::CACHE_TAG,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected function _afterLoad()
if ($helper->isX3Version()) {
if (!is_array($this->getValue())) {
$value = $this->getValue();
$this->setValue(empty($value) ? false : unserialize($value));
$this->setValue(empty($value) ? false : \Zend_Serializer::unserialize((string) $value));
}

return;
Expand Down

0 comments on commit 0b7145a

Please sign in to comment.