Dashboard reset times out

Dashboard reset times out

by Diane Soini -
Number of replies: 0

I submitted a tracker to suggest that the dashboard reset should be a cli script because the GUI script times out for our installation because we have over 100K users and they suggested to me to post my solution here.

Here is the script which is placed in admin/cli:

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see 

/**
 * CLI script to reset dashboards.
 *
 * @package    core
 * @subpackage cli
 * @copyright  2011 David Mudrak 
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

define('CLI_SCRIPT', true);

require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php');
require_once($CFG->dirroot.'/my/lib.php');

$longoptions = [
    'help' => false,
];
list($options, $unrecognized) = cli_get_params($longoptions, ['h' => 'help']);

if ($unrecognized) {
    $unrecognized = implode("\n  ", $unrecognized);
    cli_error(get_string('cliunknowoption', 'admin', $unrecognized), 2);
}

if ($options['help']) {
    // The indentation of this string is "wrong" but this is to avoid a extra whitespace in console output.
    if ($options['help']) {
    // The indentation of this string is "wrong" but this is to avoid a extra whitespace in console output.
    $help = <<<EOF
Resets Moodle dashboards for all users

Options:
-h, --help            Print out this help

Example:
\$ sudo -u www-data /usr/bin/php admin/cli/reset_dashboards.php

EOF;

    echo $help;
    exit(0);
}

my_reset_page_for_all_users(MY_PAGE_PRIVATE, 'my-index');

exit(0);
@moodle.com>
Average of ratings: -