Skip to content

Commit

Permalink
MDL-39087 Delete all component files in uninstall_plugin()
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Apr 11, 2013
1 parent 5718a12 commit 546b886
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/adminlib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ function uninstall_plugin($type, $name) {
// remove event handlers and dequeue pending events // remove event handlers and dequeue pending events
events_uninstall($component); events_uninstall($component);


// Delete all remaining files in the filepool owned by the component.
$fs = get_file_storage();
$fs->delete_component_files($component);

// Finally purge all caches. // Finally purge all caches.
purge_all_caches(); purge_all_caches();


Expand Down
15 changes: 15 additions & 0 deletions lib/filestorage/file_storage.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -743,6 +743,21 @@ public function delete_area_files_select($contextid, $component,
$filerecords->close(); $filerecords->close();
} }


/**
* Delete all files associated with the given component.
*
* @param string $component the component owning the file
*/
public function delete_component_files($component) {
global $DB;

$filerecords = $DB->get_recordset('files', array('component' => $component));
foreach ($filerecords as $filerecord) {
$this->get_file_instance($filerecord)->delete();
}
$filerecords->close();
}

/** /**
* Move all the files in a file area from one context to another. * Move all the files in a file area from one context to another.
* *
Expand Down
11 changes: 11 additions & 0 deletions lib/filestorage/tests/file_storage_test.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -688,6 +688,17 @@ public function test_delete_area_files_select() {
$this->assertEquals(0, count($areafiles)); $this->assertEquals(0, count($areafiles));
} }


public function test_delete_component_files() {
$user = $this->setup_three_private_files();
$fs = get_file_storage();

$areafiles = $fs->get_area_files($user->ctxid, 'user', 'private');
$this->assertEquals(4, count($areafiles));
$fs->delete_component_files('user');
$areafiles = $fs->get_area_files($user->ctxid, 'user', 'private');
$this->assertEquals(0, count($areafiles));
}

public function test_create_file_from_url() { public function test_create_file_from_url() {
$this->resetAfterTest(true); $this->resetAfterTest(true);


Expand Down

0 comments on commit 546b886

Please sign in to comment.