Git merges in Moodle 3.1.8 by Andrew Nicols

commit 45a405014e28a965b3f7328efa49774e360cacdc
Author: Andrew Nicols <andrew@nicols.co.uk>
Date:   Thu, 20 Jul 2017 10:24:43 +0800
Tag:    v3.1.8

Merge branch 'wip-MDL-57649-31-fix2' of git://github.com/abgreeve/moodle into MOODLE_31_STABLE