Skip to content

Commit

Permalink
MDL-33550 reset repository static cache between unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jun 14, 2012
1 parent cfc4db4 commit 6fd1cf0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/phpunit/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,11 @@ public static function reset_all_data($logchanges = false) {
get_string_manager()->reset_caches();
events_get_handlers('reset');
textlib::reset_caches();
if (class_exists('repository')) {
repository::reset_caches();
}
$GROUPLIB_CACHE = null;
//TODO: add more resets here and probably refactor them to new core function
//TODO MDL-25290: add more resets here and probably refactor them to new core function

// purge dataroot directory
self::reset_dataroot();
Expand Down
16 changes: 13 additions & 3 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2191,21 +2191,31 @@ public function convert_references_to_local() {
}
}


/**
* Called from phpunit between tests, resets whatever was cached
*/
public static function reset_caches() {
self::sync_external_file(null, true);
}

/**
* Call to request proxy file sync with repository source.
*
* @param stored_file $file
* @param bool $resetsynchistory whether to reset all history of sync (used by phpunit)
* @return bool success
*/
public static function sync_external_file(stored_file $file) {
public static function sync_external_file($file, $resetsynchistory = false) {
global $DB;
// TODO MDL-25290 static should be replaced with MUC code.
static $synchronized = array();
if ($resetsynchistory) {
$synchronized = array();
}

$fs = get_file_storage();

if (!$file->get_referencefileid()) {
if (!$file || !$file->get_referencefileid()) {
return false;
}
if (array_key_exists($file->get_id(), $synchronized)) {
Expand Down

0 comments on commit 6fd1cf0

Please sign in to comment.