matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.94k stars 2.66k forks source link

Invalidate merged Noncore JS / CSS in case of any plugin update/downgrade/uninstall #4655

Closed tsteur closed 10 years ago

tsteur commented 10 years ago

In case we are in production mode (merged assets is enabled) and there is a plugin upgrade/downgrade/uninstall we should regenerate the merged Noncore JS / CSS if needed.

julienmoumne commented 10 years ago

This should already work, see first line of [https://github.com/piwik/piwik/blob/master/core/Filesystem.php#L24] :

/**
* Called on Core install, update, plugin enable/disable
* Will clear all cache that could be affected by the change in configuration being made
*/
    public static function deleteAllCacheOnUpdate($pluginName = false)
    {
        AssetManager::getInstance()->removeMergedAssets($pluginName);
        View::clearCompiledTemplates();
        Cache::deleteTrackerCache();
    }
tsteur commented 10 years ago

During update/downgrade/... it is not called I think. At least this is what I've experienced. I will try to reproduce it later. We should definitely remove the first line of that comment as a function does not know when it is called :)

tsteur commented 10 years ago

To reproduce I installed the CustomAlerts plugin. Afterwards I increased the version number form 0.1.12 to 0.1.13 in plugin.json and added the following CSS to the alerts.less file

body, html {
  background-color: red;
}

In database Piwik recognized the update but did not recompile the CSS. Same for downgrading.

julienmoumne commented 10 years ago

If you are manually editing files, you are then in "development mode" right?

_disable_mergedassets should then be set to true

tsteur commented 10 years ago

That's what I would normally do. But to reproduce this behavior on production I disabled merged assets (=false).

julienmoumne commented 10 years ago

Why would you edit files in a production environment?

tsteur commented 10 years ago

This is basically what happens when you update a 3rd party plugin in production environment

julienmoumne commented 10 years ago

Is there no button for the user to press in order to trigger the update?

julienmoumne commented 10 years ago

By 3rd party you mean a plugin not published in the marketplace right?

In that case, maybe the simple solution is to document the fact the tmp directory must be manually emptied when a plugin is manually updated.

tsteur commented 10 years ago

We experienced this issue also when updating plugins via Marketplace or when uploading a plugin ZIP in the UI. When you are running multiple PHP nodes you usually want to update manually though. Documenting could be a solution but can be problematic since you maybe do not directly notice that you forgot to clean the tmp directory (which also causes a rebuild of all JS files). In our case we didn't notice it in the beginning since everything still kinda worked but didn't. Maybe we can delete the assets in case any plugin changes? We do already have the installed version in the option table and can compare it with the current plugin version in the plugin.json file before it is actually updated.

tsteur commented 10 years ago

In 237d8efcc6e1ac8bf76ecdb7f2f0473b806b2551: fixes #4655 assets are not invalidated after a plugin change. To fix this issue (at least for now) we always compare the cache buster. For JavaScript in production this is always fast as the hash is based only on plugin names + version. For css we have to concat the content of all raw css/less files which should be still fast, especially since the css is cached in the browser afterwards. @Julien let me know what you think about this and we can change it otherwise

tsteur commented 10 years ago

In 3da7d94126c97b9e552c9bc8de658c4d8cf5691a: refs #4655 updated description of merged assets setting

timo-bes commented 10 years ago

The setting disable_merged_assets is mentioned multiple times in the code as well. I'd suggest updating all descriptions. Just do a quick search for disable_merged_assets to see what I mean: at a first glance, StylesheetUIAssetFetcher and AssetManager need updates as well.

Or maybe it would be better to remove the duplicate documentation and refer to the comment in global.ini from the other places.

tsteur commented 10 years ago

In 2a00eb6b5980cab2a7a9a8c58a1081478f319106: refs #4655 updated documentation as the merged_assets flag is not really relevant for CSS at the moment

tsteur commented 10 years ago

In b150893ba245a5b43ef8033c199e3ec3a5dfeada: refs #4655 updated description of merged assets option

tsteur commented 10 years ago

In 5c12352ae91a9a3e5c1dfa224d80d05b66f98b45: refs #4655 actually here we can refer to the comment in the config

tsteur commented 10 years ago

Thx Timo! I removed it in one place and updated another. Probably we still need the documentation in two places. The inline doc for developers (developer.piwik.org) and the other one for people who want to configure Piwik and just browse through the config.