Skip to content

Commit fdb249b

Browse files
author
quentin.schmick
committed
Merged in master
2 parents dc4f4c9 + 41af928 commit fdb249b

File tree

13 files changed

+76
-52
lines changed

13 files changed

+76
-52
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
/tests export-ignore
1212
/.editorconfig export-ignore
1313
/.github export-ignore
14+
/docker export-ignore

.github/workflows/tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: tests
22

33
on:
44
push:
5+
pull_request:
56
schedule:
67
- cron: '0 0 * * *'
78

@@ -23,8 +24,9 @@ jobs:
2324
strategy:
2425
fail-fast: true
2526
matrix:
26-
php: [7.3, 7.4]
27-
stability: [prefer-lowest, prefer-stable]
27+
php: [7.3, 7.4, 8.0, 8.1]
28+
stability:
29+
- prefer-stable
2830

2931
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
3032

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Laravel Process Stamps
22

3-
[![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)
4-
[![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)
5-
[![Total Downloads](https://img.shields.io/packagist/dt/orisintel/laravel-process-stamps.svg?style=flat-square)](https://packagist.org/packages/orisintel/laravel-process-stamps)
3+
[![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)
4+
[![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)
5+
[![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)
6+
[![Maintainability](https://api.codeclimate.com/v1/badges/f7dfbbd4462347976259/maintainability)](https://codeclimate.com/github/always-open/laravel-process-stamps/maintainability)
67

78
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.
89

@@ -11,13 +12,13 @@ It is sometimes very useful to know which process created or modified a particul
1112
You can install the package via composer:
1213

1314
```bash
14-
composer require orisintel/laravel-process-stamps
15+
composer require always-open/laravel-process-stamps
1516
```
1617

1718
## Configuration
1819

1920
``` php
20-
php artisan vendor:publish --provider="\OrisIntel\ProcessStamps\ProcessStampsServiceProvider"
21+
php artisan vendor:publish --provider="\AlwaysOpen\ProcessStamps\ProcessStampsServiceProvider"
2122
```
2223

2324
Running the above command will publish both the migration and the config file.
@@ -59,13 +60,32 @@ That will generate the nessesary field names to track processes.
5960
composer test
6061
```
6162

63+
## Using Docker
64+
All assets are set up under the docker-compose.yml file. The first time you run the docker image you must build it with
65+
the following command:
66+
```bash
67+
docker-compose build
68+
```
69+
70+
Then you can bring it up in the background using:
71+
```bash
72+
docker-compose up -d
73+
```
74+
75+
And the image is aliased so you can access its command line via:
76+
```bash
77+
docker exec -it processes-stamp-app /bin/bash
78+
```
79+
80+
From there you can run the tests within an isolated environment
81+
6282
## Contributing
6383

6484
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
6585

6686
### Security
6787

68-
If you discover any security related issues, please email [[email protected]](mailto:[email protected]) instead of using the issue tracker.
88+
If you discover any security related issues, please email @tomschlick or @qschmick directly instead of using the issue tracker.
6989

7090
## Credits
7191

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
## Reporting a Vulnerability
44

5-
If you encounter what you believe to be a security vulnerability, please report it immediately to [email protected]. Please include your name, your email address, the url of the package, and a description of the suspected issue.
5+
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.

composer.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,23 @@
99
],
1010
"homepage": "https://github.com/always-open/laravel-process-stamps",
1111
"license": "MIT",
12-
"authors": [
13-
{
14-
"name": "Tom Schlick",
15-
"email": "[email protected]",
16-
"role": "Developer"
17-
}
18-
],
1912
"require": {
2013
"php": "^8.0.0|^8.1.0",
2114
"laravel/framework": "^9.0"
2215
},
2316
"require-dev": {
24-
"doctrine/dbal": "^3.3",
25-
"larapack/dd": "^1.0",
26-
"mockery/mockery": "~1.0",
17+
"doctrine/dbal": "^2.9|^3.0",
2718
"orchestra/testbench": "^7.0",
2819
"phpunit/phpunit": "^9.0"
2920
},
3021
"autoload": {
3122
"psr-4": {
32-
"OrisIntel\\ProcessStamps\\": "src"
23+
"AlwaysOpen\\ProcessStamps\\": "src"
3324
}
3425
},
3526
"autoload-dev": {
3627
"psr-4": {
37-
"OrisIntel\\ProcessStamps\\Tests\\": "tests"
28+
"AlwaysOpen\\ProcessStamps\\Tests\\": "tests"
3829
}
3930
},
4031
"scripts": {
@@ -48,7 +39,7 @@
4839
"extra": {
4940
"laravel": {
5041
"providers": [
51-
"OrisIntel\\ProcessStamps\\ProcessStampsServiceProvider"
42+
"AlwaysOpen\\ProcessStamps\\ProcessStampsServiceProvider"
5243
]
5344
}
5445
}

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ services:
44
build:
55
context: ./
66
dockerfile: ./docker/Dockerfile
7-
image: processstamps
8-
container_name: processstamps-app
7+
image: processes-stamp
8+
container_name: processes-stamp-app
99
restart: unless-stopped
1010
working_dir: /var/www/
1111
volumes:

src/ProcessStamp.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
namespace OrisIntel\ProcessStamps;
3+
namespace AlwaysOpen\ProcessStamps;
44

55
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\ModelNotFoundException;
67
use Illuminate\Database\Eloquent\Relations\BelongsTo;
78
use Illuminate\Database\Eloquent\Relations\HasMany;
89
use Illuminate\Support\Facades\Cache;
9-
use Illuminate\Support\Facades\DB;
1010

1111
class ProcessStamp extends Model
1212
{
@@ -42,6 +42,8 @@ public function getTable() : string
4242
* @param null|string $hash
4343
*
4444
* @return ProcessStamp
45+
*
46+
* @throws ModelNotFoundException
4547
*/
4648
public static function firstOrCreateByProcess(array $process, ?string $hash = null) : self
4749
{
@@ -59,23 +61,31 @@ public static function firstOrCreateByProcess(array $process, ?string $hash = nu
5961
$parent = static::firstOrCreateByProcess(static::getProcessName($process['type'], $process['parent_name']));
6062
}
6163

62-
$stamp = static::where('hash', $hash)->first();
64+
return retry(4, function() use ($hash, $process, $parent) {
65+
$stamp = static::firstWhere('hash', $hash);
66+
67+
/*
68+
* If stamp does not exist in the database yet, go ahead and obtain a lock to create it.
69+
* This specifically doesn't lock as the first step to avoid all calls obtaining a lock from the cache if
70+
* the item already exists in the DB.
71+
*/
72+
if (! $stamp) {
73+
Cache::lock('process-stamps-hash-create-' . $hash, 10)
74+
->get(function () use (&$stamp, $hash, $process, $parent) {
75+
$stamp = static::firstOrCreate(['hash' => $hash], [
76+
'name' => trim($process['name']),
77+
'type' => $process['type'],
78+
'parent_id' => optional($parent)->getKey(),
79+
]);
80+
});
81+
}
6382

64-
/*
65-
* If stamp does not exist in the database yet, go ahead and obtain a lock to create it.
66-
* 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.
67-
*/
68-
if (! $stamp) {
69-
Cache::lock('process-stamps-hash-create-' . $hash, 10)->get(function () use (&$stamp, $hash, $process, $parent) {
70-
$stamp = static::firstOrCreate(['hash' => $hash], [
71-
'name' => trim($process['name']),
72-
'type' => $process['type'],
73-
'parent_id' => optional($parent)->getKey(),
74-
]);
75-
});
76-
}
83+
if (null === $stamp) {
84+
throw new ModelNotFoundException();
85+
}
7786

78-
return $stamp;
87+
return $stamp;
88+
}, 25);
7989
}
8090

8191
/**

src/ProcessStampable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace OrisIntel\ProcessStamps;
3+
namespace AlwaysOpen\ProcessStamps;
44

55
use Illuminate\Database\Eloquent\Relations\BelongsTo;
66

src/ProcessStampsServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace OrisIntel\ProcessStamps;
3+
namespace AlwaysOpen\ProcessStamps;
44

55
use Illuminate\Database\Schema\Blueprint;
66
use Illuminate\Support\Arr;

tests/Fakes/Post.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace OrisIntel\ProcessStamps\Tests\Fakes;
3+
namespace AlwaysOpen\ProcessStamps\Tests\Fakes;
44

55
use Illuminate\Database\Eloquent\Model;
6-
use OrisIntel\ProcessStamps\ProcessStampable;
6+
use AlwaysOpen\ProcessStamps\ProcessStampable;
77

88
class Post extends Model
99
{

0 commit comments

Comments
 (0)