Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2586,12 +2586,6 @@ parameters:
count: 1
path: app/code/core/Mage/Core/Model/Design/Fallback.php

-
rawMessage: 'Property Mage_Core_Model_Design_Package::$_store (int|Mage_Core_Model_Store|string) on left side of ?? is not nullable.'
identifier: nullCoalesce.property
count: 1
path: app/code/core/Mage/Core/Model/Design/Package.php

-
rawMessage: 'Parameter #1 $policyCode of method Mage_Core_Model_Domainpolicy::_getDomainPolicyByCode() expects string, int given.'
identifier: argument.type
Expand Down
5 changes: 0 additions & 5 deletions app/code/core/Mage/Adminhtml/Block/Cache/Additional.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ public function getCleanSwatchesUrl()
{
return $this->getUrl('*/*/cleanSwatches');
}

public function getCleanMediaUrl()
{
return $this->getUrl('*/*/cleanMedia');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ protected function _beforeSave()
return $this;
}

/**
* Clean compiled JS/CSS when updating url configuration settings
*/
protected function _afterSave()
{
if ($this->isValueChanged()) {
Mage::getModel('core/design_package')->cleanMergedJsCss();
}

return $this;
}

/**
* @inheritDoc
*/
Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions app/code/core/Mage/Adminhtml/controllers/CacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,29 +146,6 @@ public function massRefreshAction()
$this->_redirect('*/*');
}

/**
* Clean JS/css files cache
*/
public function cleanMediaAction()
{
try {
Mage::getModel('core/design_package')->cleanMergedJsCss();
Mage::dispatchEvent('clean_media_cache_after');
$this->_getSession()->addSuccess(
Mage::helper('adminhtml')->__('The JavaScript/CSS cache has been cleaned.'),
);
} catch (Mage_Core_Exception $e) {
$this->_getSession()->addError($e->getMessage());
} catch (Exception $e) {
$this->_getSession()->addException(
$e,
Mage::helper('adminhtml')->__('An error occurred while clearing the JavaScript/CSS cache.'),
);
}

$this->_redirect('*/*');
}

