Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quiz data #57

Merged
merged 48 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0542594
quiz-data - Quiz data export webservice
EJMFarrow Oct 4, 2024
e06ecf0
quiz-data - Import quiz webservice
EJMFarrow Oct 16, 2024
132a509
quiz-data - Fill in defaults, match import and export
EJMFarrow Oct 17, 2024
2ebe5cd
quiz-data - Basic export CLI
EJMFarrow Oct 17, 2024
a3baa9a
quiz-data - Import CLI
EJMFarrow Oct 17, 2024
19829a3
quiz-data - Allow questions from 2 contexts in quiz.
EJMFarrow Oct 18, 2024
56b6980
quiz-data - First pass at exporting quizzes with course
EJMFarrow Oct 18, 2024
5ba319d
quiz-data - Refactor multiple repo creation
EJMFarrow Oct 22, 2024
66d0fdf
quiz-data - Export quiz data when creating multiple repos. Use only o…
EJMFarrow Oct 22, 2024
b4434b8
quiz-data - First pass at whole course export
EJMFarrow Nov 7, 2024
4143720
quiz-data - First pass at import whole course
EJMFarrow Nov 8, 2024
960632d
quiz-data - Refactor
EJMFarrow Nov 11, 2024
752f503
quiz-data - Fix issues with git checking when making a subcall
EJMFarrow Nov 12, 2024
b97a2c8
quiz-data - webservice unit tests
EJMFarrow Nov 13, 2024
0d5724b
quiz-data - Refactor quiet/subcall parameters. Avoid abort prompt on …
EJMFarrow Nov 14, 2024
fe737cb
quiz-data - Move test repo
EJMFarrow Nov 14, 2024
a5e3005
quiz-data - First export quiz unit test
EJMFarrow Nov 14, 2024
377e970
quiz-data - Unit tests for export_quiz
EJMFarrow Nov 19, 2024
ec21d9d
quiz-data - Import quiz unit tests
EJMFarrow Nov 20, 2024
52be5ac
quiz-data - Additional cli_helper tests + fix old tests
EJMFarrow Nov 20, 2024
881585b
quiz-data - Update for deprecation, PHP
EJMFarrow Nov 20, 2024
4cc03b4
quiz-data - CI fixes
EJMFarrow Nov 20, 2024
5139ffe
quiz-data - More deprecation changes
EJMFarrow Nov 20, 2024
f01b9ee
quiz-data - Update quiz import
EJMFarrow Nov 26, 2024
6e6527a
quiz-data - Fix deprecation
EJMFarrow Nov 26, 2024
3ee8160
quiz-data - Code check fixes
EJMFarrow Nov 27, 2024
6418f49
quiz-data - export whole course unit tests
EJMFarrow Nov 28, 2024
4179ce0
quiz-data - Import whole course to new instance
EJMFarrow Nov 29, 2024
699ebf6
quiz-data - Fix all the tests that got broekn along the way
EJMFarrow Dec 2, 2024
a2eb63a
quiz-data - Up postgres for CI
EJMFarrow Dec 2, 2024
abb5d9a
quiz-data - Fix DB issue
EJMFarrow Dec 2, 2024
52d5d47
quiz-data - Fix defaults
EJMFarrow Dec 3, 2024
c11076c
quiz-data - Update documentation
EJMFarrow Dec 3, 2024
529adb1
quiz-data - Bug fixes
EJMFarrow Dec 4, 2024
275d1ad
quiz-data - fix ignore
EJMFarrow Dec 4, 2024
297d494
quiz-data - Make quiz export easier
EJMFarrow Dec 5, 2024
4a192d1
quiz-data - Make import quiz easier. Not quite functioning - need to …
EJMFarrow Dec 5, 2024
d481799
quiz-data - Import whole quiz
EJMFarrow Dec 9, 2024
df2a822
quiz-data - Update docs and tests
EJMFarrow Dec 9, 2024
fc351ea
quiz-data - Code check
EJMFarrow Dec 9, 2024
96f7669
quiz-data - Fix directory paths
EJMFarrow Dec 9, 2024
42d99fc
quiz-data - Fix whole import
EJMFarrow Dec 9, 2024
c93a91b
quiz-data - Make quiz import/export easier. Catch Moodle instance mis…
EJMFarrow Dec 10, 2024
c4905d6
quiz-data - Fix tests
EJMFarrow Dec 10, 2024
4a36db1
quiz-data - Update documents
EJMFarrow Dec 10, 2024
7f0a327
quiz-data - Docs, more filepath fixes
EJMFarrow Dec 10, 2024
ede7681
quiz-data - Up version, code check
EJMFarrow Dec 10, 2024
e61b047
quiz-data - Catch empty argument
EJMFarrow Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

