Skip to content

Commit

Permalink
quiz-data - Refactor multiple repo creation
Browse files Browse the repository at this point in the history
  • Loading branch information
EJMFarrow committed Oct 22, 2024
1 parent 56b6980 commit 5ba319d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
7 changes: 2 additions & 5 deletions classes/cli_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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':
Expand Down
25 changes: 12 additions & 13 deletions cli/createmultiplerepos.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
}

// Create course repo.
$scriptdirectory = dirname(__FILE__);
$clihelper = new cli_helper($options);
$arguments = $clihelper->get_arguments();
$arguments['contextlevel'] = 'course';
Expand All @@ -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;
}
8 changes: 8 additions & 0 deletions cli/createrepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit 5ba319d

Please sign in to comment.