2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Build and store theme CSS.
22 * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 define('CLI_SCRIPT', true);
28 require(__DIR__
.'/../../config.php');
29 require_once("$CFG->libdir/clilib.php");
30 require_once("$CFG->libdir/csslib.php");
31 require_once("$CFG->libdir/outputlib.php");
48 list($options, $unrecognized) = cli_get_params($longparams, $shortmappings);
51 $unrecognized = implode("\n ", $unrecognized);
52 cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
55 if ($options['help']) {
57 "Compile the CSS for one or more installed themes.
58 Existing CSS caches will replaced.
59 By default all themes will be recompiled unless otherwise specified.
62 -t, --themes A comma separated list of themes to be compiled
63 -d, --direction Only compile a single direction (either ltr or rtl)
64 -v, --verbose Print info comments to stdout
65 -h, --help Print out this help
68 \$ sudo -u www-data /usr/bin/php admin/cli/build_theme_css.php --themes=boost --direction=ltr
74 if (empty($options['verbose'])) {
75 $trace = new null_progress_trace();
77 $trace = new text_progress_trace();
80 cli_heading('Build theme css');
82 // Determine which themes we need to build.
84 if (is_null($options['themes'])) {
85 $trace->output('No themes specified. Finding all installed themes.');
86 $themenames = array_keys(core_component
::get_plugin_list('theme'));
88 if (is_string($options['themes'])) {
89 $themenames = explode(',', $options['themes']);
91 cli_error('--themes must be a comma separated list of theme names');
95 $trace->output('Checking that each theme is correctly installed...');
97 foreach ($themenames as $themename) {
98 if (is_null(theme_get_config_file_path($themename))) {
99 cli_error("Unable to find theme config for {$themename}");
102 // Load the config for the theme.
103 $themeconfigs[] = theme_config
::load($themename);
106 $directions = ['ltr', 'rtl'];
108 if (!is_null($options['direction'])) {
109 if (!in_array($options['direction'], $directions)) {
110 cli_error("--direction must be either ltr or rtl");
113 $directions = [$options['direction']];
116 $trace->output('Building CSS for themes: ' . implode(', ', $themenames));
117 theme_build_css_for_themes($themeconfigs, $directions);