From bb8bb8e41cea2216cfdd28bf353d413cb60a4428 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Thu, 30 Nov 2017 05:49:45 +0000 Subject: [PATCH] MDL-60815 theme: fix loading editor styles --- lib/outputlib.php | 8 ++++++++ lib/tests/theme_config_test.php | 22 ++++++++++++++++++++++ theme/styles.php | 10 +++------- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/outputlib.php b/lib/outputlib.php index 7a8beff5226..e5a8514d980 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -897,6 +897,14 @@ class theme_config { global $CFG; $rev = theme_get_revision(); if ($rev > -1) { + $themesubrevision = theme_get_sub_revision_for_theme($this->name); + + // Provide the sub revision to allow us to invalidate cached theme CSS + // on a per theme basis, rather than globally. + if ($themesubrevision && $themesubrevision > 0) { + $rev .= "_{$themesubrevision}"; + } + $url = new moodle_url("/theme/styles.php"); if (!empty($CFG->slasharguments)) { $url->set_slashargument('/'.$this->name.'/'.$rev.'/editor', 'noparam', true); diff --git a/lib/tests/theme_config_test.php b/lib/tests/theme_config_test.php index 99ab6a98423..85945c41cd0 100644 --- a/lib/tests/theme_config_test.php +++ b/lib/tests/theme_config_test.php @@ -153,4 +153,26 @@ class core_theme_config_testcase extends advanced_testcase { $this->assertTrue(core_useragent::set_user_device_type('tablet')); $this->assertTrue(core_useragent::set_user_device_type('featurephone')); } + + /** + * Confirm that the editor_css_url contains the theme revision and the + * theme subrevision if not in theme designer mode. + */ + public function test_editor_css_url_has_revision_and_subrevision() { + global $CFG; + + $this->resetAfterTest(); + $theme = theme_config::load(theme_config::DEFAULT_THEME); + $themename = $theme->name; + $themerevision = 1234; + $themesubrevision = 5678; + + $CFG->themedesignermode = false; + $CFG->themerev = $themerevision; + + theme_set_sub_revision_for_theme($themename, $themesubrevision); + $url = $theme->editor_css_url(); + + $this->assertRegExp("/{$themerevision}_{$themesubrevision}/", $url->out(false)); + } } diff --git a/theme/styles.php b/theme/styles.php index 4977095decd..6a4aa9b9d60 100644 --- a/theme/styles.php +++ b/theme/styles.php @@ -69,11 +69,7 @@ $values = explode('_', $rev); $rev = min_clean_param(array_shift($values), 'INT'); $themesubrev = array_shift($values); -if (is_null($themesubrev)) { - // Default to the current theme subrevision if one isn't - // provided in the URL. - $themesubrev = theme_get_sub_revision_for_theme($themename); -} else { +if (!is_null($themesubrev)) { $themesubrev = min_clean_param($themesubrev, 'INT'); } @@ -144,12 +140,12 @@ make_localcache_directory('theme', false); if ($type === 'editor') { $csscontent = $theme->get_css_content_editor(); - css_store_css($theme, $candidatesheet, $csscontent, false); if ($cache) { + css_store_css($theme, $candidatesheet, $csscontent, false); css_send_cached_css($candidatesheet, $etag); } else { - css_send_uncached_css(file_get_contents($candidatesheet)); + css_send_uncached_css($csscontent); } }