Issue Details (XML | Word | Printable)

Key: MDL-17524
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Pierre Pichet
Reporter: Pierre Pichet
Votes: 0
Watchers: 0
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Deleting a calculated question delete datasetdefinitions shared by other question

Created: 05/Dec/08 12:48 AM   Updated: 09/Dec/08 07:06 PM
Component/s: Questions
Affects Version/s: 1.6.8
Fix Version/s: 1.6.9, 1.7.7, 1.8.8, 1.9.4

Participants: Pierre Pichet and Tim Hunt
Security Level: None
QA Assignee: Tim Hunt
Resolved date: 05/Dec/08
Affected Branches: MOODLE_16_STABLE
Fixed Branches: MOODLE_16_STABLE, MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE


 Description  « Hide
the delete function delete all datasetdefiniton used by this question without testing if they are shared by other questions.
        if ($datasets = get_records('question_datasets', 'question', $questionid)) {
            foreach ($datasets as $dataset) {
                delete_records('question_dataset_definitions', 'id', $dataset->datasetdefinition);
                delete_records('question_dataset_items', 'definition', $dataset->datasetdefinition);
            }
        }

changing this in HEAD to
        if ($datasets = $DB->get_records('question_datasets', array('question' => $questionid))) {
            foreach ($datasets as $dataset) {
                if (!$DB->get_records_select( // no other questions sharing this datasetdefinition
                        'question_datasets',
                        "question != ?
                        AND datasetdefinition = ?;", array($questionid, $dataset->datasetdefinition))){
                    $DB->delete_records('question_dataset_definitions', array('id' => $dataset->datasetdefinition));
                    $DB->delete_records('question_dataset_items', array('definition' => $dataset->datasetdefinition));
                }
            }
        }
solve the problem.
will merge down to 1.6
We can conclude that either shared datasetdefinition are not so often used or that such calculated questions are too precious to be deleted ...


 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Pierre Pichet added a comment - 05/Dec/08 01:31 AM
for 1.9 and older version this becomes
+ if (! get_records_select(
+ 'question_datasets',
+ "question != $questionid
+ AND datasetdefinition = $dataset->datasetdefinition;")){ + delete_records('question_dataset_definitions', 'id', $dataset->datasetdefinition); + delete_records('question_dataset_items', 'definition', $dataset->datasetdefinition); + }

Pierre Pichet added a comment - 05/Dec/08 02:24 AM
Just hope that I set fix versions correctly...

Tim Hunt added a comment - 09/Dec/08 07:06 PM
Looks good.