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

Images get lost when moving question to other context #98

Open
PhilippImhof opened this issue May 24, 2023 · 2 comments
Open

Images get lost when moving question to other context #98

PhilippImhof opened this issue May 24, 2023 · 2 comments
Assignees
Labels
Milestone

Comments

@PhilippImhof
Copy link
Collaborator

Description of bug / unexpected behavior

When a question is moved from one context to another, images that are embedded in the part's text get lost.

Expected behavior

The images should still be there, obviously.

How to reproduce the issue

  1. Create a new question. Embed an image in the text of part 1. Save the question. Preview the question to verify the image is there.
  2. Move the question to another course. (Moving it to a different category of the same course is not enough.)
  3. Preview the question again. The image is not there anymore.

The same happens for files embedded in parts' feedback texts.

Additional comments

When moving the files, we use the $questionid:

public function move_files($questionid, $oldcontextid, $newcontextid) {
$fs = get_file_storage();
parent::move_files($questionid, $oldcontextid, $newcontextid);
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_formulas', 'answersubqtext', $questionid);
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_formulas', 'answerfeedback', $questionid);
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_formulas', 'partcorrectfb', $questionid);
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_formulas', 'partpartiallycorrectfb', $questionid);
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_formulas', 'partincorrectfb', $questionid);
$this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}

However, when saving the question, we use $ans->id which is the part's ID.

$ans->subqtext = $this->import_or_save_files($subqtextarr, $context, 'qtype_formulas', 'answersubqtext', $ans->id);

@PhilippImhof PhilippImhof self-assigned this May 24, 2023
@PhilippImhof
Copy link
Collaborator Author

This will be fixed with #62.

@PhilippImhof
Copy link
Collaborator Author

As a side effect, this means that uploaded files (embedded in parts) will not be removed when the question is deleted.

@PhilippImhof PhilippImhof added this to the 6.0.0 milestone Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant