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
Don't try to display a custom logo or favicon if they don't exist #10000
Conversation
…if they don't exist Prevents 404 errors.
Gratz! Issue/pr nb #10000 :) |
@@ -163,6 +163,16 @@ protected static function rewritePath($path) | |||
return SettingsPiwik::rewriteMiscUserPathWithInstanceId($path); | |||
} | |||
|
|||
public static function hasUserLogo() | |||
{ | |||
return file_exists(Filesystem::getPathToPiwikRoot() . '/' . CustomLogo::getPathUserLogo()); |
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.
BTW: Here you could use PIWIK_INCLUDE_PATH . CustomLogo::getPathUserLogo()
and same below
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.
I copied the code from the existing hasSvgLogo and getPathToLogo methods for consistency :). Is there any difference between the static method and the constant? Should I still use the constant?
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.
good point, I didn't notice that. Consistency is always good. We usually always use PIWIK_INCLUDE_PATH
but not sure why Filesystem::getPathToPiwikRoot()
was used there is there's no difference and the constant should be better. I'm ok with Filesystem::getPathToPiwikRoot()
in this case. To remove the duplicated code though maybe there could be a method like
private function getRootPath()
{
return Filesystem::getPathToPiwikRoot() . '/';
}
// or
private function getAbsolutePath($reference)
{
return Filesystem::getPathToPiwikRoot() . '/' . $reference;
}
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.
As you prefer, we can also replace all calls to this method in this file by the constant.
If we add a new method getAbsolutePath, I think it should be in the Filesystem class, isn't it ?
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.
Somehow I would prefer not to have it in Filesystem but would be also ok there. Having a look at this again in the code there is often file_exists($pathToPiwikRoot . '/' . $customLogo)
etc, finding several file_exists
. The code seems quite confusing in there in general and needs to be refactored at some point. Maybe there could me instead a method
private function logoExists($reference)
{
return file_exists(Filesystem::getPathToPiwikRoot() . '/' . $reference);
}
Of course this could be as well in Filesystem but might be as well fine in CustomLogo for now
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.
Done in 637b839 ;)
I tested it and works great 👍 Just made two really minor comments but after those changes we can merge. Thank you for that and for getting this done so quick 👍 |
[ci skip]
Awesome 👍 👍 Thanks for this. Merging now |
A possible fix for #9966