diff --git a/classes/cli_helper.php b/classes/cli_helper.php index 6031d57..fe0f0c9 100644 --- a/classes/cli_helper.php +++ b/classes/cli_helper.php @@ -49,10 +49,7 @@ class cli_helper { * @var array|null Full set of options combining command line and defaults */ public ?array $processedoptions = null; - /** - * @var bool Are we processing quizzes as part of a multiple repo shortcut? - */ - public bool $ischildquiz = false; + /** * CATEGORY_FILE - Name of file containing category information in each directory and subdirectory. */ @@ -763,7 +760,7 @@ public function check_context(object $activity, bool $defaultwarning=false, bool echo "Failed to get list of questions from Moodle.\n"; static::call_exit(); return new \stdClass(); // Required for PHPUnit. - } else if (!$silent && !$this->ischildquiz) { + } else if (!$silent && !isset($this->get_arguments()['quiet'])) { $activityname = get_class($activity); switch ($activityname) { case 'qbank_gitsync\export_repo': diff --git a/cli/createmultiplerepos.php b/cli/createmultiplerepos.php index db8ebca..11bba72 100755 --- a/cli/createmultiplerepos.php +++ b/cli/createmultiplerepos.php @@ -141,6 +141,7 @@ } // Create course repo. +$scriptdirectory = dirname(__FILE__); $clihelper = new cli_helper($options); $arguments = $clihelper->get_arguments(); $arguments['contextlevel'] = 'course'; @@ -152,24 +153,22 @@ $clihelper->commit_hash_setup($createrepo); // Create quiz repos. -$clihelper->ischildquiz = true; $contextinfo = $clihelper->check_context($createrepo, false, true); if ($arguments['directory']) { $basedirectory = $arguments['rootdirectory'] . '/' . $arguments['directory']; } else { $basedirectory = $arguments['rootdirectory']; } -$arguments['directory'] = ''; -$arguments['contextlevel'] = 'module'; -$arguments['subcategory'] = null; -$arguments['coursename'] = null; -$arguments['questioncategoryid'] = null; +$moodleinstance = $arguments['moodleinstance']; +$instanceid = $arguments['instanceid']; +$token = $arguments['token'][$moodleinstance]; +$ignorecat = $arguments['ignorecat']; +$ignorecat = ($ignorecat) ? ' -x "' . $ignorecat . '"' : ''; foreach ($contextinfo->quizzes as $quiz) { - $arguments['instanceid'] = "{$quiz->instanceid}"; - $arguments['rootdirectory'] = $clihelper->create_initialised_repo(cli_helper::get_quiz_directory($basedirectory, $quiz->name)); - echo "\nExporting quiz: {$quiz->name} to {$arguments['rootdirectory']}\n"; - $clihelper->processedoptions = $arguments; - $createrepo = new create_repo($clihelper, $moodleinstances); - $createrepo->process(); - $clihelper->commit_hash_setup($createrepo); + $instanceid = "{$quiz->instanceid}"; + $rootdirectory = $clihelper->create_initialised_repo(cli_helper::get_quiz_directory($basedirectory, $quiz->name)); + echo "\nExporting quiz: {$quiz->name} to {$rootdirectory}\n"; + chdir($scriptdirectory); + $output = shell_exec('php createrepo.php -r "' . $rootdirectory . '" -i "' . $moodleinstance . '" -l "module" -n ' . (int) $instanceid . ' -t ' . $token . ' -z' . $ignorecat); + echo $output; } diff --git a/cli/createrepo.php b/cli/createrepo.php index 55efb82..30c230d 100755 --- a/cli/createrepo.php +++ b/cli/createrepo.php @@ -147,6 +147,14 @@ 'variable' => 'ignorecat', 'valuerequired' => true, ], + [ + 'longopt' => 'quiet', + 'shortopt' => 'z', + 'description' => 'Do not display context info or option to abort.', + 'default' => false, + 'variable' => 'quiet', + 'valuerequired' => false, + ], ]; if (!function_exists('simplexml_load_file')) {