diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d03ca3c..4453cc9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,6 +2,7 @@ name: tests on: push: + pull_request: schedule: - cron: '0 0 * * *' diff --git a/README.md b/README.md index 765c88e..566a505 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Laravel Process Stamps -[![Latest Version on Packagist](https://img.shields.io/packagist/v/orisintel/laravel-process-stamps.svg?style=flat-square)](https://packagist.org/packages/orisintel/laravel-process-stamps) -[![Build Status](https://img.shields.io/github/workflow/status/orisintel/laravel-process-stamps/tests?style=flat-square)](https://github.com/orisintel/laravel-process-stamps/actions?query=workflow%3Atests) -[![Total Downloads](https://img.shields.io/packagist/dt/orisintel/laravel-process-stamps.svg?style=flat-square)](https://packagist.org/packages/orisintel/laravel-process-stamps) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/always-open/laravel-process-stamps.svg?style=flat-square)](https://packagist.org/packages/always-open/laravel-process-stamps) +[![Build Status](https://img.shields.io/github/workflow/status/always-open/laravel-process-stamps/tests?style=flat-square)](https://github.com/always-open/laravel-process-stamps/actions?query=workflow%3Atests) +[![Total Downloads](https://img.shields.io/packagist/dt/always-open/laravel-process-stamps.svg?style=flat-square)](https://packagist.org/packages/always-open/laravel-process-stamps) It is sometimes very useful to know which process created or modified a particular record in your database. This package provides a trait to add to your Laravel models which automatically logs that for you. @@ -11,13 +11,13 @@ It is sometimes very useful to know which process created or modified a particul You can install the package via composer: ```bash -composer require orisintel/laravel-process-stamps +composer require always-open/laravel-process-stamps ``` ## Configuration ``` php -php artisan vendor:publish --provider="\OrisIntel\ProcessStamps\ProcessStampsServiceProvider" +php artisan vendor:publish --provider="\AlwaysOpen\ProcessStamps\ProcessStampsServiceProvider" ``` Running the above command will publish both the migration and the config file. @@ -84,7 +84,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ### Security -If you discover any security related issues, please email [opensource@orisintel.com](mailto:opensource@orisintel.com) instead of using the issue tracker. +If you discover any security related issues, please email @tomschlick or @qschmick directly instead of using the issue tracker. ## Credits diff --git a/SECURITY.md b/SECURITY.md index 7498fa5..d75931c 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,4 +2,4 @@ ## Reporting a Vulnerability -If you encounter what you believe to be a security vulnerability, please report it immediately to opensource@orisintel.com. Please include your name, your email address, the url of the package, and a description of the suspected issue. +If you encounter what you believe to be a security vulnerability, please report it immediately to @tomschlick or @qschmick. Please include your name, your email address, the url of the package, and a description of the suspected issue. diff --git a/composer.json b/composer.json index 3ef9fb8..7536d06 100644 --- a/composer.json +++ b/composer.json @@ -1,27 +1,14 @@ { - "name": "orisintel/laravel-process-stamps", + "name": "always-open/laravel-process-stamps", "description": "Logs which process created or modified a record", "keywords": [ - "orisintel", + "always-open", "laravel-process-stamps", "laravel", "logging" ], - "homepage": "https://github.com/orisintel/laravel-process-stamps", + "homepage": "https://github.com/always-open/laravel-process-stamps", "license": "MIT", - "authors": [ - { - "name": "Tom Schlick", - "email": "tschlick@orisintel.com", - "role": "Developer" - }, - { - "name": "ORIS Intelligence", - "email": "developers@orisintel.com", - "homepage": "https://orisintel.com", - "role": "Organization" - } - ], "require": { "php": "^7.3|^8.0", "laravel/framework": "^8.0" @@ -35,12 +22,12 @@ }, "autoload": { "psr-4": { - "OrisIntel\\ProcessStamps\\": "src" + "AlwaysOpen\\ProcessStamps\\": "src" } }, "autoload-dev": { "psr-4": { - "OrisIntel\\ProcessStamps\\Tests\\": "tests" + "AlwaysOpen\\ProcessStamps\\Tests\\": "tests" } }, "scripts": { @@ -54,7 +41,7 @@ "extra": { "laravel": { "providers": [ - "OrisIntel\\ProcessStamps\\ProcessStampsServiceProvider" + "AlwaysOpen\\ProcessStamps\\ProcessStampsServiceProvider" ] } } diff --git a/src/ProcessStamp.php b/src/ProcessStamp.php index a19c70f..670450c 100644 --- a/src/ProcessStamp.php +++ b/src/ProcessStamp.php @@ -1,12 +1,12 @@ first(); + return retry(4, function() use ($hash, $process, $parent) { + $stamp = static::firstWhere('hash', $hash); + + /* + * If stamp does not exist in the database yet, go ahead and obtain a lock to create it. + * This specifically doesn't lock as the first step to avoid all calls obtaining a lock from the cache if + * the item already exists in the DB. + */ + if (! $stamp) { + Cache::lock('process-stamps-hash-create-' . $hash, 10) + ->get(function () use (&$stamp, $hash, $process, $parent) { + $stamp = static::firstOrCreate(['hash' => $hash], [ + 'name' => trim($process['name']), + 'type' => $process['type'], + 'parent_id' => optional($parent)->getKey(), + ]); + }); + } - /* - * If stamp does not exist in the database yet, go ahead and obtain a lock to create it. - * This specifically doesn't lock as the first step to avoid all calls obtaining a lock from the cache if the item already exists in the DB. - */ - if (! $stamp) { - Cache::lock('process-stamps-hash-create-' . $hash, 10)->get(function () use (&$stamp, $hash, $process, $parent) { - $stamp = static::firstOrCreate(['hash' => $hash], [ - 'name' => trim($process['name']), - 'type' => $process['type'], - 'parent_id' => optional($parent)->getKey(), - ]); - }); - } + if (null === $stamp) { + throw new ModelNotFoundException(); + } - return $stamp; + return $stamp; + }, 25); } /** diff --git a/src/ProcessStampable.php b/src/ProcessStampable.php index 7c21832..6fa79eb 100644 --- a/src/ProcessStampable.php +++ b/src/ProcessStampable.php @@ -1,6 +1,6 @@