Skip to content

Commit

Permalink
Merge branch 'MDL-69522-custom-message-m' of https://github.com/Peter…
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Jan 19, 2021
2 parents 38f21e1 + c426b09 commit 790cb18
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/classes/antivirus/manager.php
Expand Up @@ -106,7 +106,18 @@ public static function scan_file($file, $filename, $deleteinfected) {
if ($deleteinfected) {
unlink($file);
}
throw new \core\antivirus\scanner_exception('virusfound', '', array('item' => $filename));

// Get custom message to display to user from antivirus engine.
$displaymessage = $antivirus->get_virus_found_message();
$placeholders = array_merge(['item' => $filename], $displaymessage['placeholders']);

throw new \core\antivirus\scanner_exception(
$displaymessage['string'],
'',
$placeholders,
null,
$displaymessage['component']
);
} else if ($result === $antivirus::SCAN_RESULT_ERROR) {
// Here we need to generate a different incident based on an error.
$incidentdetails = $antivirus->get_incident_details($file, $filename, $notice, false);
Expand Down Expand Up @@ -163,7 +174,17 @@ public static function scan_data($data) {
$event = \core\event\virus_infected_data_detected::create($params);
$event->trigger();

throw new \core\antivirus\scanner_exception('virusfound', '', array('item' => get_string('datastream', 'antivirus')));
// Get custom message to display to user from antivirus engine.
$displaymessage = $antivirus->get_virus_found_message();
$placeholders = array_merge(['item' => get_string('datastream', 'antivirus')], $displaymessage['placeholders']);

throw new \core\antivirus\scanner_exception(
$displaymessage['string'],
'',
$placeholders,
null,
$displaymessage['component']
);
} else if ($result === $antivirus::SCAN_RESULT_ERROR) {
// Here we need to generate a different incident based on an error.
$incidentdetails = $antivirus->get_incident_details('', $filename, $notice, false);
Expand Down
10 changes: 10 additions & 0 deletions lib/classes/antivirus/scanner.php
Expand Up @@ -238,4 +238,14 @@ public function get_incident_details($file = '', $filename = '', $notice = '', $
public function get_messages() : array {
return $this->messages;
}

/**
* Getter method for the antivirus message displayed in the exception.
*
* @return array array of string and component to pass to exception constructor.
*/
public function get_virus_found_message() {
// Base antivirus found string.
return ['string' => 'virusfound', 'component' => 'antivirus', 'placeholders' => []];
}
}

0 comments on commit 790cb18

Please sign in to comment.