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

[1.21] role-import: moosh prevents importing roles with an empty archetype tag or without an archetype tag #472

Closed
danowar2k opened this issue May 14, 2024 · 3 comments

Comments

@danowar2k
Copy link
Contributor

  • moosh version: 1.21
  • moodle version: 4.1.6
    • database: postgres
  • php version: 7.4.33
  • operating system: Solaris

Actual behaviour

Given a role at /path/to/roleNoArchetype.xml which contains the following empty archetype tag:

	<archetype/>

moosh import -f /path/to/roleNoArchetype.xml outputs

XML data defines an unknown archetype ''.

Moodle itself lets the admin import the role without any errors.

Expected behaviour

moosh should import the role without errors, just like Moodle does.

Steps to reproduce

  • Create a Moodle role file with an empty archetype tag
  • Try to import the role to Moodle with moosh
@danowar2k
Copy link
Contributor Author

Additional notes: moosh does import the role if it has no archetype tag at all. The role XML schema for Moodle allows the tag to not occur at all, see https://github.com/moodle/moodle/blob/462d5f04a8fea5e2aaa7911cc700f90d54b8a73b/admin/roles/role_schema.xml#L9.

The possible solution would be to replace the lines at

$archetype = $importData['archetype'];
$archetypes = get_role_archetypes();
if (!isset($archetypes[$archetype])) {
$this->exitError(sprintf('XML data defines an unknown archetype \'%s\'.', $archetype));
}

with

        $archetype = $importData['archetype'];
        if ($archetype) {
           $archetypes = get_role_archetypes();
           if (!isset($archetypes[$archetype])) {
               $this->exitError(sprintf('XML data defines an unknown archetype \'%s\'.', $archetype));
           }
        }

@danowar2k
Copy link
Contributor Author

Just tested a role file without even an empty archetype tag. Sadly it doesn't work either. Moodle's parse_preset functioon stores null in $importData['archetype']. You don't even check if there is any real value for the assoc array value (not even for null). So as long as your role doesn't have an existing of the 8 Moodle archetypes, you currently can't import role XML files with moosh.

@danowar2k danowar2k changed the title [1.21] role-import: Moodle lets user import role with empty archetype tag, but moosh doesn't [1.21] role-import: Moodle lets user import role with no archetype, but moosh doesn't May 14, 2024
@danowar2k
Copy link
Contributor Author

Probably solved by #473

@danowar2k danowar2k changed the title [1.21] role-import: Moodle lets user import role with no archetype, but moosh doesn't [1.21] role-import: moosh doesn't let import role with an empty archetype tag or without an archetype tag May 14, 2024
@danowar2k danowar2k changed the title [1.21] role-import: moosh doesn't let import role with an empty archetype tag or without an archetype tag [1.21] role-import: moosh doesn't let import roles with an empty archetype tag or without an archetype tag May 14, 2024
@danowar2k danowar2k changed the title [1.21] role-import: moosh doesn't let import roles with an empty archetype tag or without an archetype tag [1.21] role-import: moosh prevents importing roles with an empty archetype tag or without an archetype tag May 14, 2024
@tmuras tmuras closed this as completed May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants