MDL-65978 blog: Fix removing associations
This commit is contained in:
+18
-11
@@ -150,22 +150,29 @@ class update_entry extends external_api {
|
||||
$context = context_system::instance();
|
||||
|
||||
// Validate course association. We need to convert the course id to context.
|
||||
if (!empty($entrydata->courseassoc)) {
|
||||
$coursecontext = context_course::instance($entrydata->courseassoc);
|
||||
if (isset($entrydata->courseassoc)) {
|
||||
$entrydata->courseid = $entrydata->courseassoc;
|
||||
$entrydata->courseassoc = $coursecontext->id; // Convert to context.
|
||||
$context = $coursecontext;
|
||||
|
||||
if (!empty($entrydata->courseid)) {
|
||||
$coursecontext = context_course::instance($entrydata->courseassoc);
|
||||
|
||||
$entrydata->courseassoc = $coursecontext->id; // Convert to context.
|
||||
$context = $coursecontext;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate mod association.
|
||||
if (!empty($entrydata->modassoc)) {
|
||||
$modcontext = context_module::instance($entrydata->modassoc);
|
||||
if (!empty($coursecontext) && $coursecontext->id != $modcontext->get_course_context(true)->id) {
|
||||
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'modassoc');
|
||||
}
|
||||
if (isset($entrydata->modassoc)) {
|
||||
$entrydata->coursemoduleid = $entrydata->modassoc;
|
||||
$entrydata->modassoc = $modcontext->id; // Convert to context.
|
||||
$context = $modcontext;
|
||||
|
||||
if (!empty($entrydata->coursemoduleid)) {
|
||||
$modcontext = context_module::instance($entrydata->modassoc);
|
||||
if (!empty($coursecontext) && $coursecontext->id != $modcontext->get_course_context(true)->id) {
|
||||
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'modassoc');
|
||||
}
|
||||
$entrydata->modassoc = $modcontext->id; // Convert to context.
|
||||
$context = $modcontext;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate context. It might be upated because of the new association.
|
||||
|
||||
+20
@@ -1086,6 +1086,26 @@ class external_test extends \externallib_advanced_testcase {
|
||||
$this->assertEquals($newattachfilename, $entry['attachmentfiles'][0]['filename']);
|
||||
}
|
||||
}
|
||||
|
||||
// Update removing associations.
|
||||
$options = [
|
||||
['name' => 'courseassoc', 'value' => 0],
|
||||
['name' => 'modassoc', 'value' => 0],
|
||||
];
|
||||
|
||||
$result = update_entry::execute($entryid, $subject, $summary, FORMAT_HTML, $options);
|
||||
$result = external_api::clean_returnvalue(update_entry::execute_returns(), $result);
|
||||
|
||||
// Retrieve files via WS.
|
||||
$result = \core_blog\external::get_entries();
|
||||
$result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
|
||||
|
||||
foreach ($result['entries'] as $entry) {
|
||||
if ($entry['id'] == $entryid) {
|
||||
$this->assertEmpty($entry['courseid']);
|
||||
$this->assertEmpty($entry['coursemoduleid']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user