Skip to content

Commit aca8c0b

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #15016: chore: checkout last 5 commits (by @DanielRuf) - #15017: chore: use random_int() in some places (by @DanielRuf) - #15012: fix: set message-success in setup if we already have the latest version (by @DanielRuf) - #15002: small optimization in if-condition (by @likemusic)
2 parents 2851994 + 4cb581a commit aca8c0b

File tree

22 files changed

+45
-27
lines changed

22 files changed

+45
-27
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ language: php
1515
php:
1616
- 7.0
1717
- 7.1
18+
git:
19+
depth: 5
1820
env:
1921
global:
2022
- COMPOSER_BIN_DIR=~/bin

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Massaction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function render(\Magento\Framework\DataObject $row)
6565
*/
6666
protected function _getCheckboxHtml($value, $checked)
6767
{
68-
$id = 'id_' . rand(0, 999);
68+
$id = 'id_' . random_int(0, 999);
6969
$html = '<label class="data-grid-checkbox-cell-inner" for="'. $id .'">';
7070
$html .= '<input type="checkbox" name="' . $this->getColumn()->getName() . '" ';
7171
$html .= 'id="' . $id . '" data-role="select-row"';

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilter.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,25 @@ class AttributeFilter
2828
public function prepareProductAttributes(Product $product, array $productData, array $useDefaults)
2929
{
3030
foreach ($productData as $attribute => $value) {
31-
$considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1";
32-
if ($value === '' && $considerUseDefaultsAttribute) {
33-
/** @var $product Product */
34-
if ((bool)$product->getData($attribute) === (bool)$value) {
35-
unset($productData[$attribute]);
36-
}
31+
if ($this->isAttributeShouldNotBeUpdated($product, $useDefaults, $attribute, $value)) {
32+
unset($productData[$attribute]);
3733
}
3834
}
35+
3936
return $productData;
4037
}
38+
39+
/**
40+
* @param Product $product
41+
* @param $useDefaults
42+
* @param $attribute
43+
* @param $value
44+
* @return bool
45+
*/
46+
private function isAttributeShouldNotBeUpdated(Product $product, $useDefaults, $attribute, $value)
47+
{
48+
$considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1";
49+
50+
return ($value === '' && $considerUseDefaultsAttribute && !$product->getData($attribute));
51+
}
4152
}

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ protected function getTemporaryTreeIndexTableName()
594594
if (empty($this->tempTreeIndexTableName)) {
595595
$this->tempTreeIndexTableName = $this->connection->getTableName('temp_catalog_category_tree_index')
596596
. '_'
597-
. substr(md5(time() . rand(0, 999999999)), 0, 8);
597+
. substr(md5(time() . random_int(0, 999999999)), 0, 8);
598598
}
599599

600600
return $this->tempTreeIndexTableName;

app/code/Magento/SalesRule/Model/Coupon/Codegenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function generateCode()
3838
$length = $this->getActualLength();
3939
$code = '';
4040
for ($i = 0, $indexMax = strlen($alphabet) - 1; $i < $length; ++$i) {
41-
$code .= substr($alphabet, mt_rand(0, $indexMax), 1);
41+
$code .= substr($alphabet, random_int(0, $indexMax), 1);
4242
}
4343

4444
return $code;
@@ -54,7 +54,7 @@ protected function getActualLength()
5454
$lengthMin = $this->getLengthMin() ? $this->getLengthMin() : static::DEFAULT_LENGTH_MIN;
5555
$lengthMax = $this->getLengthMax() ? $this->getLengthMax() : static::DEFAULT_LENGTH_MAX;
5656

57-
return $this->getLength() ? $this->getLength() : mt_rand($lengthMin, $lengthMax);
57+
return $this->getLength() ? $this->getLength() : random_int($lengthMin, $lengthMax);
5858
}
5959

6060
/**

app/code/Magento/SalesRule/Model/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ public function acquireCoupon($saveNewlyCreated = true, $saveAttemptCount = 10)
521521
$coupon->setCode(
522522
$couponCode . self::getCouponCodeGenerator()->getDelimiter() . sprintf(
523523
'%04u',
524-
rand(0, 9999)
524+
random_int(0, 9999)
525525
)
526526
);
527527
continue;

lib/internal/Magento/Framework/Encryption/Crypt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(
7575
$abc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
7676
$initVector = '';
7777
for ($i = 0; $i < $initVectorSize; $i++) {
78-
$initVector .= $abc[rand(0, strlen($abc) - 1)];
78+
$initVector .= $abc[random_int(0, strlen($abc) - 1)];
7979
}
8080
} elseif (false === $initVector) {
8181
/* Set vector to zero bytes to not use it */

lib/internal/Magento/Framework/Setup/BackendFrontnameGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ class BackendFrontnameGenerator
2929
public static function generate()
3030
{
3131
return self::ADMIN_AREA_PATH_PREFIX
32-
. substr(base_convert(rand(0, PHP_INT_MAX), 10, 36), 0, self::ADMIN_AREA_PATH_RANDOM_PART_LENGTH);
32+
. substr(base_convert(random_int(0, PHP_INT_MAX), 10, 36), 0, self::ADMIN_AREA_PATH_RANDOM_PART_LENGTH);
3333
}
3434
}

lib/internal/Magento/Framework/Webapi/ErrorProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public function apiShutdownFunction()
317317
protected function _saveFatalErrorReport($reportData)
318318
{
319319
$this->directoryWrite->create('report/api');
320-
$reportId = abs(intval(microtime(true) * rand(100, 1000)));
320+
$reportId = abs(intval(microtime(true) * random_int(100, 1000)));
321321
$this->directoryWrite->writeFile('report/api/' . $reportId, $this->serializer->serialize($reportData));
322322
return $reportId;
323323
}

pub/errors/processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ protected function _setReportData($reportData)
463463
public function saveReport($reportData)
464464
{
465465
$this->reportData = $reportData;
466-
$this->reportId = abs(intval(microtime(true) * rand(100, 1000)));
466+
$this->reportId = abs(intval(microtime(true) * random_int(100, 1000)));
467467
$this->_reportFile = $this->_reportDir . '/' . $this->reportId;
468468
$this->_setReportData($reportData);
469469

0 commit comments

Comments
 (0)