Skip to content

Commit

Permalink
MDL-16177 Detecting if script is called from URL, in which case it pr…
Browse files Browse the repository at this point in the history
…ints header, footer and form. Otherwise, silently create a global $generator object that can be used by unit tests.
  • Loading branch information
nicolasconnault committed Jun 22, 2009
1 parent f45f654 commit c20b684
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions admin/generator.php
Expand Up @@ -541,7 +541,7 @@ public function generate_modules($courses) {
$module->section = $section->id;
$module->coursemodule = add_course_module($module);
$module->section = $i;

if (function_exists($add_instance_function)) {
$this->verbose("Calling module function $add_instance_function");
$module->instance = $add_instance_function($module, '');
Expand All @@ -567,7 +567,7 @@ public function generate_modules($courses) {
if (empty($modules_array[$moduledata->name])) {
$modules_array[$moduledata->name] = array();
}

// TODO Find out why some $module_record end up empty here... (particularly quizzes)
if (!empty($module_record->instance)) {
$modules_array[$moduledata->name][] = $module_record;
Expand Down Expand Up @@ -1168,9 +1168,9 @@ public function generate_data() {
private function _arguments($argv) {
$_ARG = array();
foreach ($argv as $arg) {
if (ereg('--?([^=]+)=(.*)',$arg,$reg)) {
if (preg_match('/--?([^=]+)=(.*)/',$arg,$reg)) {
$_ARG[$reg[1]] = $reg[2];
} elseif(ereg('-([a-zA-Z0-9]+)',$arg,$reg)) {
} elseif(preg_match('/-([a-zA-Z0-9]+)/',$arg,$reg)) {
$_ARG[$reg[1]] = 'true';
}
}
Expand Down Expand Up @@ -1222,6 +1222,10 @@ public function __destroy() {
}
}

class generator_silent extends generator {

}

function generator_generate_data($settings) {
$generator = new generator($settings);
$generator->do_generation = true;
Expand Down Expand Up @@ -1293,11 +1297,13 @@ function definition_after_data() {
if (isset($argv) && isset($argc)) {
$generator = new generator_cli($argv, $argc);
$generator->generate_data();
} else {
} elseif (strstr($_SERVER['REQUEST_URI'], 'generator.php')) {
$generator = new generator_web();
$generator->setup();
$generator->display();
$generator->generate_data();
} else {
$generator = new generator_silent();
}

?>

0 comments on commit c20b684

Please sign in to comment.