/**
* Clean catalog files cache
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@ public function saveAction()

Mage::app()->saveUseCache($enable);

// clean javascript/css cache
if ($this->getRequest()->getPost('jscss_action')) {
if (Mage::getDesign()->cleanMergedJsCss()) {
$this->_getSession()->addSuccess(
Mage::helper('adminhtml')->__('The JavaScript/CSS cache has been cleared.'),
);
} else {
$this->_getSession()->addError(Mage::helper('adminhtml')->__('Failed to clear the JavaScript/CSS cache.'));
}
}

/**
* Run catalog actions
*/
Expand Down
160 changes: 27 additions & 133 deletions app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getEncryptor()
* @param float $value
* @param bool $format
* @param bool $includeContainer
* @return mixed
* @return float|string
*/
public static function currency($value, $format = true, $includeContainer = true)
{
Expand All @@ -111,7 +111,7 @@ public static function currency($value, $format = true, $includeContainer = true
* @param int|Mage_Core_Model_Store $store
* @param bool $format
* @param bool $includeContainer
* @return mixed
* @return float|string
*/
public static function currencyByStore($value, $store = null, $format = true, $includeContainer = true)
{
Expand All @@ -121,8 +121,8 @@ public static function currencyByStore($value, $store = null, $format = true, $i
}

$value = $store->convertPrice($value, $format, $includeContainer);
} catch (Exception $e) {
$value = $e->getMessage();
} catch (Exception $exception) {
$value = $exception->getMessage();
}

return $value;
Expand All @@ -146,6 +146,7 @@ public function formatCurrency($value, $includeContainer = true)
* @param float $price
* @param bool $includeContainer
* @return string
* @throws Mage_Core_Model_Store_Exception
*/
public function formatPrice($price, $includeContainer = true)
{
Expand Down Expand Up @@ -275,14 +276,15 @@ public function validateKey($key)
* @param int $len
* @param string|null $chars
* @return string
* @throws Exception
*/
public function getRandomString($len, $chars = null)
{
if (is_null($chars)) {
$chars = self::CHARS_LOWERS . self::CHARS_UPPERS . self::CHARS_DIGITS;
}

for ($i = 0, $str = '', $lc = strlen($chars) - 1; $i < $len; $i++) {
for ($index = 0, $str = '', $lc = strlen($chars) - 1; $index < $len; $index++) {
$str .= $chars[random_int(0, $lc)];
}

Expand Down Expand Up @@ -347,6 +349,7 @@ public function getVersionHash(Mage_Core_Model_Encryption $encryptionModel)
*
* @param bool|int|Mage_Core_Model_Store|null|string $store
* @return int
* @throws Mage_Core_Model_Store_Exception
*/
public function getStoreId($store = null)
{
Expand All @@ -356,7 +359,7 @@ public function getStoreId($store = null)
/**
* @param string $string
* @param bool $german
* @return false|string
* @return string
*
* @SuppressWarnings("PHPMD.ErrorControlOperator")
*/
Expand Down Expand Up @@ -397,21 +400,19 @@ public function removeAccents($string, $german = false)
}

$replacements[$german] = [];
foreach ($subst as $k => $v) {
$replacements[$german][$k < 256 ? chr($k) : '&#' . $k . ';'] = $v;
foreach ($subst as $key => $value) {
$replacements[$german][$key < 256 ? chr($key) : '&#' . $key . ';'] = $value;
}
}

// convert string from default database format (UTF-8)
// to encoding which replacement arrays made with (ISO-8859-1)
if ($s = @iconv('UTF-8', 'ISO-8859-1', $string)) {
$string = $s;
if ($encoded = @iconv('UTF-8', 'ISO-8859-1', $string)) {
$string = $encoded;
}

// Replace
$string = strtr($string, $replacements[$german]);

return $string;
return strtr($string, $replacements[$german]);
}

/**
Expand Down Expand Up @@ -567,19 +568,19 @@ public function decorateArray($array, $prefix = 'decorated_', $forceSetAll = fal
$keyIsLast = "{$prefix}is_last";

$count = count($array); // this will force Iterator to load
$i = 0;
$index = 0;
$isEven = false;
foreach ($array as $key => $element) {
if (is_object($element)) {
$this->_decorateArrayObject($element, $keyIsFirst, ($i === 0), $forceSetAll || ($i === 0));
$this->_decorateArrayObject($element, $keyIsFirst, ($index === 0), $forceSetAll || ($index === 0));
$this->_decorateArrayObject($element, $keyIsOdd, !$isEven, $forceSetAll || !$isEven);
$this->_decorateArrayObject($element, $keyIsEven, $isEven, $forceSetAll || $isEven);
$isEven = !$isEven;
$i++;
$this->_decorateArrayObject($element, $keyIsLast, ($i === $count), $forceSetAll || ($i === $count));
$index++;
$this->_decorateArrayObject($element, $keyIsLast, ($index === $count), $forceSetAll || ($index === $count));
} elseif (is_array($element)) {
if ($forceSetAll || ($i === 0)) {
$array[$key][$keyIsFirst] = ($i === 0);
if ($forceSetAll || ($index === 0)) {
$array[$key][$keyIsFirst] = ($index === 0);
}

if ($forceSetAll || !$isEven) {
Expand All @@ -591,9 +592,9 @@ public function decorateArray($array, $prefix = 'decorated_', $forceSetAll = fal
}

$isEven = !$isEven;
$i++;
if ($forceSetAll || ($i === $count)) {
$array[$key][$keyIsLast] = ($i === $count);
$index++;
if ($forceSetAll || ($index === $count)) {
$array[$key][$keyIsLast] = ($index === $count);
}
}
}
Expand Down Expand Up @@ -695,9 +696,9 @@ public function xmlToAssoc(SimpleXMLElement $xml)
$array = [];
foreach ($xml as $key => $value) {
if (isset($value->$key)) {
$i = 0;
$index = 0;
foreach ($value->$key as $v) {
$array[$key][$i++] = (string) $v;
$array[$key][$index++] = (string) $v;
}
} else {
// try to transform it into string value, trimming spaces between elements
Expand Down Expand Up @@ -778,113 +779,6 @@ public function uniqHash($prefix = '')
return $prefix . md5(uniqid(microtime() . mt_rand(), true));
}

/**
* Merge specified files into one
*
* By default will not merge, if there is already merged file exists and it
* was modified after its components
* If target file is specified, will attempt to write merged contents into it,
* otherwise will return merged content
* May apply callback to each file contents. Callback gets parameters:
* (<existing system filename>, <file contents>)
* May filter files by specified extension(s)
* Returns false on error
*
* @param string|false $targetFile - file path to be written
* @param bool $mustMerge
* @param callable $beforeMergeCallback
* @param array|string $extensionsFilter
* @return bool|string
* @SuppressWarnings("PHPMD.ErrorControlOperator")
*/
public function mergeFiles(
array $srcFiles,
$targetFile = false,
$mustMerge = false,
$beforeMergeCallback = null,
$extensionsFilter = []
) {
try {
// check whether merger is required
$shouldMerge = $mustMerge || !$targetFile;
if (!$shouldMerge) {
if (!file_exists($targetFile)) {
$shouldMerge = true;
} else {
$targetMtime = filemtime($targetFile);
foreach ($srcFiles as $file) {
if (!file_exists($file)) {
// no translation intentionally
Mage::logException(new Exception(sprintf('File %s not found.', $file)));
} elseif (@filemtime($file) > $targetMtime) {
$shouldMerge = true;
break;
}
}
}
}

// merge contents into the file
if ($shouldMerge) {
if ($targetFile && !is_writable(dirname($targetFile))) {
// no translation intentionally
throw new Exception(sprintf('Path %s is not writeable.', dirname($targetFile)));
}

// filter by extensions
if ($extensionsFilter) {
if (!is_array($extensionsFilter)) {
$extensionsFilter = [$extensionsFilter];
}

foreach ($srcFiles as $key => $file) {
$fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (!in_array($fileExt, $extensionsFilter)) {
unset($srcFiles[$key]);
}
}
}

if (empty($srcFiles)) {
// no translation intentionally
throw new Exception('No files to compile.');
}

$data = '';
foreach ($srcFiles as $file) {
if (!file_exists($file)) {
continue;
}

$contents = file_get_contents($file) . "\n";
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
if ($beforeMergeCallback && is_callable($beforeMergeCallback)) {
$contents = call_user_func($beforeMergeCallback, $file, $contents);
}

$data .= $contents;
}

if (!$data) {
// no translation intentionally
throw new Exception(sprintf("No content found in files:\n%s", implode("\n", $srcFiles)));
}

if ($targetFile) {
file_put_contents($targetFile, $data, LOCK_EX);
} else {
return $data; // no need to write to file, just return data
}
}

return true; // no need in merger or merged into file successfully
} catch (Exception $e) {
Mage::logException($e);
}

return false;
}

/**
* Return default country code
*
Expand Down Expand Up @@ -1015,7 +909,7 @@ public function getEscapedCSVData(array $data)
$value = (string) $value;

$firstLetter = substr($value, 0, 1);
if ($firstLetter && in_array($firstLetter, ['=', '+', '-'])) {
if (in_array($firstLetter, ['=', '+', '-'])) {
$data[$key] = ' ' . $value;
}
}
Expand All @@ -1036,7 +930,7 @@ public function unEscapeCSVData($data)
foreach ($data as $key => $value) {
$value = (string) $value;

if (preg_match("/^ [=\-+]/", $value)) {
if (preg_match('/^ [=\-+]/', $value)) {
$data[$key] = ltrim($value);
}
}
Expand Down
Loading
Loading