Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
daanrijpkemacb committed Apr 24, 2024
1 parent d025b05 commit 9039126
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Observability/SentryLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function initialize(object $config): void

private function getEnvironment(): string
{
if ($_SERVER['SERVER_NAME'] === 'localhost') {
if (!isset($_SERVER['SERVER_NAME']) || $_SERVER['SERVER_NAME'] === 'localhost') {
return 'development';
}

Expand Down
19 changes: 15 additions & 4 deletions src/Observability/SimpleFileIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ final class SimpleFileIO {
public function writeActivationFile(BluemConfiguration $data): bool
{
$path = __DIR__ . '/../../logs/';
$filename = "activations_" . date("Ymd") . ".json";
$filename = $this->createFileName();

$allData = [
'config'=>$data,
'php_version'=>PHP_VERSION,
'bluem_php_version'=>BLUEM_PHP_LIBRARY_VERSION
];

try {
$fileContent = json_encode($data, JSON_THROW_ON_ERROR) . "\r\n";
$fileContent = json_encode($allData, JSON_THROW_ON_ERROR) . "\r\n";
} catch (JsonException $e) {
return false;
}
Expand All @@ -23,10 +29,15 @@ public function writeActivationFile(BluemConfiguration $data): bool
public function activationFileExists(): bool
{
$path = __DIR__ . '/../../logs/';
# consider a new file every month
$filename = "activations_" . date("Ym") . ".json";
$filename = $this->createFileName();

return file_exists($path . $filename);
}

# consider a new file every month
private function createFileName(): string
{
return "activations_" . date("Ym") . ".json";
}
}

16 changes: 12 additions & 4 deletions src/Observability/SimpleMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ public function notifyConfiguration(object $configuration): bool {
foreach ($configuration as $key => $value) {
$message .= strtoupper($key) . ": " . $value . "\n";
}
$message .= "Environment: ". $_SERVER['SERVER_NAME'] === 'localhost' ? 'development' : 'production';
$message .= "Environment: ". $this->getEnvironment();
$message .= "Bluem PHP library version: ".BLUEM_PHP_LIBRARY_VERSION;

$adminEmail = "pluginsupport@bluem.nl";

// Additional headers
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers = "From: $adminEmail\r\n";
$headers .= "Reply-To: $adminEmail\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$to = "pluginsupport@bluem.nl";
$to = $adminEmail;
$subject = "Library Bluem-php instantiatie";

// Send the email
return mail($to, $subject, $message, $headers);
}

private function getEnvironment()
{
return (!isset($_SERVER['SERVER_NAME']) || $_SERVER['SERVER_NAME'] === 'localhost' ? 'development' : 'production');
}
}

0 comments on commit 9039126

Please sign in to comment.