Skip to content

Commit

Permalink
code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Feb 9, 2025
1 parent fc3dc7c commit 30607a5
Show file tree
Hide file tree
Showing 25 changed files with 315 additions and 289 deletions.
2 changes: 1 addition & 1 deletion app/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Calendar

public function __construct($dateInput = null)
{
$this->date = DateTime::createFromFormat('d/m/Y', "01/".$dateInput)->getTimestamp();
$this->date = DateTime::createFromFormat('d/m/Y', '01/'.$dateInput)->getTimestamp();
$this->active_year = $dateInput !== null ? date('Y', $this->date) : date('Y');
$this->active_month = $dateInput !== null ? date('m', $this->date) : date('m');
$this->active_day = $dateInput !== null ? date('d', $this->date) : date('d');
Expand Down
92 changes: 46 additions & 46 deletions app/Console/Commands/SendNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;

class SendNotifications extends Command
{
Expand Down Expand Up @@ -98,53 +97,54 @@ public function handle()
$txt .= "<br>\n";
}

// Create a new PHPMailer instance
$mail = new PHPMailer(true);
// Create a new PHPMailer instance
$mail = new PHPMailer(true);

// Server settings
$mail->isSMTP(); // Use SMTP
$mail->Host = env('MAIL_HOST'); // Set the SMTP server
$mail->SMTPAuth = env('MAIL_AUTH'); // Enable SMTP authentication
$mail->Username = env('MAIL_USERNAME'); // SMTP username
$mail->Password = env('MAIL_PASSWORD'); // SMTP password
$mail->SMTPSecure = env('MAIL_SMTP_SECURE',false); // Enable TLS encryption, `ssl` also accepted
$mail->SMTPAutoTLS = env('MAIL_SMTP_AUTO_TLS'); // Enable auto TLS
$mail->Port = env('MAIL_PORT'); // TCP port to connect to

// Recipients
$mail->setFrom(config('deming.notification.mail-from'));
$mail->addAddress($user->email);
$mail->Subject = config('deming.notification.mail-subject');

// Get message model
$message = config('deming.notification.mail-content');
if (($message==null)||(strlen($message)==0))
$message = trans('cruds.config.notifications.message_default_content');

// Replace %table% in message model
$message = str_replace("%table%",$txt,$message);

// Content
$mail->isHTML(true);
$mail->Body = $message;

// Optional: Add DKIM signing
$mail->DKIM_domain = env('MAIL_DKIM_DOMAIN');
$mail->DKIM_private = env('MAIL_DKIM_PRIVATE');
$mail->DKIM_selector = env('MAIL_DKIM_SELECTOR');
$mail->DKIM_passphrase = env('MAIL_DKIM_PASSPHRASE');
$mail->DKIM_identity = $mail->From;

// Send email
$mail->send();

// Success
Log::debug("Mail sent to {$user->email}");
$mail->isSMTP(); // Use SMTP
$mail->Host = env('MAIL_HOST'); // Set the SMTP server
$mail->SMTPAuth = env('MAIL_AUTH'); // Enable SMTP authentication
$mail->Username = env('MAIL_USERNAME'); // SMTP username
$mail->Password = env('MAIL_PASSWORD'); // SMTP password
$mail->SMTPSecure = env('MAIL_SMTP_SECURE', false); // Enable TLS encryption, `ssl` also accepted
$mail->SMTPAutoTLS = env('MAIL_SMTP_AUTO_TLS'); // Enable auto TLS
$mail->Port = env('MAIL_PORT'); // TCP port to connect to

// Recipients
$mail->setFrom(config('deming.notification.mail-from'));
$mail->addAddress($user->email);
$mail->Subject = config('deming.notification.mail-subject');

// Get message model
$message = config('deming.notification.mail-content');
if (($message === null) || (strlen($message) === 0)) {
$message = trans('cruds.config.notifications.message_default_content');
}

// Replace %table% in message model
$message = str_replace('%table%', $txt, $message);

// Content
$mail->isHTML(true);
$mail->Body = $message;

// Optional: Add DKIM signing
$mail->DKIM_domain = env('MAIL_DKIM_DOMAIN');
$mail->DKIM_private = env('MAIL_DKIM_PRIVATE');
$mail->DKIM_selector = env('MAIL_DKIM_SELECTOR');
$mail->DKIM_passphrase = env('MAIL_DKIM_PASSPHRASE');
$mail->DKIM_identity = $mail->From;

// Send email
$mail->send();

// Success
Log::debug("Mail sent to {$user->email}");
}
}
}
} catch (Exception $e) {
// Log error
Log::error("Message could not be sent. Mailer Error: {$mail->ErrorInfo}");
} catch (Exception $e) {
// Log error
Log::error("Message could not be sent. Mailer Error: {$mail->ErrorInfo}");
}
} else {
Log::debug('SendNotifications - no notifications today');
Expand Down
24 changes: 12 additions & 12 deletions app/Exports/ActionsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ public function map($action): array
{
return [
[
$action->reference,
$action->type,
$action->due_date,
$action->scope,
$action->measures()->implode('clause', ', '),
$action->name,
$action->cause,
$action->owners()->implode('name', ', '),
$action->remediation,
$action->status,
$action->close_date,
$action->justification,
$action->reference,
$action->type,
$action->due_date,
$action->scope,
$action->measures()->implode('clause', ', '),
$action->name,
$action->cause,
$action->owners()->implode('name', ', '),
$action->remediation,
$action->status,
$action->close_date,
$action->justification,
],
];
}
Expand Down
12 changes: 8 additions & 4 deletions app/Http/Controllers/API/ControlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public function store(Request $request)

$control = Control::create($request->all());

if ($request->has('measures'))
if ($request->has('measures')) {
$control->measures()->sync($request->input('measures', []));
}

if ($request->has('owners'))
if ($request->has('owners')) {
$control->owners()->sync($request->input('owners', []));
}

return response()->json($control, 201);
}
Expand All @@ -47,11 +49,13 @@ public function update(Request $request, Control $control)

$control->update($request->all());

if ($request->has('measures'))
if ($request->has('measures')) {
$control->measures()->sync($request->input('measures', []));
}

if ($request->has('owners'))
if ($request->has('owners')) {
$control->owners()->sync($request->input('owners', []));
}

return response()->json();
}
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/API/MeasureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public function store(Request $request)
abort_if(Auth::User()->role !== 4, Response::HTTP_FORBIDDEN, '403 Forbidden');

$measure = Measure::create($request->all());
if ($request->has('controls'))
if ($request->has('controls')) {
$measure->controls()->sync($request->input('controls', []));
}

return response()->json($measure, 201);
}
Expand All @@ -42,8 +43,9 @@ public function update(Request $request, Measure $measure)
abort_if(Auth::User()->role !== 4, Response::HTTP_FORBIDDEN, '403 Forbidden');

$measure->update($request->all());
if ($request->has('controls'))
if ($request->has('controls')) {
$measure->controls()->sync($request->input('controls', []));
}

return response()->json();
}
Expand Down
Loading

0 comments on commit 30607a5

Please sign in to comment.