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 * This hack is intended for clustered sites that do not want
19 * to use shared cachedir for component cache.
21 * This file needs to be called after any change in PHP files in dataroot,
22 * that is before upgrade and install.
25 * @copyright 2013 Petr Skoda (skodak) {@link http://skodak.org}
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 define('CLI_SCRIPT', true);
31 define('ABORT_AFTER_CONFIG', true); // We need just the values from config.php.
32 define('CACHE_DISABLE_ALL', true); // This prevents reading of existing caches.
33 define('IGNORE_COMPONENT_CACHE', true);
35 require(__DIR__
.'/../../config.php');
36 require_once($CFG->libdir
.'/clilib.php');
38 // Now get cli options.
39 list($options, $unrecognized) = cli_get_params(
52 $unrecognized = implode("\n ", $unrecognized);
53 cli_error(get_string('cliunknowoption', 'admin', $unrecognized), 2);
56 if (!$options['rebuild'] and !$options['file'] and !$options['print']) {
58 "Create alternative component cache file
61 -h, --help Print out this help
62 --rebuild Rebuild \$CFG->alternative_component_cache file
63 --file=filepath Save component cache to file
64 --print Print component cache file content
67 \$ php admin/cli/rebuild_alternative_component_cache.php --rebuild
74 error_reporting(E_ALL | E_STRICT
);
75 ini_set('display_errors', 1);
77 $content = core_component
::get_cache_content();
79 if ($options['print']) {
84 if ($options['rebuild']) {
85 if (empty($CFG->alternative_component_cache
)) {
86 fwrite(STDERR
, 'config.php does not contain $CFG->alternative_component_cache setting');
90 $target = $CFG->alternative_component_cache
;
92 $target = $options['file'];
96 fwrite(STDERR
, "Invalid target file $target");
101 $bytes = file_put_contents($target, $content);
104 fwrite(STDERR
, "Error writing to $target");
105 fwrite(STDERR
, "\n");
110 echo "File $target was updated\n";