Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved calculating version hash for the js-translation.json file. #10378

Merged
merged 9 commits into from
Aug 18, 2017
8 changes: 8 additions & 0 deletions app/code/Magento/Translation/Block/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@ public function getTranslationFilePath()
{
return $this->fileManager->getTranslationFilePath();
}

/**
* @return string
*/
public function getTranslationFileVersion()
{
return $this->fileManager->getTranslationFileVersion();
}
}
15 changes: 15 additions & 0 deletions app/code/Magento/Translation/Model/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,19 @@ public function updateTranslationFileContent($content)
}
$this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content);
}

/**
* @return string
*/
public function getTranslationFileVersion()
{
$translationFile = $this->getTranslationFileFullPath();
$translationFileHash = '';

if ($this->driverFile->isExists($translationFile)) {
$translationFileHash = sha1_file($translationFile);
}

return sha1($translationFileHash . $this->getTranslationFilePath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$.initNamespaceStorage('mage-translation-file-version');
versionObj = $.localStorage.get('mage-translation-file-version');

<?php $version = sha1($block->getTranslationFileTimestamp() . $block->getTranslationFilePath()); ?>
<?php $version = $block->getTranslationFileVersion(); ?>

if (versionObj.version !== '<?= /* @noEscape */ $version ?>') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoudn't we escape version there? Previously it was always sha1, but from now it uses raw value from public method, that could be overridden by plugin.
@ishakhsuvarov i think it should be escaped. what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds completely reasonable to me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishakhsuvarov pull request prepared #10904

dependencies.push(
Expand Down