MDL-50887 antivirus: Use namespace referenced classes.

This commit is contained in:
Ruslan Kabalin
2016-02-29 09:31:09 +00:00
parent b6bb4e81bb
commit 11362ae3ff
8 changed files with 23 additions and 24 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ require_capability('moodle/site:config', context_system::instance());
$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageantiviruses";
// Get currently installed and enabled antivirus plugins.
$availableantiviruses = antiviruses_get_available();
$availableantiviruses = \core\antivirus\manager::get_available();
if (!empty($antivirus) and empty($availableantiviruses[$antivirus])) {
redirect ($returnurl);
}
@@ -652,8 +652,8 @@ class manager {
// Perform a virus scan now.
try {
antiviruses_scan_file($filepath, $attachment->filename, true);
} catch (\antivirus_exception $e) {
\core\antivirus\manager::scan_file($filepath, $attachment->filename, true);
} catch (\core\antivirus\scanner_exception $e) {
mtrace("--> A virus was found in the attachment '{$attachment->filename}'.");
$this->inform_attachment_virus();
return;
+2 -2
View File
@@ -6549,7 +6549,7 @@ class admin_setting_manageantiviruses extends admin_setting {
return true;
}
$antivirusesavailable = antiviruses_get_available();
$antivirusesavailable = \core\antivirus\manager::get_available();
foreach ($antivirusesavailable as $antivirus => $antivirusstr) {
if (strpos($antivirus, $query) !== false) {
return true;
@@ -6578,7 +6578,7 @@ class admin_setting_manageantiviruses extends admin_setting {
$txt->updown = "$txt->up/$txt->down";
$antivirusesavailable = antiviruses_get_available();
$antivirusesavailable = \core\antivirus\manager::get_available();
$activeantiviruses = explode(',', $CFG->antiviruses);
$activeantiviruses = array_reverse($activeantiviruses);
+6 -6
View File
@@ -39,7 +39,7 @@ class manager {
*
* @return array Array ('antivirusname'=>stdClass antivirus object).
*/
public static function antiviruses_get_enabled() {
private static function get_enabled() {
global $CFG;
$active = array();
@@ -63,11 +63,11 @@ class manager {
* @param string $file Full path to the file.
* @param string $filename Name of the file (could be different from physical file if temp file is used).
* @param bool $deleteinfected whether infected file needs to be deleted.
* @throws \core_antivirus\scanner_exception If file is infected.
* @throws \core\antivirus\scanner_exception If file is infected.
* @return void
*/
public static function antiviruses_scan_file($file, $filename, $deleteinfected) {
$antiviruses = antiviruses_get_enabled();
public static function scan_file($file, $filename, $deleteinfected) {
$antiviruses = self::get_enabled();
foreach ($antiviruses as $antivirus) {
$antivirus->scan_file($file, $filename, $deleteinfected);
}
@@ -94,9 +94,9 @@ class manager {
*
* @return array Array ('antivirusname'=>'localised antivirus name').
*/
public static function antiviruses_get_available() {
public static function get_available() {
$antiviruses = array();
foreach (core_component::get_plugin_list('antivirus') as $antivirusname => $dir) {
foreach (\core_component::get_plugin_list('antivirus') as $antivirusname => $dir) {
$antiviruses[$antivirusname] = get_string('pluginname', 'antivirus_'.$antivirusname);
}
return $antiviruses;
+4 -4
View File
@@ -4389,9 +4389,9 @@ function events_pending_count($eventname) {
* @return void
*/
function clam_message_admins($notice) {
debugging('clam_message_admins() is deprecated, please use message_admins() method of antivirus_clamav class.', DEBUG_DEVELOPER);
debugging('clam_message_admins() is deprecated, please use message_admins() method of \antivirus_clamav\scanner class.', DEBUG_DEVELOPER);
$antivirus = antiviruses_get_antivirus('clamav');
$antivirus = \core\antivirus\manager::get_antivirus('clamav');
$antivirus->message_admins($notice);
}
@@ -4403,8 +4403,8 @@ function clam_message_admins($notice) {
* @return string The definition of the error code
*/
function get_clam_error_code($returncode) {
debugging('get_clam_error_code() is deprecated, please use get_clam_error_code() method of antivirus_clamav class.', DEBUG_DEVELOPER);
debugging('get_clam_error_code() is deprecated, please use get_clam_error_code() method of \antivirus_clamav\scanner class.', DEBUG_DEVELOPER);
$antivirus = antiviruses_get_antivirus('clamav');
$antivirus = \core\antivirus\manager::get_antivirus('clamav');
return $antivirus->get_clam_error_code($returncode);
}
+4 -5
View File
@@ -54,11 +54,10 @@ information provided here is intended especially for developers.
are assigned to fields and buttons through a self-contained JS function.
* Added $CFG->urlrewriteclass option to config.php allowing clean / semantic urls to
be implemented in a plugin, eg local_cleanurls.
* $CFG->pathtoclam global setting has been moved to clamav antivirus plugin
setting of the same name.
* clam_message_admins() and get_clam_error_code() have been deprecated, its
functionality is now a part of antivirus_clamav class methods.
* \repository::antivir_scan_file() has been deprecated, antiviruses_scan_file() that
* $CFG->pathtoclam global setting has been moved to clamav antivirus plugin setting of the same name.
* clam_message_admins() and get_clam_error_code() have been deprecated, its functionality
is now a part of \antivirus_clamav\scanner class methods.
* \repository::antivir_scan_file() has been deprecated, \core\antivirus\manager::scan_file() that
applies antivirus plugins is replacing its functionality.
=== 3.0 ===
+3 -3
View File
@@ -1191,8 +1191,8 @@ abstract class repository implements cacheable_object {
* @param bool $deleteinfected
*/
public static function antivir_scan_file($thefile, $filename, $deleteinfected) {
debugging('Please upgrade your code to use antiviruses_scan_file instead', DEBUG_DEVELOPER);
antiviruses_scan_file($thefile, $filename, $deleteinfected);
debugging('Please upgrade your code to use \core\antivirus\manager::scan_file instead', DEBUG_DEVELOPER);
\core\antivirus\manager::scan_file($thefile, $filename, $deleteinfected);
}
/**
@@ -1320,7 +1320,7 @@ abstract class repository implements cacheable_object {
// scan for viruses if possible, throws exception if problem found
// TODO: MDL-28637 this repository_no_delete is a bloody hack!
antiviruses_scan_file($thefile, $record->filename, empty($CFG->repository_no_delete));
\core\antivirus\manager::scan_file($thefile, $record->filename, empty($CFG->repository_no_delete));
$fs = get_file_storage();
// If file name being used.
+1 -1
View File
@@ -141,7 +141,7 @@ class repository_upload extends repository {
}
}
antiviruses_scan_file($_FILES[$elname]['tmp_name'], $_FILES[$elname]['name'], true);
\core\antivirus\manager::scan_file($_FILES[$elname]['tmp_name'], $_FILES[$elname]['name'], true);
// {@link repository::build_source_field()}
$sourcefield = $this->get_file_source_info($_FILES[$elname]['name']);