MDL-29029 move unmaintained generator to admin tools

Do NOT add link into settings tree, this is extremely dangerous and buggy. It is now usable only in DEBUG_DEVELOPER mode!
This commit is contained in:
Petr Skoda
2011-09-17 12:34:49 +02:00
parent b412f9c4c9
commit 6c7365d98d
6 changed files with 156 additions and 34 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Random course generator CLI interface.
*
* @package tool
* @subpackage generator
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('CLI_SCRIPT', true);
require(dirname(__FILE__) . '/../../../../config.php');
require_once(dirname(__FILE__) . '/../locallib.php');
if (!debugging('', DEBUG_DEVELOPER)) {
echo("This script is for developers only!!!\n");
exit(1);
}
$generator = new generator_cli($argv, $argc);
$generator->generate_data();
+48
View File
@@ -0,0 +1,48 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Random course generator.
*
* @package tool
* @subpackage generator
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(dirname(__FILE__) . '/../../../config.php');
require_once('locallib.php');
require_login();
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/site:config', $systemcontext);
if (!is_siteadmin()) {
error('Only for admins');
}
if (!debugging('', DEBUG_DEVELOPER)) {
error('This script is for developers only!!!');
}
$PAGE->set_url('/admin/tool/generator/index.php');
$PAGE->set_context(get_system_context());
$PAGE->set_pagelayout('base');
$generator = new generator_web();
$generator->setup();
$generator->display();
$generator->generate_data();
$generator->complete();
@@ -0,0 +1,26 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Strings for component 'tool_generator', language 'en', branch 'MOODLE_22_STABLE'
*
* @package tool
* @subpackage generator
* @copyright 2011 petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Random course generator';
@@ -1,5 +1,4 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -18,14 +17,14 @@
/**
* Random course generator. By Nicolas Connault and friends.
*
* To use go to .../admin/generator.php?web_interface=1 in your browser.
*
* @package generator
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package tool
* @subpackage generator
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__).'/../config.php');
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot .'/course/lib.php');
require_once($CFG->libdir .'/filelib.php');
@@ -1120,7 +1119,7 @@ class generator_cli extends generator {
$help .= " -{$argument->short},$paddingstr1--{$argument->long}$equal$paddingstr2{$argument->help}\n";
}
$help .= "\nEmail nicolas@moodle.com for any suggestions or bug reports.\n";
$help .= "\nUse http://tracker.moodle.org for any suggestions or bug reports.\n";
if ($argc == 1 || in_array($settings[1], array('--help', '-help', '-h', '-?'))) {
echo $help;
@@ -1176,14 +1175,12 @@ class generator_cli extends generator {
echo "Invalid username or password!{$this->eolchar}";
die();
}
complete_user_login($user);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if (!is_siteadmin($user->id)) {//TODO: add some proper access control check here!!
if (!is_siteadmin($user)) {//TODO: add some proper access control check here!!
echo "You do not have administration privileges on this Moodle site. "
."These are required for running the generation script.{$this->eolchar}";
die();
}
complete_user_login($user);
}
parent::generate_data();
@@ -1215,14 +1212,15 @@ class generator_web extends generator {
global $CFG;
$this->mform = new generator_form();
$this->do_generation = optional_param('do_generation', false, PARAM_BOOL);
if ($data = $this->mform->get_data(false)) {
$this->do_generation = optional_param('do_generation', false, PARAM_BOOL);
foreach ($this->settings as $setting) {
if (isset($data->{$setting->long})) {
$this->set($setting->long, $data->{$setting->long});
}
}
} else {
$this->do_generation = false;
}
}
@@ -1315,22 +1313,3 @@ class generator_form extends moodleform {
}
}
if (CLI_SCRIPT) {
$generator = new generator_cli($argv, $argc);
$generator->generate_data();
} elseif (strstr($_SERVER['REQUEST_URI'], 'generator.php')) {
require_login();
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
require_capability('moodle/site:config', $systemcontext);
$PAGE->set_url('/admin/generator.php');
$PAGE->set_pagelayout('base');
$generator = new generator_web();
$generator->setup();
$generator->display();
$generator->generate_data();
$generator->complete();
} else {
$generator = new generator_silent();
}
+32
View File
@@ -0,0 +1,32 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* Version details.
*
* @package tool
* @subpackage generator
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2011091700; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2011091600; // Requires this Moodle version
$plugin->component = 'tool_generator'; // Full name of the plugin (used for diagnostics)
$maturity = MATURITY_ALPHA; // this version's maturity level
+1 -1
View File
@@ -367,7 +367,7 @@ class plugin_manager {
),
'tool' => array(
'capability', 'profiling', 'unittest', 'unsuproles'
'capability', 'generator', 'profiling', 'unittest', 'unsuproles'
),
'webservice' => array(