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

Cannot import activities between two courses using the Grid format #169

Closed
jboulen opened this issue Sep 28, 2022 · 11 comments
Closed

Cannot import activities between two courses using the Grid format #169

jboulen opened this issue Sep 28, 2022 · 11 comments
Assignees

Comments

@jboulen
Copy link

jboulen commented Sep 28, 2022

environment :
moodle v4.0.4
grid 400.1.1
debian 11 (php 7.4 / mysql)

steps to reproduce :

  1. create two courses and use grid format
  2. define images on each sections
  3. create an activity in the first course
  4. go to the second course and use "import" or "course reuse" in course administration
  5. select first course, and then "jump to final step"
  6. an error should occur

grid-error
grid-debug_info
grid-stack_trace

workaround :
We can add this line in a try/catch to avoid the error. The import works, but maybe there is a side effect to ignore this exception...

@gjb2048
Copy link
Collaborator

gjb2048 commented Sep 28, 2022

@jboulen Q - on your system is '3' the course id of the new course?

@jboulen
Copy link
Author

jboulen commented Sep 28, 2022

my first course has id '2', general section id is '1', section 1 id is '2'.
my second course has id '3', general section id is '3', section 1 id is '4'.

@gjb2048
Copy link
Collaborator

gjb2048 commented Sep 28, 2022

@jboulen Interesting, thanks.

@gjb2048
Copy link
Collaborator

gjb2048 commented Sep 28, 2022

@jboulen Q, if you remove the lines 228 - 234 in /course/format/grid/backup/moodle2/restore_format_grid_plugin.class.php being:

            $newimagecontainer = new \stdClass();
            $newimagecontainer->sectionid = $newsectionid;
            $newimagecontainer->courseid = $courseid;
            $newimagecontainer->image = $data->image;
            $newimagecontainer->contenthash = $data->contenthash;
            $newimagecontainer->displayedimagestate = 0;
            $newid = $DB->insert_record('format_grid_image', $newimagecontainer, true);

then does the issue happen? As I'm now suspecting that:

            $oldsectionid = $data->sectionid;
            $this->set_mapping('gridimage', $oldsectionid, $newsectionid, true);
            $this->add_related_files('format_grid', 'sectionimage', 'gridimage');

above it could already be adding the records... to the gridimage table.

@jboulen
Copy link
Author

jboulen commented Sep 28, 2022

Without this lines, the issue does not happen :
grid-success

(and activities have been correctly imported)

@gjb2048
Copy link
Collaborator

gjb2048 commented Sep 28, 2022

@jboulen And does the image show please?

@gjb2048
Copy link
Collaborator

gjb2048 commented Sep 28, 2022

Ok, solution breaks course duplication.

@gjb2048 gjb2048 changed the title cannot import activities between 2 courses using Grid format Cannot import activities between two courses using Grid format Sep 28, 2022
@gjb2048 gjb2048 changed the title Cannot import activities between two courses using Grid format Cannot import activities between two courses using the Grid format Sep 28, 2022
@gjb2048
Copy link
Collaborator

gjb2048 commented Sep 28, 2022

@jboulen
Copy link
Author

jboulen commented Sep 29, 2022

@jboulen And does the image show please?

The original image for the second course has been preserved. However, when you edit section, there are two images in section image field (the original image and image used by the first course).

@jboulen
Copy link
Author

jboulen commented Sep 29, 2022

@jboulen Please test 4769e4b - you can do a drop in replacement for https://raw.githubusercontent.com/gjb2048/moodle-format_grid/4769e4b9e48ca685a96961c311ea3ed06b5ae7bc/backup/moodle2/restore_format_grid_plugin.class.php.

It works. Activities have been correctly imported and there is only one image in section image field when you edit section.

The section image in second course has been preserved. I think this is the desired behavior. It would probably be strange if the first course image was imported ?

Thank you very much.

@gjb2048
Copy link
Collaborator

gjb2048 commented Sep 29, 2022

@jboulen Thanks for letting me know. I looked at all my test courses that I created for this and couldn't see a second image.

Logically perhaps it would make sense for the first course image to overwrite the second, but then the intent of the action is the content of the course and the image is a display thing. But as this is not a clear answer as some people will want the image overwritten and others not, then I'm going to leave as is. To overwrite the image will lead to even more complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants