MDL-68526 core_contentbank: Delete content when a course is deleted

Or when a course category is moved/deleted
This commit is contained in:
Amaia Anabitarte
2020-05-18 16:05:04 +02:00
parent d85118369d
commit f2a9bb6edb
6 changed files with 130 additions and 6 deletions
+33
View File
@@ -146,6 +146,39 @@ abstract class content {
return $this->content->name;
}
/**
* Set a new contextid to the content.
*
* @param int $contextid The new contextid of the content.
* @return bool True if the content has been succesfully updated. False otherwise.
*/
public function set_contextid(int $contextid): bool {
if ($this->content->contextid == $contextid) {
return true;
}
$oldcontextid = $this->content->contextid;
$this->content->contextid = $contextid;
$updated = $this->update_content();
if ($updated) {
// Move files to new context
$fs = get_file_storage();
$fs->move_area_files_to_new_context($oldcontextid, $contextid, 'contentbank', 'public', $this->content->id);
} else {
$this->content->contextid = $oldcontextid;
}
return $updated;
}
/**
* Returns the contextid of the content.
*
* @return int The id of the content context.
*/
public function get_contextid(): string {
return $this->content->contextid;
}
/**
* Returns the content ID.
*