services:
postgres:
image: postgres:13
image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -32,7 +32,16 @@ jobs:
matrix: # I don't know why, but mariadb is much slower, so mostly use pgsql.
include:
- php: '8.2'
moodle-branch: 'master'
moodle-branch: 'main'
database: 'pgsql'
- php: '8.2'
moodle-branch: 'MOODLE_405_STABLE'
database: 'pgsql'
- php: '8.2'
moodle-branch: 'MOODLE_404_STABLE'
database: 'pgsql'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
- php: '8.1'
moodle-branch: 'MOODLE_402_STABLE'
Expand Down
158 changes: 105 additions & 53 deletions classes/cli_helper.php

Large diffs are not rendered by default.

125 changes: 115 additions & 10 deletions classes/create_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ class create_repo {
* @var string
*/
public string $manifestpath;
/**
* Path to actual manifest file.
*
* @var string|null
*/
public ?string $nonquizmanifestpath;
/**
* Path to temporary manifest file.
*
Expand All @@ -109,6 +115,12 @@ class create_repo {
* @var string
*/
public string $moodleurl;
/**
* Are we using git?.
* Set in config. Adds commit hash to manifest.
* @var bool
*/
public bool $usegit;

/**
* Constructor.
Expand All @@ -121,11 +133,19 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
// (Moodle code rules don't allow 'extract()').
$arguments = $clihelper->get_arguments();
$moodleinstance = $arguments['moodleinstance'];
$this->usegit = $arguments['usegit'];
if ($arguments['directory']) {
$this->directory = $arguments['rootdirectory'] . '/' . $arguments['directory'];
$this->directory = ($arguments['rootdirectory']) ?
$arguments['rootdirectory'] . '/' . $arguments['directory'] : $arguments['directory'];
} else {
$this->directory = $arguments['rootdirectory'];
}
if (!empty($arguments['nonquizmanifestpath'])) {
$this->nonquizmanifestpath = ($arguments['rootdirectory']) ?
$arguments['rootdirectory'] . '/' . $arguments['nonquizmanifestpath'] : $arguments['nonquizmanifestpath'];
} else {
$this->nonquizmanifestpath = null;
}
$this->subcategory = ($arguments['subcategory']) ? $arguments['subcategory'] : 'top';
if (is_array($arguments['token'])) {
$token = $arguments['token'][$moodleinstance];
Expand All @@ -134,8 +154,8 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
}
$contextlevel = $arguments['contextlevel'];
$coursename = $arguments['coursename'];
$modulename = $arguments['modulename'];
$coursecategory = $arguments['coursecategory'];
$modulename = (isset($arguments['modulename'])) ? $arguments['modulename'] : null;
$coursecategory = (isset($arguments['coursecategory'])) ? $arguments['coursecategory'] : null;
$qcategoryid = $arguments['qcategoryid'];
$instanceid = $arguments['instanceid'];
$this->ignorecat = $arguments['ignorecat'];
Expand Down Expand Up @@ -197,6 +217,18 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
$this->tempfilepath = str_replace(cli_helper::MANIFEST_FILE,
'_export' . cli_helper::TEMP_MANIFEST_FILE,
$this->manifestpath);
$this->manifestcontents = new \stdClass();
$this->manifestcontents->context = new \stdClass();
$this->manifestcontents->context->contextlevel = cli_helper::get_context_level($instanceinfo->contextinfo->contextlevel);
$this->manifestcontents->context->coursename = $instanceinfo->contextinfo->coursename;
$this->manifestcontents->context->modulename = $instanceinfo->contextinfo->modulename;
$this->manifestcontents->context->coursecategory = $instanceinfo->contextinfo->categoryname;
$this->manifestcontents->context->instanceid = $instanceinfo->contextinfo->instanceid;
$this->manifestcontents->context->defaultsubcategoryid = $this->qcategoryid;
$this->manifestcontents->context->defaultsubdirectory = null;
$this->manifestcontents->context->defaultignorecat = $this->ignorecat;
$this->manifestcontents->context->moodleurl = $this->moodleurl;
$this->manifestcontents->questions = [];
}

/**
Expand All @@ -205,14 +237,11 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
*
* @return void
*/
public function process():void {
$this->manifestcontents = new \stdClass();
$this->manifestcontents->context = null;
$this->manifestcontents->questions = [];
public function process(): void {
$this->export_to_repo();
$this->manifestcontents->context->defaultsubdirectory = $this->subdirectory;
cli_helper::create_manifest_file($this->manifestcontents, $this->tempfilepath,
$this->manifestpath, $this->moodleurl,
$this->qcategoryid, $this->subdirectory, false);
$this->manifestpath, false);
unlink($this->tempfilepath);
}

Expand All @@ -222,7 +251,83 @@ public function process():void {
* @param string $wsurl webservice URL
* @return curl_request
*/
public function get_curl_request($wsurl):curl_request {
public function get_curl_request($wsurl): curl_request {
return new \qbank_gitsync\curl_request($wsurl);
}

/**
* Create quiz directories and populate.
* @param object $clihelper
* @param string $scriptdirectory - directory of CLI scripts
* @return void
*/
public function create_quiz_directories(object $clihelper, string $scriptdirectory): void {
$contextinfo = $clihelper->check_context($this, false, true);
$arguments = $clihelper->get_arguments();
if ($arguments['directory']) {
$basedirectory = $arguments['rootdirectory'] . '/' . $arguments['directory'];
} else {
$basedirectory = $arguments['rootdirectory'];
}
$moodleinstance = $arguments['moodleinstance'];
$instanceid = $arguments['instanceid'];
if (is_array($arguments['token'])) {
$token = $arguments['token'][$moodleinstance];
} else {
$token = $arguments['token'];
}
$ignorecat = $arguments['ignorecat'];
$ignorecat = ($ignorecat) ? ' -x "' . $ignorecat . '"' : '';
$quizlocations = [];
foreach ($contextinfo->quizzes as $quiz) {
$instanceid = $quiz->instanceid;
$quizdirectory = cli_helper::get_quiz_directory($basedirectory, $quiz->name);
$rootdirectory = $clihelper->create_directory($quizdirectory);
echo "\nExporting quiz: {$quiz->name} to {$rootdirectory}\n";
$output = $this->call_repo_creation($rootdirectory, $moodleinstance, $instanceid, $token, $ignorecat, $scriptdirectory);
echo $output;
$quizmanifestpath = cli_helper::get_manifest_path($moodleinstance, 'module', null,
$contextinfo->contextinfo->coursename, $quiz->name, $rootdirectory);
$output = $this->call_export_quiz($moodleinstance, $token, $quizmanifestpath,
$this->manifestpath, $scriptdirectory);
$quizlocation = new \StdClass();
$quizlocation->moduleid = $instanceid;
$quizlocation->directory = basename($rootdirectory);
$quizlocations[] = $quizlocation;
$this->manifestcontents->quizzes = $quizlocations;
$success = file_put_contents($this->manifestpath, json_encode($this->manifestcontents));
if ($success === false) {
echo "\nUnable to update manifest file: {$this->manifestpath}\n Aborting.\n";
exit();
}
echo $output;
}
if ($arguments['usegit'] && empty($arguments['subcall'])) {
// Commit the final quiz file.
// The others are committed by the following createrepo.
chdir($basedirectory);
exec("git add --all");
exec('git commit -m "Initial Commit - final update"');
}
}

/**
* Separate out exec call for mocking.
*
* @param string $rootdirectory
* @param string $moodleinstance
* @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,
string $token, string $ignorecat, string $scriptdirectory
): ?string {
chdir($scriptdirectory);
return shell_exec('php createrepo.php -u ' . $this->usegit . ' -w -r "' .
$rootdirectory . '" -i "' . $moodleinstance .
'" -l "module" -n ' . $instanceid . ' -t ' . $token . $ignorecat);
}
}
Loading
Loading