Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - magento#15016: chore: checkout last 5 commits (by @DanielRuf)
 - magento#15017: chore: use random_int() in some places (by @DanielRuf)
 - magento#15012: fix: set message-success in setup if we already have the latest version (by @DanielRuf)
 - magento#15002: small optimization in if-condition (by @likemusic)
  • Loading branch information
VladimirZaets authored May 8, 2018
2 parents 2851994 + 4cb581a commit aca8c0b
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ language: php
php:
- 7.0
- 7.1
git:
depth: 5
env:
global:
- COMPOSER_BIN_DIR=~/bin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function render(\Magento\Framework\DataObject $row)
*/
protected function _getCheckboxHtml($value, $checked)
{
$id = 'id_' . rand(0, 999);
$id = 'id_' . random_int(0, 999);
$html = '<label class="data-grid-checkbox-cell-inner" for="'. $id .'">';
$html .= '<input type="checkbox" name="' . $this->getColumn()->getName() . '" ';
$html .= 'id="' . $id . '" data-role="select-row"';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,25 @@ class AttributeFilter
public function prepareProductAttributes(Product $product, array $productData, array $useDefaults)
{
foreach ($productData as $attribute => $value) {
$considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1";
if ($value === '' && $considerUseDefaultsAttribute) {
/** @var $product Product */
if ((bool)$product->getData($attribute) === (bool)$value) {
unset($productData[$attribute]);
}
if ($this->isAttributeShouldNotBeUpdated($product, $useDefaults, $attribute, $value)) {
unset($productData[$attribute]);
}
}

return $productData;
}

/**
* @param Product $product
* @param $useDefaults
* @param $attribute
* @param $value
* @return bool
*/
private function isAttributeShouldNotBeUpdated(Product $product, $useDefaults, $attribute, $value)
{
$considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1";

return ($value === '' && $considerUseDefaultsAttribute && !$product->getData($attribute));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ protected function getTemporaryTreeIndexTableName()
if (empty($this->tempTreeIndexTableName)) {
$this->tempTreeIndexTableName = $this->connection->getTableName('temp_catalog_category_tree_index')
. '_'
. substr(md5(time() . rand(0, 999999999)), 0, 8);
. substr(md5(time() . random_int(0, 999999999)), 0, 8);
}

return $this->tempTreeIndexTableName;
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/SalesRule/Model/Coupon/Codegenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function generateCode()
$length = $this->getActualLength();
$code = '';
for ($i = 0, $indexMax = strlen($alphabet) - 1; $i < $length; ++$i) {
$code .= substr($alphabet, mt_rand(0, $indexMax), 1);
$code .= substr($alphabet, random_int(0, $indexMax), 1);
}

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

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

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/SalesRule/Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public function acquireCoupon($saveNewlyCreated = true, $saveAttemptCount = 10)
$coupon->setCode(
$couponCode . self::getCouponCodeGenerator()->getDelimiter() . sprintf(
'%04u',
rand(0, 9999)
random_int(0, 9999)
)
);
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Encryption/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct(
$abc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$initVector = '';
for ($i = 0; $i < $initVectorSize; $i++) {
$initVector .= $abc[rand(0, strlen($abc) - 1)];
$initVector .= $abc[random_int(0, strlen($abc) - 1)];
}
} elseif (false === $initVector) {
/* Set vector to zero bytes to not use it */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class BackendFrontnameGenerator
public static function generate()
{
return self::ADMIN_AREA_PATH_PREFIX
. substr(base_convert(rand(0, PHP_INT_MAX), 10, 36), 0, self::ADMIN_AREA_PATH_RANDOM_PART_LENGTH);
. substr(base_convert(random_int(0, PHP_INT_MAX), 10, 36), 0, self::ADMIN_AREA_PATH_RANDOM_PART_LENGTH);
}
}
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Webapi/ErrorProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function apiShutdownFunction()
protected function _saveFatalErrorReport($reportData)
{
$this->directoryWrite->create('report/api');
$reportId = abs(intval(microtime(true) * rand(100, 1000)));
$reportId = abs(intval(microtime(true) * random_int(100, 1000)));
$this->directoryWrite->writeFile('report/api/' . $reportId, $this->serializer->serialize($reportData));
return $reportId;
}
Expand Down
2 changes: 1 addition & 1 deletion pub/errors/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ protected function _setReportData($reportData)
public function saveReport($reportData)
{
$this->reportData = $reportData;
$this->reportId = abs(intval(microtime(true) * rand(100, 1000)));
$this->reportId = abs(intval(microtime(true) * random_int(100, 1000)));
$this->_reportFile = $this->_reportDir . '/' . $this->reportId;
$this->_setReportData($reportData);

Expand Down
2 changes: 2 additions & 0 deletions setup/pub/magento/setup/select-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ angular.module('select-version', ['ngStorage'])
$scope.upgradeReadyForNext = false;
$scope.upgradeProcessed = false;
$scope.upgradeProcessError = false;
$scope.upgradeAlreadyLatestVersion = false;
$scope.upgradeProcessErrorMessage = '';
$scope.componentsReadyForNext = true;
$scope.componentsProcessed = false;
Expand All @@ -39,6 +40,7 @@ angular.module('select-version', ['ngStorage'])

if ($scope.upgradeProcessError) {
$scope.upgradeProcessErrorMessage = "You're already using the latest version, there's nothing for us to do.";
$scope.upgradeAlreadyLatestVersion = true;
} else {
$scope.selectedOption = [];
$scope.versions = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AddressDataGenerator
public function generateAddress()
{
return [
'postcode' => mt_rand(10000, 99999)
'postcode' => random_int(10000, 99999)
];
}
}
4 changes: 2 additions & 2 deletions setup/src/Magento/Setup/Model/DataGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ protected function readData()
*/
public function generate($minAmountOfWords, $maxAmountOfWords, $key = null)
{
$numberOfWords = mt_rand($minAmountOfWords, $maxAmountOfWords);
$numberOfWords = random_int($minAmountOfWords, $maxAmountOfWords);
$result = '';

if ($key === null || !array_key_exists($key, $this->generatedValues)) {
for ($i = 0; $i < $numberOfWords; $i++) {
$result .= ' ' . $this->dictionaryData[mt_rand(0, count($this->dictionaryData) - 1)];
$result .= ' ' . $this->dictionaryData[random_int(0, count($this->dictionaryData) - 1)];
}
$result = trim($result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function generate()
*/
private function generateRawDescription()
{
$paragraphsCount = mt_rand(
$paragraphsCount = random_int(
$this->descriptionConfig['paragraphs']['count-min'],
$this->descriptionConfig['paragraphs']['count-max']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
*/
public function generate()
{
$sentencesCount = mt_rand(
$sentencesCount = random_int(
$this->paragraphConfig['sentences']['count-min'],
$this->paragraphConfig['sentences']['count-max']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
*/
public function generate()
{
$sentenceWordsCount = mt_rand(
$sentenceWordsCount = random_int(
$this->sentenceConfig['words']['count-min'],
$this->sentenceConfig['words']['count-max']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function apply($text)

return $this->wordWrapper->wrapWords(
$text,
$this->randomWordSelector->getRandomWords($rawText, mt_rand(5, 8)),
$this->randomWordSelector->getRandomWords($rawText, random_int(5, 8)),
'<b>%s</b>'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getRandomWords($source, $count)
$randWords = [];
$wordsSize = count($words);
while ($count) {
$randWords[] = $words[mt_rand(0, $wordsSize - 1)];
$randWords[] = $words[random_int(0, $wordsSize - 1)];
$count--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function apply($text)

return $this->wordWrapper->wrapWords(
$text,
$this->randomWordSelector->getRandomWords($rawText, mt_rand(5, 8)),
$this->randomWordSelector->getRandomWords($rawText, random_int(5, 8)),
'<i>%s</i>'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function apply($text)

return $this->wordWrapper->wrapWords(
$text,
$this->randomWordSelector->getRandomWords($rawText, mt_rand(5, 8)),
$this->randomWordSelector->getRandomWords($rawText, random_int(5, 8)),
'<span>%s</span>'
);
}
Expand Down
2 changes: 1 addition & 1 deletion setup/src/Magento/Setup/Model/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getRandWord()
$this->readDictionary();
}

$randIndex = mt_rand(0, count($this->dictionary) - 1);
$randIndex = random_int(0, count($this->dictionary) - 1);
return trim($this->dictionary[$randIndex]);
}

Expand Down
5 changes: 4 additions & 1 deletion setup/view/magento/setup/select-version.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
</span>
<span class="message-text">Checking for a new version...</span>
</div>
<div class="message message-error" ng-show="upgradeProcessError">
<div
class="message"
ng-class="upgradeAlreadyLatestVersion ? 'message-success' : 'message-error'"
ng-show="upgradeProcessError">
<span class="message-text" ng-bind-html="upgradeProcessErrorMessage"></span>
</div>
<div class="message" ng-show="upgradeProcessed && !upgradeProcessError && currentVersion">
Expand Down

0 comments on commit aca8c0b

Please sign in to comment.