MDL-58220 repositories: missing/disabled issuer

This makes the code checking for a missing / disabled issuer a bit cleaner.
This commit is contained in:
Damyon Wiese 2017-03-30 12:17:50 +08:00
parent 5afb4f0e50
commit 33536fb2b7
2 changed files with 13 additions and 5 deletions

View File

@ -72,6 +72,10 @@ class repository_googledocs extends repository {
} catch (dml_missing_record_exception $e) {
$this->disabled = true;
}
if ($this->issuer && !$this->issuer->get('enabled')) {
$this->disabled = true;
}
}
/**
@ -863,7 +867,7 @@ class repository_googledocs extends repository {
// Check this issuer is enabled.
if (!$this->issuer->get('enabled')) {
if ($this->disabled) {
throw new repository_exception('cannotdownload', 'repository');
}
@ -956,7 +960,7 @@ class repository_googledocs extends repository {
* @param int $filestatus
*/
public function get_reference_details($reference, $filestatus = 0) {
if (!$this->issuer->get('enabled')) {
if ($this->disabled) {
throw new repository_exception('cannotdownload', 'repository');
}
if (empty($reference)) {

View File

@ -68,6 +68,10 @@ class repository_skydrive extends repository {
} catch (dml_missing_record_exception $e) {
$this->disabled = true;
}
if ($this->issuer && !$this->issuer->get('enabled')) {
$this->disabled = true;
}
}
/**
@ -202,7 +206,7 @@ class repository_skydrive extends repository {
$path = $this->build_node_path('root', get_string('pluginname', 'repository_skydrive'));
}
if (!$this->issuer->get('enabled')) {
if ($this->disabled) {
// Empty list of files for disabled repository.
return ['dynload' => false, 'list' => [], 'nologin' => true];
}
@ -401,7 +405,7 @@ class repository_skydrive extends repository {
public function get_file($reference, $filename = '') {
global $CFG;
if (!$this->issuer->get('enabled')) {
if ($this->disabled) {
throw new repository_exception('cannotdownload', 'repository');
}
@ -518,7 +522,7 @@ class repository_skydrive extends repository {
* @param array $options additional options affecting the file serving
*/
public function send_file($storedfile, $lifetime=null , $filter=0, $forcedownload=false, array $options = null) {
if (!$this->issuer->get('enabled')) {
if ($this->disabled) {
throw new repository_exception('cannotdownload', 'repository');
}