From ca10665747e47cc0df410f6135f60d730db84136 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Wed, 23 Oct 2024 15:27:36 -0400 Subject: [PATCH 01/14] update: Update documentation for schedule command for Laravel 11.x --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9fc81ec..6e48574 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ For this reason, we've developed the notion of custom resolvers. They must be im These custom resolvers don't run as items are entered, due to the load increase. This should arguably be queued, but easier on implementations for a command (cron) system. Use the Laravel Scheduler to execute our command. ```php -$schedule->command('logger:audit-resolver') +schedule::command('logger:audit-resolver') ->hourly() ->withoutOverlapping(); ``` From c8916a0e9852772a7219845475ba6ae7541c53c2 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Wed, 23 Oct 2024 15:27:51 -0400 Subject: [PATCH 02/14] update: Add if in migration to support PostGres --- .../migrations/2019_03_35_000001_create_logger_tables.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/database/migrations/2019_03_35_000001_create_logger_tables.php b/database/migrations/2019_03_35_000001_create_logger_tables.php index 4cd586b..7e40ce8 100644 --- a/database/migrations/2019_03_35_000001_create_logger_tables.php +++ b/database/migrations/2019_03_35_000001_create_logger_tables.php @@ -58,7 +58,13 @@ public function up(): void ->onDelete('RESTRICT'); }); - DB::statement('ALTER TABLE `audit_activities` ADD `ip_address` VARBINARY(16) AFTER `type`'); + if (DB::getDriverName() === 'pgsql') { + // PostgreSQL-specific SQL + DB::statement('ALTER TABLE audit_activities ADD ip_address BYTEA'); + } else { + // MySQL-specific SQL + DB::statement('ALTER TABLE `audit_activities` ADD `ip_address` VARBINARY(16) AFTER `type`'); + } Schema::create('audit_models', function (Blueprint $table) { $table->bigIncrements('id'); From f4d0a38e12d8b6f999c605d0fe2c814d8a1c262a Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Wed, 23 Oct 2024 15:31:57 -0400 Subject: [PATCH 03/14] update: Correct casing on command documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e48574..258c7d1 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ For this reason, we've developed the notion of custom resolvers. They must be im These custom resolvers don't run as items are entered, due to the load increase. This should arguably be queued, but easier on implementations for a command (cron) system. Use the Laravel Scheduler to execute our command. ```php -schedule::command('logger:audit-resolver') +Schedule::command('logger:audit-resolver') ->hourly() ->withoutOverlapping(); ``` From 2f59e9e5623427f8b5a7903b05c1f0f213f34ff2 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 12:18:05 -0400 Subject: [PATCH 04/14] update: Update PostGres ip_address column to use INET --- database/migrations/2019_03_35_000001_create_logger_tables.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2019_03_35_000001_create_logger_tables.php b/database/migrations/2019_03_35_000001_create_logger_tables.php index 7e40ce8..6fa1c35 100644 --- a/database/migrations/2019_03_35_000001_create_logger_tables.php +++ b/database/migrations/2019_03_35_000001_create_logger_tables.php @@ -60,7 +60,7 @@ public function up(): void if (DB::getDriverName() === 'pgsql') { // PostgreSQL-specific SQL - DB::statement('ALTER TABLE audit_activities ADD ip_address BYTEA'); + DB::statement('ALTER TABLE audit_activities ADD ip_address INET'); } else { // MySQL-specific SQL DB::statement('ALTER TABLE `audit_activities` ADD `ip_address` VARBINARY(16) AFTER `type`'); From 1f5e21e82c9350c1e56523e525e52da79bf9060c Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 12:18:37 -0400 Subject: [PATCH 05/14] update: Update saving and retrieval of ipAddress for PostGres --- src/Models/AuditActivity.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Models/AuditActivity.php b/src/Models/AuditActivity.php index da484b0..2960090 100644 --- a/src/Models/AuditActivity.php +++ b/src/Models/AuditActivity.php @@ -8,6 +8,7 @@ use Exception; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Support\Facades\DB; use Sourcetoad\Logger\Enums\ActivityType; use Sourcetoad\Logger\Enums\HttpVerb; use Sourcetoad\Logger\Logger; @@ -57,11 +58,19 @@ class AuditActivity extends BaseModel protected function setIpAddressAttribute(?string $value): void { - $this->attributes['ip_address'] = inet_pton((string)$value); + if (DB::getDriverName() === 'pgsql') { + $this->attributes['ip_address'] = $value; + } else { + $this->attributes['ip_address'] = inet_pton((string)$value); + } } protected function getIpAddressAttribute($value): string { + if (DB::getDriverName() === 'pgsql') { + return strtoupper($value); + } + return strtoupper(inet_ntop($value)); } From 8752ccb49a1f3618f566bfd03b50d7466dc52ae2 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 13:17:39 -0400 Subject: [PATCH 06/14] test: Add use Facades/DB to test --- tests/LoggerIpTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/LoggerIpTest.php b/tests/LoggerIpTest.php index 600e7bb..db2de62 100644 --- a/tests/LoggerIpTest.php +++ b/tests/LoggerIpTest.php @@ -4,6 +4,7 @@ namespace Sourcetoad\Logger\Test; use Sourcetoad\Logger\Models\AuditActivity; +use Illuminate\Support\Facades\DB; class LoggerIpTest extends TestCase { From cf473643d24587e995560d9cddf5a0ebf265c1cb Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 13:25:38 -0400 Subject: [PATCH 07/14] test: Attempt to fix tests --- tests/LoggerIpTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/LoggerIpTest.php b/tests/LoggerIpTest.php index db2de62..c99c457 100644 --- a/tests/LoggerIpTest.php +++ b/tests/LoggerIpTest.php @@ -5,9 +5,12 @@ use Sourcetoad\Logger\Models\AuditActivity; use Illuminate\Support\Facades\DB; +use Illuminate\Foundation\Testing\RefreshDatabase; class LoggerIpTest extends TestCase { + use RefreshDatabase; + public function testIpV4(): void { $address = '127.0.0.1'; From 53b1a2f8a9784796537c5eb13f4e77e324504663 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 13:43:59 -0400 Subject: [PATCH 08/14] test: Attempt to fix tests by switching extends --- tests/LoggerIpTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/LoggerIpTest.php b/tests/LoggerIpTest.php index c99c457..ee90daf 100644 --- a/tests/LoggerIpTest.php +++ b/tests/LoggerIpTest.php @@ -4,12 +4,9 @@ namespace Sourcetoad\Logger\Test; use Sourcetoad\Logger\Models\AuditActivity; -use Illuminate\Support\Facades\DB; -use Illuminate\Foundation\Testing\RefreshDatabase; -class LoggerIpTest extends TestCase +class LoggerIpTest extends Illuminate\Foundation\Testing\TestCase { - use RefreshDatabase; public function testIpV4(): void { From eb6ac1e1062abc471b02d6c4574e38894d4898aa Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 14:09:32 -0400 Subject: [PATCH 09/14] update: Install TestBench --- composer.json | 5 +++-- tests/LoggerIpTest.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index aaa2eb4..133ba2b 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ } }, "require-dev": { - "squizlabs/php_codesniffer": "^3.10", - "phpunit/phpunit": "^11.2" + "orchestra/testbench": "^9.5", + "phpunit/phpunit": "^11.2", + "squizlabs/php_codesniffer": "^3.10" } } diff --git a/tests/LoggerIpTest.php b/tests/LoggerIpTest.php index ee90daf..b580ea5 100644 --- a/tests/LoggerIpTest.php +++ b/tests/LoggerIpTest.php @@ -5,7 +5,7 @@ use Sourcetoad\Logger\Models\AuditActivity; -class LoggerIpTest extends Illuminate\Foundation\Testing\TestCase +class LoggerIpTest extends TestCase { public function testIpV4(): void From 3c95c70a4858763effafce5c99dde9f879a0a0b5 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 14:11:13 -0400 Subject: [PATCH 10/14] test: Update Testcase to use TestBench --- tests/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 9538975..b046cd4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,7 +6,7 @@ use Sourcetoad\Logger\LoggerFacade; use Sourcetoad\Logger\LoggerServiceProvider; -class TestCase extends \PHPUnit\Framework\TestCase +class TestCase extends \Orchestra\Testbench\TestCase { protected function getPackageProviders($app): array { From 85b31579cbb6453924f41a7fe743c4dc9032ecb9 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 14:29:19 -0400 Subject: [PATCH 11/14] update: Rearrange require-dev --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 133ba2b..d96a9db 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,11 @@ "illuminate/support": "^11.0", "illuminate/translation": "^11.0" }, + "require-dev": { + "orchestra/testbench": "^9.5", + "phpunit/phpunit": "^11.2", + "squizlabs/php_codesniffer": "^3.10" + }, "autoload": { "psr-4": { "Sourcetoad\\Logger\\": "src" @@ -43,9 +48,4 @@ } } }, - "require-dev": { - "orchestra/testbench": "^9.5", - "phpunit/phpunit": "^11.2", - "squizlabs/php_codesniffer": "^3.10" - } } From 7a726661f03e6f66515a136c2cd0d7259261dae9 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Mon, 28 Oct 2024 14:35:42 -0400 Subject: [PATCH 12/14] update: Fix trailing comma --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d96a9db..79d9428 100644 --- a/composer.json +++ b/composer.json @@ -47,5 +47,5 @@ "Logger": "Sourcetoad\\Logger\\LoggerFacade" } } - }, + } } From d11fc7741fbd652f526b0b257fbebed6babb69b2 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Tue, 29 Oct 2024 13:06:11 -0400 Subject: [PATCH 13/14] test: Remove unneeded space --- tests/LoggerIpTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/LoggerIpTest.php b/tests/LoggerIpTest.php index b580ea5..600e7bb 100644 --- a/tests/LoggerIpTest.php +++ b/tests/LoggerIpTest.php @@ -7,7 +7,6 @@ class LoggerIpTest extends TestCase { - public function testIpV4(): void { $address = '127.0.0.1'; From 79d3a56abbd4e1c9139f8176bf585fb0e746fc40 Mon Sep 17 00:00:00 2001 From: nilsdelaguardia Date: Tue, 29 Oct 2024 16:19:45 -0400 Subject: [PATCH 14/14] test: Use use for TestBenchTestCase --- tests/TestCase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index b046cd4..6039c07 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,8 +5,9 @@ use Sourcetoad\Logger\LoggerFacade; use Sourcetoad\Logger\LoggerServiceProvider; +use Orchestra\Testbench\TestCase as TestBenchTestCase; -class TestCase extends \Orchestra\Testbench\TestCase +class TestCase extends TestBenchTestCase { protected function getPackageProviders($app): array {