[SOLVED] Essential: upgrade made theme totally unusable

[SOLVED] Essential: upgrade made theme totally unusable

by Stephen McConnachie -
Number of replies: 19

Hi all, 

I love the essential theme, but when I upgraded it in the weekend it went completely bizarre. My Moodle was 2.7.1 and I upgraded from Essential 2.7.3ish to the latest compatible with Moodle 2.7, Essential 2.7.9.4.3 (Build: 2014111007). It passed the plugin verification test prior to installation, and I upgraded it from within Moodle, but the theme immediately broke. My settings remained intact, but all elements on the page were displayed as plaintext down the page. We've tried reverting to old Essential, tried upgrading Moodle core to 2.7.3+, tried completely removing Essential and reinstalling, but no luck. The only change is that removing and reinstalling the theme just lost all my settings (which I have saved anyway so no trouble) and reset to Essential defaults, but it's still just displaying as plaintext on the page. 

Support Desk says "The problem is that it's trying to find the CSS from http://middleton.moodle2.net.nz/pluginfile.php/1/theme_essential/style/-1/essential.css, which is using the pluginfile script to retrieve it from the cache somewhere. And I think that the -1 should be a larger number; it implies that it can't identify the location in the cache." Is there a way to make it read directly from a folder somewhere? We know where the Essential css files are stored on the server, but can't get Moodle to look in the right place.

Help! Has this happened to anyone else? Any suggestions? It's not usable in its current state, so I've reverted to my old customised Brick theme for now but we're in the middle of starting the year with heaps more staff buy-in than last year, and I can feel the buy-in eroding with each passing hour that our Moodle site is clunky and ugly! Any suggestions gratefully accepted. 

Currently running Moodle 2.7.3 (20141110) and Essential 2.7.9.4.3 (2014111007).

(Edited by Gareth J Barnard - original submission Monday, 9 February 2015, 11:34 PM) - Added [SOLVED]

Average of ratings: -
In reply to Stephen McConnachie

Re: Essential: upgrade made theme totally unusable

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Until Gareth gets here, my first thoughts were that you hit the panic button, and did too many things all at once.

At any stage in all that you have tried, did you Purge all cache ?

You could also try turning on Debugging too, just incase there are some missing files in your upgrade.

Cheers

Mary

In reply to Mary Evans

Re: Essential: upgrade made theme totally unusable

by Stephen McConnachie -

Yeah I did try purging all caches. Haha yes that's certainly a possibility! I did try each thing one at a time and check as I went but it may have been a bit full on. 

Stoked with how quickly you guys came in with solutions! Thank you heaps

In reply to Stephen McConnachie

Re: Essential: upgrade made theme totally unusable

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Stephen,

Ok, ops!  So far this technology has been around for since October and no reports of this error.  Ok, I've investigated and the eTag is not being generated for the file: https://github.com/gjb2048/moodle-theme_essential/blob/aa91a37359f3da56ed86231a0845941f363d2ced/lib.php#L210 - which means 'md5_file' is failing for some reason.  Please see attached.  I don't know why.  Did you not test on a test server first?  Sorry, but I cannot test every possible server setup.

But, it looks like the file URLhttp://middleton.moodle2.net.nz/theme/essential/style/essential.css works.  So, to use that instead, change this function to return the URL string instead of what it does (make a backup first) as this is an educated guess: https://github.com/gjb2048/moodle-theme_essential/blob/aa91a37359f3da56ed86231a0845941f363d2ced/lib.php#L133-L147 - so something like:

return '//middleton.moodle2.net.nz/theme/essential/style/essential.css';

instead of:

return $url;

Which should work with TDM off.  Also before you do make sure theme switching setting via URL is turned on so you can get yourself out of a spot.

Please do kindly post any PHP / Server errors here and I'll look when I wake up later this morning.

Gareth

Attachment 2015-02-10 01_03_33-.png
In reply to Gareth J Barnard

Re: Essential: upgrade made theme totally unusable

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Sorry Gareth, I was just posting a comment and find you had posted your comment just at the same time more or less.

Stephen has Allow theme change set already I have just been looking at te site.

I think they added the CSS file in header but is wrong location so suggested they add

<link href="//middleton.moodle2.net.nz/theme/essential/style/essential.css" rel="stylesheet">

instead...

Anyway...I'll leave this up to you as you know more about this theme than anyone! LOL

Cheers

Mary

In reply to Mary Evans

Re: Essential: upgrade made theme totally unusable

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

No worries Mary, each solution valid, but I think mine will be a one place for all solution.

In reply to Mary Evans

Re: Essential: upgrade made theme totally unusable

by Stephen McConnachie -

Yup adding that line in my browser fixes it perfectly for that one instance, though now I'm confused as to what the id number does in the generated url - I thought it must call my own essential.css which was based on the generic essential.css that sat in the shared code. If not, what's the purpose of the generated urls? Just out of curiosity as I'm just learning all this stuff...

In reply to Gareth J Barnard

Re: Essential: upgrade made theme totally unusable

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

P.s.

The -1 should be bigger but you've got TDM on.

Its not in the cache, but uses the same mechanism as images for the slider, but loads from a folder instead.  Even if I did not use pluginfile.php to make coping with theme folder location easier I still would have used eTag's for change detection.

Do you have a test server with the same identical setup for the verification checks you made?

In reply to Gareth J Barnard

Re: Essential: upgrade made theme totally unusable

by Stephen McConnachie -

OK that's awesome, I'll pass it on to the support desk folks as I can't access the server directly (our Moodle is hosted externally). 

