diff --git a/classes/cli_helper.php b/classes/cli_helper.php index edb0fb7..db2f2a6 100644 --- a/classes/cli_helper.php +++ b/classes/cli_helper.php @@ -139,6 +139,10 @@ public function parse_options(): array { */ public function validate_and_clean_args(): void { $cliargs = $this->processedoptions; + if (!isset($cliargs['usegit'])) { + echo "\nAre you using Git? You will need to specify true or false for --usegit.\n"; + static::call_exit(); + } if (!isset($cliargs['token'])) { echo "\nYou will need a security token (--token).\n"; static::call_exit(); @@ -328,6 +332,10 @@ public function prioritise_options($commandlineargs): array { } else { $variables[$variablename] = $option['default']; } + if (in_array($variablename, ['usegit'])) { + $variables[$variablename] = ($variables[$variablename] === 'true') ? true : $variables[$variablename]; + $variables[$variablename] = ($variables[$variablename] === 'false') ? false : $variables[$variablename]; + } } else { if (isset($commandlineargs[$option['longopt']]) || isset($commandlineargs[$option['shortopt']])) { $variables[$variablename] = true; @@ -562,8 +570,10 @@ public function commit_hash_setup(object $activity):void { $this->create_gitignore($activity->manifestpath); $manifestdirname = dirname($activity->manifestpath); chdir($manifestdirname); - exec("git add --all"); - exec('git commit -m "Initial Commit - ' . basename($activity->manifestpath) . '"'); + if (!(isset($this->get_arguments()['subcall']) && $this->get_arguments()['subcall'])) { + exec("git add --all"); + exec('git commit -m "Initial Commit - ' . basename($activity->manifestpath) . '"'); + } foreach ($activity->manifestcontents->questions as $question) { $commithash = exec('git log -n 1 --pretty=format:%H -- "' . substr($question->filepath, 1) . '"'); if ($commithash) { @@ -672,7 +682,7 @@ public function create_directory(string $directory):string { * @return void */ public function check_for_changes($fullmanifestpath) { - if (!$this->get_arguments()['usegit']) { + if (!$this->get_arguments()['usegit'] || (isset($this->get_arguments()['subcall']) && $this->get_arguments()['subcall'])) { return; } $this->check_repo_initialised($fullmanifestpath); diff --git a/classes/create_repo.php b/classes/create_repo.php index 3dec25d..1f5f8aa 100644 --- a/classes/create_repo.php +++ b/classes/create_repo.php @@ -261,7 +261,7 @@ public function create_quiz_directories($clihelper, $scriptdirectory) { $rootdirectory = $clihelper->create_directory($quizdirectory); echo "\nExporting quiz: {$quiz->name} to {$rootdirectory}\n"; chdir($scriptdirectory); - $output = shell_exec('php createrepo.php -r "' . $rootdirectory . '" -i "' . $moodleinstance . '" -l "module" -n ' . $instanceid . ' -t ' . $token . ' -z' . $ignorecat); + $output = shell_exec('php createrepo.php -z -r "' . $rootdirectory . '" -i "' . $moodleinstance . '" -l "module" -n ' . $instanceid . ' -t ' . $token . ' -x ' . $ignorecat); echo $output; $quizmanifestname = cli_helper::get_manifest_path($moodleinstance, 'module', null, $contextinfo->contextinfo->coursename, $quiz->name, $rootdirectory); @@ -279,7 +279,7 @@ public function create_quiz_directories($clihelper, $scriptdirectory) { } echo $output; } - if ($arguments['usegit']) { + if ($arguments['usegit'] && !(isset($arguments()['subcall']) && $arguments()['subcall'])) { // Commit the final quiz file. // The others are committed by the following createrepo. chdir($basedirectory); diff --git a/classes/export_repo.php b/classes/export_repo.php index ff5181b..ed77ad5 100644 --- a/classes/export_repo.php +++ b/classes/export_repo.php @@ -308,32 +308,34 @@ public function update_quiz_directories($clihelper, $scriptdirectory) { $instanceid = (int) $quiz->instanceid; if (!isset($locarray[$instanceid]) || !is_dir(dirname($basedirectory) . '/' . $locarray[$instanceid]->directory)) { $rootdirectory = $clihelper->create_directory(cli_helper::get_quiz_directory($basedirectory, $quiz->name)); - $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(); + if (!isset($locarray[$instanceid])) { + $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 "\nExporting quiz: {$quiz->name} to {$rootdirectory}\n"; chdir($scriptdirectory); - $output = shell_exec('php createrepo.php -r "' . $rootdirectory . '" -i "' . $moodleinstance . '" -l "module" -n ' . $instanceid . ' -t ' . $token . ' -z' . $ignorecat); + $output = shell_exec('php createrepo.php -w -z -r "' . $rootdirectory . '" -i "' . $moodleinstance . '" -l "module" -n ' . $instanceid . ' -t ' . $token . ' -x ' . $ignorecat); } else { $rootdirectory = dirname($basedirectory) . '/' . $locarray[$instanceid]->directory; echo "\nExporting quiz: {$quiz->name} to {$rootdirectory}\n"; chdir($scriptdirectory); $quizmanifestname = cli_helper::get_manifest_path($moodleinstance, 'module', null, $contextinfo->contextinfo->coursename, $quiz->name, ''); - $output = shell_exec('php exportrepofrommoodle.php -z -r "' . $rootdirectory . '" -i "' . $moodleinstance . '" -f "' . $quizmanifestname . '" -t ' . $token); + $output = shell_exec('php exportrepofrommoodle.php -w -z -r "' . $rootdirectory . '" -i "' . $moodleinstance . '" -f "' . $quizmanifestname . '" -t ' . $token); } echo $output; $quizmanifestname = cli_helper::get_manifest_path($moodleinstance, 'module', null, $contextinfo->contextinfo->coursename, $quiz->name, $rootdirectory); chdir($scriptdirectory); - $output = shell_exec('php exportquizstructurefrommoodle.php -z -r "" -i "' . $moodleinstance . '" -n ' . $instanceid . ' -t ' . $token. ' -p "' . $this->manifestpath. '" -f "' . $quizmanifestname . '"'); + $output = shell_exec('php exportquizstructurefrommoodle.php -w -z -r "" -i "' . $moodleinstance . '" -n ' . $instanceid . ' -t ' . $token. ' -p "' . $this->manifestpath. '" -f "' . $quizmanifestname . '"'); echo $output; } } diff --git a/classes/import_repo.php b/classes/import_repo.php index c1721d5..e7ddae0 100644 --- a/classes/import_repo.php +++ b/classes/import_repo.php @@ -900,14 +900,14 @@ public function update_quizzes($clihelper, $scriptdirectory) { if (is_dir($rootdirectory . '/top')) { // Quiz could have no questions in its context. echo "\nImporting quiz context: {$structurecontents->quiz->name}\n"; - $output = shell_exec('php importrepotomoodle.php -z -r "' . $rootdirectory . + $output = shell_exec('php importrepotomoodle.php -w -z -r "' . $rootdirectory . '" -i "' . $moodleinstance . '" -f "' . $quizmanifestname . '" -t ' . $token); echo $output; } if ($instanceid === false) { chdir($scriptdirectory); echo "\nImporting quiz structure: {$structurecontents->quiz->name}\n"; - $output = shell_exec('php importquizstructuretomoodle.php -z -r "" -i "' . $moodleinstance . '" -n ' . + $output = shell_exec('php importquizstructuretomoodle.php -w -z -r "" -i "' . $moodleinstance . '" -n ' . $contextinfo->contextinfo->instanceid . ' -t ' . $token. ' -p "' . $this->manifestpath. '" -f "' . $quizmanifestname . '" -a "' . $structurefile . '"'); echo $output; diff --git a/cli/createrepo.php b/cli/createrepo.php index 30c230d..a1790b2 100755 --- a/cli/createrepo.php +++ b/cli/createrepo.php @@ -137,7 +137,7 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', - 'valuerequired' => false, + 'valuerequired' => true, ], [ 'longopt' => 'ignorecat', @@ -155,6 +155,15 @@ 'variable' => 'quiet', 'valuerequired' => false, ], + [ + 'longopt' => 'subcall', + 'shortopt' => 'w', + 'description' => 'Is this a subcall of the script?', + 'default' => false, + 'variable' => 'subcall', + 'valuerequired' => false, + 'hidden' => true, + ], ]; if (!function_exists('simplexml_load_file')) { diff --git a/cli/createwholecourserepo.php b/cli/createwholecourserepo.php index 3fbccff..73c9735 100755 --- a/cli/createwholecourserepo.php +++ b/cli/createwholecourserepo.php @@ -125,7 +125,7 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', - 'valuerequired' => false, + 'valuerequired' => true, ], [ 'longopt' => 'ignorecat', diff --git a/cli/deletefrommoodle.php b/cli/deletefrommoodle.php index 77d50d3..72b84e3 100755 --- a/cli/deletefrommoodle.php +++ b/cli/deletefrommoodle.php @@ -135,7 +135,7 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', - 'valuerequired' => false, + 'valuerequired' => true, ], [ 'longopt' => 'ignorecat', diff --git a/cli/exportquizstructurefrommoodle.php b/cli/exportquizstructurefrommoodle.php index 156eb82..7c6e784 100644 --- a/cli/exportquizstructurefrommoodle.php +++ b/cli/exportquizstructurefrommoodle.php @@ -85,7 +85,7 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', - 'valuerequired' => false, + 'valuerequired' => true, ], [ 'longopt' => 'modulename', @@ -110,6 +110,15 @@ 'default' => false, 'variable' => 'quiet', 'valuerequired' => false, + ], + [ + 'longopt' => 'subcall', + 'shortopt' => 'w', + 'description' => 'Is this a subcall of the script?', + 'default' => false, + 'variable' => 'subcall', + 'valuerequired' => false, + 'hidden' => true, ] ]; diff --git a/cli/exportrepofrommoodle.php b/cli/exportrepofrommoodle.php index 399362b..ceb5f04 100644 --- a/cli/exportrepofrommoodle.php +++ b/cli/exportrepofrommoodle.php @@ -95,7 +95,7 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', - 'valuerequired' => false, + 'valuerequired' => true, ], [ 'longopt' => 'ignorecat', @@ -113,6 +113,15 @@ 'variable' => 'quiet', 'valuerequired' => false, ], + [ + 'longopt' => 'subcall', + 'shortopt' => 'w', + 'description' => 'Is this a subcall of the script?', + 'default' => false, + 'variable' => 'subcall', + 'valuerequired' => false, + 'hidden' => true, + ], ]; if (!function_exists('simplexml_load_file')) { diff --git a/cli/exportwholecoursefrommoodle.php b/cli/exportwholecoursefrommoodle.php index ea4da8e..20e2956 100644 --- a/cli/exportwholecoursefrommoodle.php +++ b/cli/exportwholecoursefrommoodle.php @@ -95,7 +95,7 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', - 'valuerequired' => false, + 'valuerequired' => true, ], [ 'longopt' => 'ignorecat', diff --git a/cli/importquizstructuretomoodle.php b/cli/importquizstructuretomoodle.php index bb2b829..7323af1 100644 --- a/cli/importquizstructuretomoodle.php +++ b/cli/importquizstructuretomoodle.php @@ -109,8 +109,17 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', + 'valuerequired' => true, + ], + [ + 'longopt' => 'subcall', + 'shortopt' => 'w', + 'description' => 'Is this a subcall of the script?', + 'default' => false, + 'variable' => 'subcall', 'valuerequired' => false, - ] + 'hidden' => true, + ], ]; if (!function_exists('simplexml_load_file')) { diff --git a/cli/importrepotomoodle.php b/cli/importrepotomoodle.php index 2c179c3..a990843 100755 --- a/cli/importrepotomoodle.php +++ b/cli/importrepotomoodle.php @@ -135,7 +135,7 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', - 'valuerequired' => false, + 'valuerequired' => true, ], [ 'longopt' => 'ignorecat', @@ -153,6 +153,15 @@ 'variable' => 'quiet', 'valuerequired' => false, ], + [ + 'longopt' => 'subcall', + 'shortopt' => 'w', + 'description' => 'Is this a subcall of the script?', + 'default' => false, + 'variable' => 'subcall', + 'valuerequired' => false, + 'hidden' => true, + ], ]; if (!function_exists('simplexml_load_file')) { diff --git a/cli/importwholecoursetomoodle.php b/cli/importwholecoursetomoodle.php index 910ec2f..59d65f3 100755 --- a/cli/importwholecoursetomoodle.php +++ b/cli/importwholecoursetomoodle.php @@ -135,7 +135,7 @@ 'description' => 'Is the repo controlled using Git?', 'default' => $usegit, 'variable' => 'usegit', - 'valuerequired' => false, + 'valuerequired' => true, ], [ 'longopt' => 'ignorecat',