Skip to content

Commit

Permalink
fix: fsck_file email report was always empty (even when it shouldn't …
Browse files Browse the repository at this point in the history
…be!)
  • Loading branch information
gboudreau committed Oct 13, 2024
1 parent c0e29b8 commit 522c135
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions includes/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,31 +562,34 @@ public function emailAsRequired() {

$last_mod_date = filemtime($logfile);
if ($last_mod_date > $this->getLastEmailSentTime()) {
$body = $this->getBody(TRUE);

if ($this->shouldSendViaEmail()) {
email_sysadmin($this->getSubject(), $this->getBody());
email_sysadmin($this->getSubject(), $body);
}

LogHook::trigger(LogHook::EVENT_TYPE_FSCK, Log::EVENT_CODE_FSCK_REPORT, $this->getSubject() . "\n" . $this->getBody());
LogHook::trigger(LogHook::EVENT_TYPE_FSCK, Log::EVENT_CODE_FSCK_REPORT, $this->getSubject() . "\n" . $body);

$this->lastEmailSentTime = $last_mod_date;
Settings::set("last_email_$this->filename", $this->lastEmailSentTime);
}
}

private function shouldSendViaEmail() {
$this->getBody();
$fsck_report = FsckTask::getCurrentTask()->get_fsck_report();
return (@$fsck_report->send_via_email === TRUE);
}

private function getBody() {
private function getBody($delete_log = false) {
$logfile = "$this->path/$this->filename";
if ($this->filename == 'fsck_checksums.log') {
return file_get_contents($logfile) . "\nNote: You should manually delete the $logfile file once you're done with it.";
} else if ($this->filename == 'fsck_files.log' && file_exists($logfile)) {
$fsck_report = unserialize(file_get_contents($logfile));
/** @var FSCKReport $fsck_report */
unlink($logfile);
if ($delete_log) {
unlink($logfile);
}
return $fsck_report->get_email_body(FALSE) . "\nNote: This report is a complement to the last report you've received. It details possible errors with files for which the fsck was postponed.";
} else {
return '[empty]';
Expand Down

0 comments on commit 522c135

Please sign in to comment.