Skip to content

Commit 0b7145a

Browse files
authored
Quickfix/remove serialize (#1152)
1 parent da0f491 commit 0b7145a

File tree

3 files changed

+82
-16
lines changed

3 files changed

+82
-16
lines changed

app/code/community/Algolia/Algoliasearch/Helper/Config.php

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ public function isPartialUpdateEnabled($storeId = null)
236236

237237
public function getAutocompleteSections($storeId = null)
238238
{
239-
$attrs = unserialize(Mage::getStoreConfig(self::AUTOCOMPLETE_SECTIONS, $storeId));
239+
$attrs = array();
240+
$config = Mage::getStoreConfig(self::AUTOCOMPLETE_SECTIONS, $storeId);
241+
242+
if ($config !== null && $config !== '') {
243+
$attrs = \Zend_Serializer::unserialize($config);
244+
}
240245

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

359364
public function getExcludedPages($storeId = null)
360365
{
361-
$attrs = unserialize(Mage::getStoreConfig(self::EXCLUDED_PAGES, $storeId));
366+
$attrs = array();
367+
$config = Mage::getStoreConfig(self::EXCLUDED_PAGES, $storeId);
368+
369+
if ($config !== null && $config !== '') {
370+
$attrs = \Zend_Serializer::unserialize($config);
371+
}
362372

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

385-
$attrs = unserialize(Mage::getStoreConfig(self::SORTING_INDICES, $storeId));
395+
$attrs = array();
396+
$config = Mage::getStoreConfig(self::SORTING_INDICES, $storeId);
397+
398+
if ($config !== null && $config !== '') {
399+
$attrs = \Zend_Serializer::unserialize($config);
400+
}
386401

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

504519
public function getCategoryAdditionalAttributes($storeId = null)
505520
{
506-
$attrs = unserialize(Mage::getStoreConfig(self::CATEGORY_ATTRIBUTES, $storeId));
521+
$attrs = array();
522+
$config = Mage::getStoreConfig(self::CATEGORY_ATTRIBUTES, $storeId);
523+
524+
if ($config !== null && $config !== '') {
525+
$attrs = \Zend_Serializer::unserialize($config);
526+
}
507527

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

515535
public function getProductAdditionalAttributes($storeId = null)
516536
{
517-
$attributes = unserialize(Mage::getStoreConfig(self::PRODUCT_ATTRIBUTES, $storeId));
537+
$attributes = array();
538+
$config = Mage::getStoreConfig(self::PRODUCT_ATTRIBUTES, $storeId);
539+
540+
if ($config !== null && $config !== '') {
541+
$attributes = \Zend_Serializer::unserialize($config);
542+
}
543+
544+
$facets = array();
545+
$config = Mage::getStoreConfig(self::FACETS, $storeId);
518546

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

522-
$sorts = unserialize(Mage::getStoreConfig(self::SORTING_INDICES, $storeId));
552+
$sorts = array();
553+
$config = Mage::getStoreConfig(self::SORTING_INDICES, $storeId);
554+
555+
if ($config !== null && $config !== '') {
556+
$sorts = \Zend_Serializer::unserialize($config);
557+
}
523558
$attributes = $this->addIndexableAttributes($attributes, $sorts, '0');
524559

525-
$customRankings = unserialize(Mage::getStoreConfig(self::PRODUCT_CUSTOM_RANKING, $storeId));
560+
$customRankings = array();
561+
$config = Mage::getStoreConfig(self::PRODUCT_CUSTOM_RANKING, $storeId);
562+
563+
if ($config !== null && $config !== '') {
564+
$customRankings = \Zend_Serializer::unserialize($config);
565+
}
526566
$customRankings = array_filter($customRankings, function ($customRanking) {
527567
return $customRanking['attribute'] != 'custom_attribute';
528568
});
529569
$attributes = $this->addIndexableAttributes($attributes, $customRankings, '0', '0');
530570

571+
531572
if (is_array($attributes)) {
532573
return $attributes;
533574
}
@@ -537,7 +578,13 @@ public function getProductAdditionalAttributes($storeId = null)
537578

538579
public function getFacets($storeId = null)
539580
{
540-
$attrs = unserialize(Mage::getStoreConfig(self::FACETS, $storeId));
581+
$attrs = array();
582+
$config = Mage::getStoreConfig(self::FACETS, $storeId);
583+
584+
if ($config !== null && $config !== '') {
585+
$attrs = \Zend_Serializer::unserialize($config);
586+
}
587+
541588
foreach ($attrs as &$attr) {
542589
if ($attr['type'] == 'other') {
543590
$attr['type'] = $attr['other_type'];
@@ -660,7 +707,12 @@ public function isEnabledSynonyms($storeId = null)
660707

661708
public function getSynonyms($storeId = null)
662709
{
663-
$synonyms = unserialize(Mage::getStoreConfig(self::SYNONYMS, $storeId));
710+
$synonyms = array();
711+
$config = Mage::getStoreConfig(self::SYNONYMS, $storeId);
712+
713+
if ($config !== null && $config !== '') {
714+
$synonyms = \Zend_Serializer::unserialize($config);
715+
}
664716

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

672724
public function getOnewaySynonyms($storeId = null)
673725
{
674-
$onewaySynonyms = unserialize(Mage::getStoreConfig(self::ONEWAY_SYNONYMS, $storeId));
726+
$onewaySynonyms = array();
727+
$config = Mage::getStoreConfig(self::ONEWAY_SYNONYMS, $storeId);
728+
729+
if ($config !== null && $config !== '') {
730+
$onewaySynonyms = \Zend_Serializer::unserialize($config);
731+
}
675732

676733
if (is_array($onewaySynonyms)) {
677734
return $onewaySynonyms;
@@ -734,7 +791,11 @@ public function getBackendRenderingDisplayMode($storeId = null)
734791
public function getNonCastableAttributes($storeId = null)
735792
{
736793
$nonCastableAttributes = array();
737-
$config = unserialize(Mage::getStoreConfig(self::NON_CASTABLE_ATTRIBUTES, $storeId));
794+
$config = Mage::getStoreConfig(self::NON_CASTABLE_ATTRIBUTES, $storeId);
795+
796+
if ($config !== null && $config !== '') {
797+
$config = \Zend_Serializer::unserialize($config);
798+
}
738799

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

750811
private function getCustomRanking($configName, $storeId = null)
751812
{
752-
$attrs = unserialize(Mage::getStoreConfig($configName, $storeId));
813+
$attrs = array();
814+
$config = Mage::getStoreConfig($configName, $storeId);
815+
816+
if ($config !== null && $config !== '') {
817+
$attrs = \Zend_Serializer::unserialize($config);
818+
}
753819

754820
if (is_array($attrs)) {
755821
foreach ($attrs as $index => $attr) {

app/code/community/Algolia/Algoliasearch/Helper/Entity/Suggestionhelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getPopularQueries($storeId)
5151
// load from cache if we can
5252
$cachedPopularQueries = Mage::app()->loadCache($this->_popularQueriesCacheId);
5353
if ($cachedPopularQueries) {
54-
$this->_popularQueries = unserialize($cachedPopularQueries);
54+
$this->_popularQueries = \Zend_Serializer::unserialize((string) $cachedPopularQueries);
5555
} else {
5656
$collection = Mage::getResourceModel('catalogsearch/query_collection');
5757
$collection->getSelect()->where('num_results >= '.$this->config->getMinNumberOfResults().' AND popularity >= '.$this->config->getMinPopularity().' AND query_text != "__empty__"');
@@ -77,7 +77,7 @@ public function getPopularQueries($storeId)
7777

7878
$this->_popularQueries = array_slice($suggestions, 0, 9);
7979
try { //save to cache
80-
$cacheContent = serialize($this->_popularQueries);
80+
$cacheContent = \Zend_Serializer::serialize($this->_popularQueries);
8181
$tags = array(
8282
Mage_CatalogSearch_Model_Query::CACHE_TAG,
8383
);

app/code/community/Algolia/Algoliasearch/Model/System/Config/Backend/Serialized/Array.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ protected function _afterLoad()
99
if ($helper->isX3Version()) {
1010
if (!is_array($this->getValue())) {
1111
$value = $this->getValue();
12-
$this->setValue(empty($value) ? false : unserialize($value));
12+
$this->setValue(empty($value) ? false : \Zend_Serializer::unserialize((string) $value));
1313
}
1414

1515
return;

0 commit comments

Comments
 (0)