-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Changes from 1 commit
a1dab12
b3a1c7e
507cd42
def3cff
75990d4
cc44db7
93ca363
5b1b749
cbca085
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ public function getTranslationFileTimestamp() | |
/** | ||
* @return string | ||
*/ | ||
protected function getTranslationFileFullPath() | ||
public function getTranslationFileFullPath() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change of method visibility may break potential customization or extension which inherited from this class. |
||
{ | ||
return $this->directoryList->getPath(DirectoryList::STATIC_VIEW) . | ||
\DIRECTORY_SEPARATOR . | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = sha1(sha1_file($block->getTranslationFileFullPath()) . $block->getTranslationFilePath()); ?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hashes calculation and operations on the filesystem should not be a responsibility of the presentation layer. |
||
|
||
if (versionObj.version !== '<?= /* @noEscape */ $version ?>') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds completely reasonable to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ishakhsuvarov pull request prepared #10904 |
||
dependencies.push( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change indeed breaks backwards compatibility rules, but with existing block design this case becomes quite complicated to solve properly without adding a method.
If we are going to violate the rule for the specific case – I would suggest implementing this in the "desirable state" way, so it would cover all the theoretical cases which may come up in the future.
Briefly, this could be a method with more general name, something like
getTranslationFileVersion
, which would proxy the call to the dedicated model, which calculates the value (doing so in the template is not a best practice anyway). This way it becomes a more usable "extension point" for third-party developers to possibly customize the behavior and improves ability to maintain this code for the core team.