Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIG-3839 (hotfix) Fixes email issue #3345

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ function bos_emergency_alerts_mail($key, &$message, $params) {
if ($key == "subscribe_error") {
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['subject'] = "Emergency Alerts Subscription Error.";
$message['body'] = "
<p>There was an issue with a user subscribing to Everbridge Emergency Alerts from boston.gov.</p>
<p>The subscription came from a form on: " . \Drupal::request()->server->get("HTTP_REFERER") . "</p>
<p>The user was located at: " . \Drupal::request()->getClientIp() . "</p>
<p>The information completed on the form was:<br/>
<pre>" . print_r($params["message"], TRUE) . "</pre>
</p>";
$message['body'][] = "<p>There was an issue with a user subscribing to Everbridge Emergency Alerts from boston.gov.</p>";
$message['body'][] = "<p>The subscription came from a form on: " . \Drupal::request()->server->get("HTTP_REFERER") . "</p>";
$message['body'][] = "<p>The user was located at: " . \Drupal::request()->getClientIp() ?? "--" . "</p>";
$message['body'][] = "<p>The error reported was: " . $params["message"]["error"] ?? "--" . "</p>";
$message['body'][] = "<p>The information completed on the form was:<br/>";
$message['body'][] = "<pre>" . print_r($params["message"]["form"] ?? [], TRUE) . "</pre>";
$message['body'][] = "</p>";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ private function isFlooding(Request $request) {
*
* Actual email formatted in bos_emergency_alerts_mail().
*/
public function mailAlert(): void {
public function mailAlert($message): void {

$request = $this->request->request->all();

if (empty($this->settings["email_alerts"])) {
if (empty($this->settings["emergency_alerts_settings"]["email_alerts"])) {
$this->log->warning("Emergency_alerts email recipient is not set. An error has been encountered, but no email has been sent.");
return;
}

$params['message'] = $request;
$result = $this->mail->mail("bos_emergency_alerts", "subscribe_error", $this->settings["email_alerts"], "en", $params, NULL, TRUE);
$params['message'] = ["error" => $message, "form" => $request];
$result = $this->mail->mail("bos_emergency_alerts", "subscribe_error", $this->settings["emergency_alerts_settings"]["email_alerts"], "en", $params, NULL, TRUE);
if ($result['result'] !== TRUE) {
$this->log->warning("There was a problem sending your message and it was not sent.");
}
Expand Down Expand Up @@ -220,14 +220,14 @@ public function responseOutput(string $message, int $type): Response {
$json['errors'] = ["message" => $message];
unset($json['contact']);
$response->setContent(json_encode($json));
$this->log->error("Internal Error");
$this->mailAlert();
$this->mailAlert($message);
break;

default:
$json['status'] = 'error';
$json['errors'] = ["message" => $message];
$response->setContent(json_encode($json));
$this->mailAlert($message);
break;
}
return $response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ protected function executeCurl(bool $retry = FALSE): array {
return $this->curl->executeCurl($retry);
}
catch (Exception $e) {
$config = CobSettings::getSettings("EA_SETTINGS", "bos_emergency_alerts");
$mailManager = \Drupal::service('plugin.manager.mail');
if (!$mailManager->mail(
"bos_emergency_alerts",
'subscribe_error',
$config["emergency_alerts_settings"]["email_alerts"] ?? "[email protected]",
"en",
["message" => (array) $this->curl->request()],
NULL,
TRUE)) {
\Drupal::logger("bos_emergency_alerts")->warning(t("Error Email sending from Drupal has failed."));
}
throw new Exception($e->getMessage(), $e->getCode());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private function lookupArcGISGeocoder(string $direction): BosGeoAddress|bool {

$config = $this->config["arcgis"];

$curl = new BosCurlControllerBase([], TRUE);
$curl = new BosCurlControllerBase([], FALSE);
$base = $config["base_url"];

switch ($direction) {
Expand Down Expand Up @@ -295,7 +295,7 @@ private function lookupGoogleGeocoder(string $direction): BosGeoAddress|bool {

$config = $this->config["google"];

$curl = new BosCurlControllerBase([], TRUE);
$curl = new BosCurlControllerBase([], FALSE);
$base = $config["base_url"];
$token = $config["token"]; //"AIzaSyBIJymUhZLfQNNds5zZ6JsEz-tgLfN8qD4";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function executeCurl(bool $retry = FALSE): array {

elseif ($this->response["http_code"] >= 300 || $this->response["http_code"] < 200) {
// Got an error or non-200 code - throw error
$this->error = "Unexpected Endpoint Error (HTTP Code: {$this->response["http_code"]}): {$this->response["response_raw"]}";
$this->error = "Endpoint Error (HTTP Code: {$this->response["http_code"]}): {$this->response["response_raw"]}";
$this->writeError($this->error);
throw new Exception($this->error, self::BAD_REQUEST);
}
Expand Down Expand Up @@ -363,6 +363,7 @@ private function extractHeaders(string &$response, array &$headers): void {

// Log
\Drupal::logger("BosCurlHandler")->info("
Headers have been extracted.<br>Complete response log:<br>
<table>
<tr><td>Endpoint</td><td>{$this->request["host"]}</td></tr>
<tr><td>Response Headers</td><td>{$_headers}</td></tr>
Expand All @@ -385,11 +386,11 @@ private function extractHeaders(string &$response, array &$headers): void {
*/
private function writeError(string $narrative = "Error"): void {
\Drupal::logger("CurlControllerBase")
->error("<br>
->error("Error Encountered.<br>
<table>
<tr><td>Issue</td><td>{$narrative}</td></tr>
<tr><td>Endpoint</td><td>" . $this->request["host"] ?? "unknown" . "</td></tr>
<tr><td>JSON Payload</td><td>" . json_encode($this->request["body"] ?? []) . "</td></tr>
<tr><td>Endpoint</td><td>" . ($this->request["host"] ?? "unknown") . "</td></tr>
<tr><td>JSON Payload</td><td>" . (json_encode($this->request["body"]) ?? []) . "</td></tr>
<tr><td>JSON Response</td><td>" . print_r($this->response["response_raw"]??"", TRUE) . "</td></tr>
</table>
");
Expand Down