Skip to content

Commit

Permalink
quiz-data - Make quiz export easier
Browse files Browse the repository at this point in the history
  • Loading branch information
EJMFarrow committed Dec 5, 2024
1 parent 275d1ad commit 297d494
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
19 changes: 2 additions & 17 deletions classes/create_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ public function create_quiz_directories(object $clihelper, string $scriptdirecto
* @param string $instanceid
* @param string $token
* @param string $ignorecat
* @param string $scriptdirectory
* @return string|null
*/
public function call_repo_creation(string $rootdirectory, string $moodleinstance, string $instanceid,
Expand All @@ -315,20 +316,4 @@ public function call_repo_creation(string $rootdirectory, string $moodleinstance
$rootdirectory . '" -i "' . $moodleinstance .
'" -l "module" -n ' . $instanceid . ' -t ' . $token . $ignorecat);
}

/**
* Separate out exec call for mocking.
*
* @param string $moodleinstance
* @param string $token
* @param string $quizmanifestpath
* @return string|null
*/
public function call_export_quiz(string $moodleinstance, string $token,
string $quizmanifestpath, string $scriptdirectory): ?string {
chdir($scriptdirectory);
return shell_exec('php exportquizstructurefrommoodle.php -u ' . $this->usegit .
' -w -r "" -i "' . $moodleinstance . '" -t "'
. $token. '" -p "' . $this->manifestpath . '" -f "' . $quizmanifestpath . '"');
}
}
}
32 changes: 32 additions & 0 deletions classes/export_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,38 @@ public function export_to_repo_main_process(object $moodlequestionlist): void {
}
}

public function export_quiz_structure($clihelper, $scriptdirectory) {
$arguments = $clihelper->get_arguments();
$moodleinstance = $arguments['moodleinstance'];
if (is_array($arguments['token'])) {
$token = $arguments['token'][$moodleinstance];
} else {
$token = $arguments['token'];
}
$quizmanifestpath = cli_helper::get_manifest_path($moodleinstance, 'module', null,
$this->manifestcontents->context->coursename,
$this->manifestcontents->context->modulename, dirname($this->manifestpath));
$output = $this->call_export_quiz($moodleinstance, $token, $quizmanifestpath, $scriptdirectory);
echo $output;
}

/**
* Separate out exec call for mocking.
*
* @param string $moodleinstance
* @param string $token
* @param string $quizmanifestpath
* @param string $scriptdirectory
* @return string|null
*/
public function call_export_quiz(string $moodleinstance, string $token,
string $quizmanifestpath, string $scriptdirectory): ?string {
chdir($scriptdirectory);
return shell_exec('php exportquizstructurefrommoodle.php -u ' . $this->usegit .
' -w -r "" -i "' . $moodleinstance . '" -t "'
. $token. '" -p "' . $this->manifestpath . '" -f "' . $quizmanifestpath . '"');
}

/**
* Mockable function that just exits code.
*
Expand Down
8 changes: 8 additions & 0 deletions cli/createrepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,11 @@
$clihelper->check_repo_initialised($createrepo->manifestpath);
$createrepo->process();
$clihelper->commit_hash_setup($createrepo);
if ($createrepo->manifestcontents->context->contextlevel === 70) {
$scriptdirectory = dirname(__FILE__);
$createrepo->export_quiz_structure($clihelper, $scriptdirectory);
chdir(dirname($createrepo->manifestpath));
exec("git add --all");
exec('git commit -m "Initial Commit - Quiz structure"');
}

4 changes: 4 additions & 0 deletions cli/exportrepofrommoodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@
$clihelper->check_for_changes($exportrepo->manifestpath);
$clihelper->backup_manifest($exportrepo->manifestpath);
$exportrepo->process();
if ($exportrepo->manifestcontents->context->contextlevel === 70) {
$scriptdirectory = dirname(__FILE__);
$exportrepo->export_quiz_structure($clihelper, $scriptdirectory);
}
2 changes: 1 addition & 1 deletion lang/en/qbank_gitsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$string['categoryerror'] = 'Problem with question category: {$a}';
$string['categoryerrornew'] = 'Problem with question category: {$a}. If the course is new, please open the question bank in Moodle to initialise it and try Gitsync again.';
$string['categoryerrornew'] = 'Problem with question category: {$a}. If the course or module is new, please open the question bank in Moodle to initialise it and try Gitsync again.';
$string['categorymismatcherror'] = 'Problem with question category: {$a}. The category is not in the supplied context.';
$string['contexterror'] = 'The context level is invalid: {$a}';
$string['exporterror'] = 'Could not export question id: {$a}';
Expand Down

0 comments on commit 297d494

Please sign in to comment.