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

Merge dev into main #50

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions classes/cli_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ public function validate_and_clean_args(): void {
}
}
if (isset($cliargs['ignorecat'])) {
// Allow escaping of forward slash at start in Windows.
if (strlen($cliargs['ignorecat']) > 1 && substr($cliargs['ignorecat'], 0, 2) === '//') {
$cliargs['ignorecat'] = substr($cliargs['ignorecat'], 1);
}
if (@preg_match($cliargs['ignorecat'], 'zzzzzzzz') === false) {
echo "\nThere is a problem with your regular expression for ignoring categories:\n";
echo error_get_last()["message"] . "\n";
Expand Down
2 changes: 1 addition & 1 deletion cli/createrepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
[
'longopt' => 'ignorecat',
'shortopt' => 'x',
'description' => 'Regex of categories to ignore',
'description' => 'Regex of categories to ignore - add an extra leading / for Windows.',
'default' => $ignorecat,
'variable' => 'ignorecat',
'valuerequired' => true,
Expand Down
2 changes: 1 addition & 1 deletion cli/deletefrommoodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
[
'longopt' => 'ignorecat',
'shortopt' => 'x',
'description' => 'Regex of categories to ignore',
'description' => 'Regex of categories to ignore - add an extra leading / for Windows.',
'default' => $ignorecat,
'variable' => 'ignorecat',
'valuerequired' => true,
Expand Down
2 changes: 1 addition & 1 deletion cli/exportrepofrommoodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
[
'longopt' => 'ignorecat',
'shortopt' => 'x',
'description' => 'Regex of categories to ignore',
'description' => 'Regex of categories to ignore - add an extra leading / for Windows.',
'default' => $ignorecat,
'variable' => 'ignorecat',
'valuerequired' => true,
Expand Down
2 changes: 1 addition & 1 deletion cli/importrepotomoodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
[
'longopt' => 'ignorecat',
'shortopt' => 'x',
'description' => 'Regex of categories to ignore',
'description' => 'Regex of categories to ignore - add an extra leading / for Windows.',
'default' => $ignorecat,
'variable' => 'ignorecat',
'valuerequired' => true,
Expand Down
2 changes: 1 addition & 1 deletion doc/createrepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
|n|instanceid|Numerical id of the course, module of course category.
|t|token|Security token for webservice.
|h|help|
|x|ignorecat|Regex of categories to ignore
|x|ignorecat|Regex of categories to ignore - add an extra leading / for Windows.

### Example 1:

Expand Down
2 changes: 1 addition & 1 deletion doc/deletefrommoodle.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
|n|instanceid|Numerical id of the course, module of course category.
|t|token|Security token for webservice.
|h|help|
|x|ignorecat|Regex of categories to ignore
|x|ignorecat|Regex of categories to ignore - add an extra leading / for Windows.

Examples:

Expand Down
2 changes: 1 addition & 1 deletion doc/exportrepofrommoodle.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
|q|questioncategoryid|Numerical id of subcategory to actually export.
|t|token|Security token for webservice.|
|h|help|
|x|ignorecat|Regex of categories to ignore
|x|ignorecat|Regex of categories to ignore - add an extra leading / for Windows.

Examples:

Expand Down
2 changes: 1 addition & 1 deletion doc/importrepotomoodle.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Commit this update.
|n|instanceid|Numerical id of the course, module of course category.
|t|token|Security token for webservice.
|h|help|
|x|ignorecat|Regex of categories to ignore
|x|ignorecat|Regex of categories to ignore - add an extra leading / for Windows.

Examples:

Expand Down
2 changes: 1 addition & 1 deletion doc/usinggit.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You can use context instance id and subcategory id instead:
* `-n` the context instance id, which is the course id in this case.
* `-q` the question category id

You can also ignore certain categories (and their descendants) using `-x` and a regex expression to match the category name(s) within Moodle.
You can also ignore certain categories (and their descendants) using `-x` and a regex expression to match the category name(s) within Moodle. (Add an extra leading / in Windows e.g. "//^.*DO_NOT_SHARE$/".)

`php createrepo.php -l course -n 2 -d "master" -q 80 -x "/^.*DO_NOT_SHARE$/"`

Expand Down
13 changes: 13 additions & 0 deletions tests/cli_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ public function test_validation_ignorecat(): void {
$helper->processedoptions = ['token' => 'X', 'manifestpath' => 'path/subpath', 'ignorecat' => '/hello/'];
$helper->validate_and_clean_args();
$this->expectOutputString('');
$this->assertEquals('/hello/', $helper->processedoptions['ignorecat']);
}

/**
Expand All @@ -516,4 +517,16 @@ public function test_validation_ignorecat_error(): void {
@$helper->validate_and_clean_args();
$this->expectOutputRegex('/problem with your regular expression/');
}

/**
* Validation
* @covers \gitsync\cli_helper\validate_and_clean_args()
*/
public function test_validation_ignorecat_replace(): void {
$helper = new fake_cli_helper([]);
$helper->processedoptions = ['token' => 'X', 'manifestpath' => 'path/subpath', 'ignorecat' => '//hello\//'];
$helper->validate_and_clean_args();
$this->expectOutputString('');
$this->assertEquals('/hello\//', $helper->processedoptions['ignorecat']);
}
}
Loading