-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Twig 3 upgrade #15573
Twig 3 upgrade #15573
Conversation
As you might know the reason for RenderTokenParser better: It seems like all classes still exist and accept the same variables. But when compiling I get the following error:
with the compiled template being: // line 4
public function block_topcontrols($context, array $blocks = [])
{
$macros = $this->macros;
// line 5
echo " ";
$this->loadTemplate("@CoreHome/_siteSelectHeader.twig", "@CoreHome/getDefaultIndexView.twig", 5)->display($context);
// line 6
echo " ";
$this->loadTemplate("@CoreHome/_periodSelect.twig", "@CoreHome/getDefaultIndexView.twig", 6)->display($context);
// line 7
echo " ";
echo call_user_func_array($this->env->getFunction('postEvent')->getCallable(), ["Template.nextToCalendar"]);
echo "
";
// line 8
$this->loadTemplate(twig_call_macro($macros["dashboardSettingsControl"], "getTemplateFile", [], 8, $context, $this->getSourceContext()), "@CoreHome/getDefaultIndexView.twig", 8)->display(twig_array_merge($context, twig_call_macro($macros["dashboardSettingsControl"], "getTemplateVars", [], 8, $context, $this->getSourceContext())));
// line 9
echo " ";
$this->loadTemplate("@CoreHome/_headerMessage.twig", "@CoreHome/getDefaultIndexView.twig", 9)->display($context);
} and |
To fix the remaining tests, this patch is needed for CustomAlerts, but it is not compatible with Twig <2.9 so it would break before this is merged: diff --git a/templates/macros.twig b/templates/macros.twig
index 48f88fe..7b6adcd 100644
--- a/templates/macros.twig
+++ b/templates/macros.twig
@@ -1,5 +1,5 @@
{% macro metricChangeDescription(alert) %}
-{% spaceless %}
+{% apply spaceless %}
{%- if alert.metric_condition == 'less_than' %}
{{ 'CustomAlerts_ValueIsLessThan'|translate(alert.metric_matched, alert.value_new) }}
{% elseif alert.metric_condition == 'greater_than' %}
@@ -13,5 +13,5 @@
{% elseif alert.metric_condition == 'percentage_increase_more_than' %}
{{ 'CustomAlerts_ValuePercentageIncreasedMoreThan'|translate(alert.metric_matched, alert.value_old|default('-'), alert.value_new) }}
{% endif -%}
-{% endspaceless %}
+{% endapply %}
{% endmacro %}
\ No newline at end of file |
@Findus23 I compared your template w/ the template on twig 2, seems instead of RenderTokenParser was written before adopting angularjs, it was trying to solve the same problem of grouping rendering & behavioral logic together in units (like components/directives). It's not needed and can be removed. Does this help? |
@Findus23 are you still working on that one, or should someone take over? |
@sgiehl I don't think I am able to rewrite or remove the RenderTokenParser and the rest should be done (apart from the things mentioned in the first comment) so someone can take over. |
Tried to dig a bit deeper into the @diosmosis If you think it's useful to completely remove the Will go though the failing UI tests now and fix them... |
I can take a look, but I'm not sure exactly when. |
BTW @Findus23 @sgiehl is there a big benefit from Twig 3 or any particular issue it solves? If it takes any more time we might otherwise rather do this in Matomo 5 or so considering it wasn't in the original Matomo 4 milestone. If we merge this, we'd likely also need to implement matomo-org/matomo-for-wordpress#233 potentially as I'd expect most WordPress plugins that use twig still use an older version and to avoid some compatibility issues. Also we'd need to see re the PHP 7.2.5 requirement increase as in WP we defined 7.2 but that might be fine. Be curious to learn what benefit Twig 3 brings and be great to know how long Twig 2 receives updates. |
At the moment we are not using Twig 2 (otherwise the update would be far simpler), but Twig 1. Benefits I can think of at the moments:
The changes are not that huge and I think with the changes by @sgiehl it is 95% finished. But now with Matomo 4 it would be a good chance to easily make a breaking chance when the next one will only come in 3 or 4 years. |
Sounds good. Will need to see how this impacts WordPress. Quite annoying re the PHP 7.2.5. Also bit scared of these global things where we need to adjust the twig files for many plugins as it costs us a lot of time and the same for developers should they need to migrate twig files (although not many developers use it to a big extend anyway it be mostly us). Eg adjusting all our plugins and especially premium features and cloud and account management code might take quite a long time as there will be a lot of testing needing to be done etc. In Premium Features a lot of the code should be in angular though. @sgiehl can you estimate how much work is left to be done here for core plus our open source plugins? |
@tsteur core and submodule plugins should work already. There shouldn't be much work to do for the other plugins I think. It's mostly only changing if conditions in for loops into filters, and converting the spaceless tag if it was used. And some imports might need to be moved as the context seems to have changed in some cases. Imho someone else should do a review now. Afterwards we can merge and should then see in the UI tests of our other plugins if something need to be changed. But will also do a search through the other plugins once this is merged and update them if needed... |
Will do a review 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.
Code looks fine, no issues in the UI I could find.
We can look into the premium features and cloud later. I can do the migration for most plugins. @sgiehl be good to summarise in a new section in /~https://github.com/matomo-org/matomo/wiki/Matomo-4.0.0-release-notes what changes in Twig 3 and how to change it. I suppose there are a few common things. This will make it easier for us and for developers. Like some examples like the ones below which we can then put into a migration guide.
Be good to not migrate the other plugins for now but focus on Matomo 4 issues. |
BTW: Adjusting the templates shouldn't be complex in most cases, so once we are in the first beta releases I could create PRs for all non-premium plugins and some major third-party plugins. |
@Findus23 it's mostly just the testing for our many non-core plugins as not everything is covered by UI tests etc. If we give 3rd party developers some examples on how to migrate it like we did in https://developer.matomo.org/guides/migrate-piwik-2-to-3 that will be great so it's easy for them to do. |
@tsteur added some migration notes here: /~https://github.com/matomo-org/matomo/wiki/Matomo-4.0.0-release-notes#migrating-templates-to-twig-3 |
updated the branch and it imho should be good to merge now. |
Looks good to me 👍 |
Concerns re the required PHP version etc but all good to merge. |
@tsteur the Twig documentation still clearly says it requires PHP 7.2.0 (see https://twig.symfony.com/doc/3.x/intro.html), not sure why they increased the requirement in composer.json to PHP 7.2.5 🤷 So maybe it would even run with PHP 7.2.0 |
It seems like it was set in But I doubt that matters as I hope no one uses PHP |
This is just a quick test to see how much work upgrading to Twig 3 would be.
It turns out that apart from replacing tons of classnames, there is little else to change. On a first look all Matomo seemed to work with just two minor template changes.
Things left to do:
core/View.php
to see the full template path to twig errorsI couldn't find the correct return Object for the RenderTokenParserSee below