I'll get them to check out the php and web server logs too. Just out of curiosity, what are eTags? 

Just to clarify, the line you're suggesting we replace is in lib.php in the \theme\essential folder?

And no I didn't have a test server... but from now on will set up my localhost Moodle installation as an identical setup and use it for checking! Lesson learnt...
(or would the test site need to be sitting on the same server as our live site in order to be useful?)

You guys are amazing, so grateful that you stepped in so quickly. 

In reply to Stephen McConnachie

Re: Essential: upgrade made theme totally unusable

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Stephen,

Ok, I've been sleeping on this and I might possibly improve the fall back mechanism for when the eTag fails as the file date / time is also being used to detect changes.  I'll need time to test a few theories though.

Right, eTags are mentioned in a link in the code: http://css-tricks.com/snippets/php/intelligent-php-cache-control/ and http://en.wikipedia.org/wiki/HTTP_ETag.

And indeed I'm suggesting the lib.php change as that function is called by all of the layout files either directly or indirectly by a file in the 'layout/includes' folder.  I wrote the code in the first place!

With test servers its best to have an identical set-up to that of production.

With the '-1' number that's all to do with Moodle core's theme cache versioning system.  When set at '-1' then TDM will be on and core code will always serve the file and no caching will happen.  When its a positive number then it will only change when 'Purge all caches' etc. ('theme_reset_all_caches' setting callback too.) happens such that the browser has a new URL and hence will get a full new copy of the CSS from the server instead of using the cached one.

If I get a moment (!!) then I'll set up a lighttpd LAMP stack with PHP 5.5.9-1 on Ubuntu to try and see why 'md5_file' returns false.

Cheers,

Gareth

In reply to Stephen McConnachie

Re: Essential: upgrade made theme totally unusable

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Stephen,

Even if I do something nutty like:

    //$etagfile = md5_file($thesheet);
    $etagfile = '';
    // File.
    $lastmodified = filemtime($thesheet);

then I can make it fail on the first page load but not on the second.  And certainly not getting two 'Expires' in the response headers for the HTTP GET exchange.

Has anybody changed the code in anyway?

Cheers,

Gareth

In reply to Gareth J Barnard

Re: Essential: upgrade made theme totally unusable

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

P.S.

I did notice on a LAMP server I used that the line:

if (empty($rss->error()))

caused a server 500 error, so could it be that:

if (!empty($CFG->themedir))

Is causing the same thing.  Anything from the logs?

In reply to Gareth J Barnard

Re: Essential: upgrade made theme totally unusable

by Tim Owens -

"Support Desk" here. I've tried the bodge described, and it appears to do the trick. I was actually planning a similar bodge myself...

The following logs might be of interest:

2015-02-09 15:59:55: (mod_fastcgi.c.2673) FastCGI-stderr: PHP Warning:  md5_file(/data/u00/www/htdocs/moodle2_shared/themes/middleton.moodle2.net.nz/essential/style/essential.css): failed to open stream: No such file or directory in /data/u00/www/htdocs/moodle2_shared/code_base_versions/dataview-custom/middleton/theme/essential/lib.php on line 210

2015-02-09 15:59:55: (mod_fastcgi.c.2673) FastCGI-stderr: PHP Warning:  filemtime(): stat failed for /data/u00/www/htdocs/moodle2_shared/themes/middleton.moodle2.net.nz/essential/style/essential.css in /data/u00/www/htdocs/moodle2_shared/code_base_versions/dataview-custom/middleton/theme/essential/lib.php on line 212

 Middleton.moodle2.net.nz routes to /data/u00/www/htdocs/middleton.moodle2.net.nz, which is a symbolic link to /data/u00/www/htdocs/moodle2_shared/code_base_versions/dataview-custom/middleton where the Moodle code is located. He has his own writeable copy. The filestore is on a separate server over NFS. The main config.php retrieves the database details from a common database and sets up $CFG to point to Middleton's database.

Looking at the code, I'm guessing $CFG->themedir is wrong. Ah. Oh. What the? OK.. let me locate the person who set that one up.... later tonight...

...to be continued... 

In reply to Tim Owens

Re: Essential: upgrade made theme totally unusable

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thanks for reporting Tim, I was worried that it was Essential.  I have double checked some core code to see that I was using '$CFG->themedir' correctly and in '/theme/font.php' there is:

} else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {

therefore the path I set in Essential is correct:

$thestylepath = $CFG->themedir . '/essential/style/';

And... 'bodge'!! What a cheek!  It is a carefully thought out workaround to solve the problem.  Perhaps next time I'll just go to sleep at 1AM instead of helping to resolve a panic.

In reply to Gareth J Barnard

Re: Essential: upgrade made theme totally unusable

by Tim Owens -

Your carefully thought out workaround and sleepily provided information directed me to the source of the problem that I've been spending 4 days losing hair over. I was beginning to lose hope!

I've now set up the themedir correctly and removed the carefully thought out workaround. All still appears to be working. Many thanks!

Average of ratings: Useful (2)
In reply to Tim Owens

Re: Essential: upgrade made theme totally unusable

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Thanks Tim, you should now be able to turn off TDM and speed things up a bit.

In reply to Stephen McConnachie

Re: Essential: upgrade made theme totally unusable

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Try adding this inside <head></head> tag in theme/essential/layout/includes/header.php

<link href="//middleton.moodle2.net.nz/theme/essential/style/essential.css" rel="stylesheet">

That works in FireBug OK, I've just tried it now.

Cheers

Mary