Skip to content

Commit

Permalink
Added helper methods to cast Mage::getStoreConfig() to int or float,
Browse files Browse the repository at this point in the history
…fixes #3727 (#3736)

* Added helper methods to cast getStoreConfig to int or float

* Use Mage::getStoreConfigFlag()

---------

Co-authored-by: Ng Kiat Siong <kiatsiong.ng@gmail.com>
  • Loading branch information
sreichel and kiatng authored Feb 2, 2024
1 parent 7a3e765 commit 88afdb1
Show file tree
Hide file tree
Showing 32 changed files with 67 additions and 47 deletions.
20 changes: 20 additions & 0 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,26 @@ public static function getStoreConfig($path, $store = null)
return self::app()->getStore($store)->getConfig($path);
}

/**
* @param string $path
* @param null|string|bool|int|Mage_Core_Model_Store $store
* @return float
*/
public static function getStoreConfigAsFloat(string $path, $store = null): float
{
return (float) self::getStoreConfig($path, $store);
}

/**
* @param string $path
* @param null|string|bool|int|Mage_Core_Model_Store $store
* @return int
*/
public static function getStoreConfigAsInt(string $path, $store = null): int
{
return (int) self::getStoreConfig($path, $store);
}

/**
* Retrieve config flag for store by path
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public function getUserCreateAdditionalEmail()
*/
public function getMinAdminPasswordLength()
{
$minLength = (int)Mage::getStoreConfig(self::XML_PATH_MIN_ADMIN_PASSWORD_LENGTH);
$minLength = Mage::getStoreConfigAsInt(self::XML_PATH_MIN_ADMIN_PASSWORD_LENGTH);
$absoluteMinLength = Mage_Core_Model_App::ABSOLUTE_MIN_PASSWORD_LENGTH;
return ($minLength < $absoluteMinLength) ? $absoluteMinLength : $minLength;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function _canShowNotification()
if ($this->_isFileAccessible()) {
return true;
}
$adminSessionLifetime = (int)Mage::getStoreConfig('admin/security/session_cookie_lifetime');
$adminSessionLifetime = Mage::getStoreConfigAsInt('admin/security/session_cookie_lifetime');
Mage::app()->saveCache(true, self::VERIFICATION_RESULT_CACHE_KEY, [], $adminSessionLifetime);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Page/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public function getFormKey()
*/
public function getLoadingTimeout()
{
return (int)Mage::getStoreConfig('admin/design/loading_timeout');
return Mage::getStoreConfigAsInt('admin/design/loading_timeout');
}
}
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Helper/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function init(Mage_Catalog_Model_Product $product, $attributeName, $image
Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_image")
);
$this->setWatermarkImageOpacity(
Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity")
Mage::getStoreConfigAsInt("design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity")
);
$this->setWatermarkPosition(
Mage::getStoreConfig("design/watermark/{$this->_getModel()->getDestinationSubdir()}_position")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ protected function _prepareDataForSave($product, $productData)
if (!$productData['use_config_gift_message_available']
&& ($product->getData('gift_message_available') === null)
) {
$product->setData('gift_message_available', (int) Mage::getStoreConfig(
$product->setData('gift_message_available', Mage::getStoreConfigAsInt(
Mage_GiftMessage_Helper_Message::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS,
$product->getStoreId()
));
Expand All @@ -288,7 +288,7 @@ protected function _prepareDataForSave($product, $productData)
&& ($product->getData('gift_wrapping_available') === null)
) {
$xmlPathGiftWrappingAvailable = 'sales/gift_options/wrapping_allow_items';
$product->setData('gift_wrapping_available', (int)Mage::getStoreConfig(
$product->setData('gift_wrapping_available', Mage::getStoreConfigAsInt(
$xmlPathGiftWrappingAvailable,
$product->getStoreId()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getStockQty()
public function getThresholdQty()
{
if (!$this->hasData('threshold_qty')) {
$qty = (float) Mage::getStoreConfig(self::XML_PATH_STOCK_THRESHOLD_QTY);
$qty = Mage::getStoreConfigAsFloat(self::XML_PATH_STOCK_THRESHOLD_QTY);
$this->setData('threshold_qty', $qty);
}
return $this->getData('threshold_qty');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function _initConfig()
];

foreach ($configMap as $field => $const) {
$this->$field = (int)Mage::getStoreConfig($const);
$this->$field = Mage::getStoreConfigAsInt($const);
}

$this->_isConfig = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function _getLoadSelect($field, $value, $object)
public function addCatalogInventoryToProductCollection($productCollection)
{
$adapter = $this->_getReadAdapter();
$isManageStock = (int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
$isManageStock = Mage::getStoreConfigAsInt(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
$stockExpr = $adapter->getCheckSql('cisi.use_config_manage_stock = 1', $isManageStock, 'cisi.manage_stock');
$stockExpr = $adapter->getCheckSql("({$stockExpr} = 1)", 'cisi.is_in_stock', '1');

Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public function getMaxSaleQty()
public function getNotifyStockQty()
{
if ($this->getUseConfigNotifyStockQty()) {
return (float) Mage::getStoreConfig(self::XML_PATH_NOTIFY_STOCK_QTY);
return Mage::getStoreConfigAsFloat(self::XML_PATH_NOTIFY_STOCK_QTY);
}
return (float) $this->getData('notify_stock_qty');
}
Expand Down Expand Up @@ -411,7 +411,7 @@ public function getQtyIncrements()
public function getDefaultQtyIncrements()
{
return Mage::getStoreConfigFlag(self::XML_PATH_ENABLE_QTY_INCREMENTS)
? (int)Mage::getStoreConfig(self::XML_PATH_QTY_INCREMENTS)
? Mage::getStoreConfigAsInt(self::XML_PATH_QTY_INCREMENTS)
: false;
}

Expand All @@ -423,7 +423,7 @@ public function getDefaultQtyIncrements()
public function getBackorders()
{
if ($this->getUseConfigBackorders()) {
return (int) Mage::getStoreConfig(self::XML_PATH_BACKORDERS);
return Mage::getStoreConfigAsInt(self::XML_PATH_BACKORDERS);
}
return $this->getData('backorders');
}
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Checkout/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,16 @@ protected function _getEmails($configPath, $storeId)
public function isMultishippingCheckoutAvailable()
{
$quote = $this->getQuote();
$isMultiShipping = (bool)(int)Mage::getStoreConfig('shipping/option/checkout_multiple');
$isMultiShipping = Mage::getStoreConfigFlag('shipping/option/checkout_multiple');
if ((!$quote) || !$quote->hasItems()) {
return $isMultiShipping;
}
$maximunQty = (int)Mage::getStoreConfig('shipping/option/checkout_multiple_maximum_qty');
$maximumQty = Mage::getStoreConfigAsInt('shipping/option/checkout_multiple_maximum_qty');
return $isMultiShipping
&& !$quote->hasItemsWithDecimalQty()
&& $quote->validateMinimumAmount(true)
&& (($quote->getItemsSummaryQty() - $quote->getItemVirtualQty()) > 0)
&& ($quote->getItemsSummaryQty() <= $maximunQty)
&& ($quote->getItemsSummaryQty() <= $maximumQty)
&& !$quote->hasNominalItems()
;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Checkout/Model/Type/Multishipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function setShippingItemsInformation($info)
}
}

$maxQty = (int)Mage::getStoreConfig('shipping/option/checkout_multiple_maximum_qty');
$maxQty = Mage::getStoreConfigAsInt('shipping/option/checkout_multiple_maximum_qty');
if ($allQty > $maxQty) {
Mage::throwException(Mage::helper('checkout')->__('Maximum qty allowed for Shipping to multiple addresses is %s', $maxQty));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Mage_ConfigurableSwatches_Helper_Swatchdimensions extends Mage_Core_Helper
*/
public function getDimension($area, $dimension, $outer = false)
{
$dimension = (int) Mage::getStoreConfig(
$dimension = Mage::getStoreConfigAsInt(
Mage_ConfigurableSwatches_Helper_Data::CONFIG_PATH_BASE . '/' . $area . '/' . $dimension
);
if ($outer) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Block/Html/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function _toHtml()
$this->assign('pm', Mage::helper('core')->jsonEncode(Zend_Locale_Data::getContent($localeCode, 'pm')));

// get first day of week and weekend days
$this->assign('firstDay', (int)Mage::getStoreConfig('general/locale/firstday'));
$this->assign('firstDay', Mage::getStoreConfigAsInt('general/locale/firstday'));
$this->assign('weekendDays', Mage::helper('core')->jsonEncode((string)Mage::getStoreConfig('general/locale/weekend')));

// define default format and tooltip format
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Controller/Varien/Front.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ protected function _checkBaseUrl($request)
return;
}

$redirectCode = (int)Mage::getStoreConfig('web/url/redirect_to_base');
$redirectCode = Mage::getStoreConfigAsInt('web/url/redirect_to_base');
if (!$redirectCode) {
return;
} elseif ($redirectCode != 301) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Resource/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getLifeTime()
if (is_null($this->_lifeTime)) {
$configNode = Mage::app()->getStore()->isAdmin() ?
'admin/security/session_cookie_lifetime' : 'web/cookie/cookie_lifetime';
$this->_lifeTime = (int) Mage::getStoreConfig($configNode);
$this->_lifeTime = Mage::getStoreConfigAsInt($configNode);

if ($this->_lifeTime < 60) {
$this->_lifeTime = ini_get('session.gc_maxlifetime');
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function start($sessionName = null)
$cookie = $this->getCookie();
if (Mage::app()->getStore()->isAdmin()) {
$sessionMaxLifetime = Mage_Core_Model_Resource_Session::SEESION_MAX_COOKIE_LIFETIME;
$adminSessionLifetime = (int)Mage::getStoreConfig('admin/security/session_cookie_lifetime');
$adminSessionLifetime = Mage::getStoreConfigAsInt('admin/security/session_cookie_lifetime');
if ($adminSessionLifetime > $sessionMaxLifetime) {
$adminSessionLifetime = $sessionMaxLifetime;
}
Expand Down
10 changes: 5 additions & 5 deletions app/code/core/Mage/Customer/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function getIsRequireAdminUserToChangeUserPassword()
*/
public function getDefaultCustomerGroupId($store = null)
{
return (int)Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $store);
return Mage::getStoreConfigAsInt(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $store);
}

/**
Expand All @@ -482,7 +482,7 @@ public function getDefaultCustomerGroupId($store = null)
*/
public function getCustomerForgotPasswordFlowSecure()
{
return (int)Mage::getStoreConfig(self::XML_PATH_CUSTOMER_FORGOT_PASSWORD_FLOW_SECURE);
return Mage::getStoreConfigAsInt(self::XML_PATH_CUSTOMER_FORGOT_PASSWORD_FLOW_SECURE);
}

/**
Expand All @@ -492,7 +492,7 @@ public function getCustomerForgotPasswordFlowSecure()
*/
public function getCustomerForgotPasswordEmailTimes()
{
return (int)Mage::getStoreConfig(self::XML_PATH_CUSTOMER_FORGOT_PASSWORD_EMAIL_TIMES);
return Mage::getStoreConfigAsInt(self::XML_PATH_CUSTOMER_FORGOT_PASSWORD_EMAIL_TIMES);
}

/**
Expand All @@ -502,7 +502,7 @@ public function getCustomerForgotPasswordEmailTimes()
*/
public function getCustomerForgotPasswordIpTimes()
{
return (int)Mage::getStoreConfig(self::XML_PATH_CUSTOMER_FORGOT_PASSWORD_IP_TIMES);
return Mage::getStoreConfigAsInt(self::XML_PATH_CUSTOMER_FORGOT_PASSWORD_IP_TIMES);
}

/**
Expand All @@ -527,7 +527,7 @@ public function getCustomerGroupIdBasedOnVatNumber($customerCountryCode, $vatVal
];

if (isset($vatClassToGroupXmlPathMap[$vatClass])) {
$groupId = (int)Mage::getStoreConfig($vatClassToGroupXmlPathMap[$vatClass], $store);
$groupId = Mage::getStoreConfigAsInt($vatClassToGroupXmlPathMap[$vatClass], $store);
}

return $groupId;
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ public function cleanPasswordsValidationData()
*/
public function getMinPasswordLength()
{
$minLength = (int)Mage::getStoreConfig(self::XML_PATH_MIN_PASSWORD_LENGTH);
$minLength = Mage::getStoreConfigAsInt(self::XML_PATH_MIN_PASSWORD_LENGTH);
$absoluteMinLength = Mage_Core_Model_App::ABSOLUTE_MIN_PASSWORD_LENGTH;
return ($minLength < $absoluteMinLength) ? $absoluteMinLength : $minLength;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected function _convertBatch(array $data, $currencyFrom, array $currenciesTo
$this->_url
);

$timeLimitCalculated = 2 * (int) Mage::getStoreConfig(self::XML_PATH_CURRENCY_CONVERTER_TIMEOUT)
$timeLimitCalculated = 2 * Mage::getStoreConfigAsInt(self::XML_PATH_CURRENCY_CONVERTER_TIMEOUT)
+ (int) ini_get('max_execution_time');

@set_time_limit($timeLimitCalculated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected function _convertBatch(array $data, $currencyFrom, array $currenciesTo
$this->_url
);

$timeLimitCalculated = 2 * (int) Mage::getStoreConfig(self::XML_PATH_FIXERIO_TIMEOUT)
$timeLimitCalculated = 2 * Mage::getStoreConfigAsInt(self::XML_PATH_FIXERIO_TIMEOUT)
+ (int) ini_get('max_execution_time');

@set_time_limit($timeLimitCalculated);
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/ImportExport/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getLocalValidPaths()
*/
public function getBunchSize()
{
return (int)Mage::getStoreConfig(self::XML_PATH_BUNCH_SIZE);
return Mage::getStoreConfigAsInt(self::XML_PATH_BUNCH_SIZE);
}

/**
Expand All @@ -67,6 +67,6 @@ public function getBunchSize()
*/
public function getImportConfigurablePageSize()
{
return (int)Mage::getStoreConfig(self::XML_PATH_IMPORT_CONFIGURABLE_PAGE_SIZE);
return Mage::getStoreConfigAsInt(self::XML_PATH_IMPORT_CONFIGURABLE_PAGE_SIZE);
}
}
2 changes: 1 addition & 1 deletion app/code/core/Mage/Log/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Mage_Log_Helper_Data extends Mage_Core_Helper_Abstract
*/
public function __construct(array $data = [])
{
$this->_logLevel = $data['log_level'] ?? (int) Mage::getStoreConfig(self::XML_PATH_LOG_ENABLED);
$this->_logLevel = $data['log_level'] ?? Mage::getStoreConfigAsInt(self::XML_PATH_LOG_ENABLED);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Log/Model/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function _construct()
*/
public function getLogCleanTime()
{
return (int)Mage::getStoreConfig(self::XML_LOG_CLEAN_DAYS) * 60 * 60 * 24;
return Mage::getStoreConfigAsInt(self::XML_LOG_CLEAN_DAYS) * 60 * 60 * 24;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Log/Model/Visitor/Online.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getUpdateFrequency()
*/
public function getOnlineInterval()
{
$value = (int) Mage::getStoreConfig(self::XML_PATH_ONLINE_INTERVAL);
$value = Mage::getStoreConfigAsInt(self::XML_PATH_ONLINE_INTERVAL);
if (!$value) {
$value = Mage_Log_Model_Visitor::DEFAULT_ONLINE_MINUTES_INTERVAL;
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Oauth/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function getProtocolEndpointUrl($type)
public function isCleanupProbability()
{
// Safe get cleanup probability value from system configuration
$configValue = (int) Mage::getStoreConfig(self::XML_PATH_CLEANUP_PROBABILITY);
$configValue = Mage::getStoreConfigAsInt(self::XML_PATH_CLEANUP_PROBABILITY);
return $configValue > 0 ? mt_rand(1, $configValue) == 1 : false;
}

Expand All @@ -208,7 +208,7 @@ public function isCleanupProbability()
*/
public function getCleanupExpirationPeriod()
{
$minutes = (int) Mage::getStoreConfig(self::XML_PATH_CLEANUP_EXPIRATION_PERIOD);
$minutes = Mage::getStoreConfigAsInt(self::XML_PATH_CLEANUP_EXPIRATION_PERIOD);
return $minutes > 0 ? $minutes : self::CLEANUP_EXPIRATION_PERIOD_DEFAULT;
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Persistent/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function isShoppingCartPersist($store = null)
*/
public function getLifeTime($store = null)
{
$lifeTime = (int) Mage::getStoreConfig(self::XML_PATH_LIFE_TIME, $store);
$lifeTime = Mage::getStoreConfigAsInt(self::XML_PATH_LIFE_TIME, $store);
return ($lifeTime < 0) ? 0 : $lifeTime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function useManageStockFilter($storeId = null)
$this->joinInventoryItem();
$manageStockExpr = $this->getConnection()->getCheckSql(
$this->_getInventoryItemField('use_config_manage_stock') . ' = 1',
(int) Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId),
Mage::getStoreConfigAsInt(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId),
$this->_getInventoryItemField('manage_stock')
);
$this->getSelect()->where($manageStockExpr . ' = ?', 1);
Expand All @@ -222,7 +222,7 @@ public function useNotifyStockQtyFilter($storeId = null)
$this->joinInventoryItem(['qty']);
$notifyStockExpr = $this->getConnection()->getCheckSql(
$this->_getInventoryItemField('use_config_notify_stock_qty') . ' = 1',
(int)Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY, $storeId),
Mage::getStoreConfigAsInt(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY, $storeId),
$this->_getInventoryItemField('notify_stock_qty')
);
$this->getSelect()->where('qty < ?', $notifyStockExpr);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Rss/Block/Catalog/NotifyStock.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function _toHtml()
];
$rssObj->_addHeader($data);

$globalNotifyStockQty = (float) Mage::getStoreConfig(
$globalNotifyStockQty = Mage::getStoreConfigAsFloat(
Mage_CatalogInventory_Model_Stock_Item::XML_PATH_NOTIFY_STOCK_QTY
);
Mage::helper('rss')->disableFlat();
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/SalesRule/Helper/Coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getFormatsList()
*/
public function getDefaultLength()
{
return (int)Mage::getStoreConfig(self::XML_PATH_SALES_RULE_COUPON_LENGTH);
return Mage::getStoreConfigAsInt(self::XML_PATH_SALES_RULE_COUPON_LENGTH);
}

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ public function getDefaultSuffix()
*/
public function getDefaultDashInterval()
{
return (int)Mage::getStoreConfig(self::XML_PATH_SALES_RULE_COUPON_DASH_INTERVAL);
return Mage::getStoreConfigAsInt(self::XML_PATH_SALES_RULE_COUPON_DASH_INTERVAL);
}

/**
Expand Down
Loading

0 comments on commit 88afdb1

Please sign in to comment.