diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 994523f0..f244dc94 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,8 +13,8 @@ jobs: strategy: fail-fast: false matrix: - php: ["8.0"] - laravel: ["^8.0"] + php: ["8.1", "8.0"] + laravel: ["^9.0", "^8.0"] dependency-version: [prefer-lowest, prefer-stable] name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} @@ -39,7 +39,7 @@ jobs: - name: Install dependencies run: | composer require "laravel/framework:${{ matrix.laravel }}" --dev --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/phpunit diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 00000000..fa56639f --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,28 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 373585ef..046e14c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `spatie/laravel-activitylog` will be documented in this file +## 4.4.0 - 2022-01-12 + +- allow Laravel 9 + ## 4.3.1 - 2021-10-20 - Fix hardcoded `deleted_at` column usage - [#965](https://github.com/spatie/laravel-activitylog/issues/965) @@ -24,7 +28,7 @@ All notable changes to `spatie/laravel-activitylog` will be documented in this f ## 4.0.0 - 2021-05-04 -PR: [#787](https://github.com/spatie/laravel-activitylog/pull/787) +PR: [#787](https://github.com/spatie/laravel-activitylog/pull/787) Special thanks to [Ahmed Nagi](https://github.com/nagi1). - Drop Laravel 6 and 7 support. @@ -32,7 +36,8 @@ Special thanks to [Ahmed Nagi](https://github.com/nagi1). - Add `LogOptions` configuration object to replace all configuration properties. - Add ability to batch activity logs [#560](https://github.com/spatie/laravel-activitylog/issues/560) - Add Pipeline to customize logged changes data. - - Deep diff array/JSON sub-keys and respect for only-dirty, no-empty ... [#692](https://github.com/spatie/laravel-activitylog/issues/692) using new pipeline. See implementation in the tests. +- - Deep diff array/JSON sub-keys and respect for only-dirty, no-empty ... [#692](https://github.com/spatie/laravel-activitylog/issues/692) using new pipeline. See implementation in the tests. +- - Implement a `CauserResolver` to define causer for current runtime [#582](https://github.com/spatie/laravel-activitylog/issues/582). ## 3.17.0 - 2021-03-02 @@ -200,6 +205,7 @@ Please use `v3.14.1` instead - this release is breaking because of the new colum - add `$logUnguarded` ## 3.0.0 - 2018-10-16 + - the preferred way to get changes on an `Activity` model is through the `changes` property instead of the `changes()` function - the `activity` relation of the `CausesActivity` trait has been renamed to `actions` - the `activity` relation of the `LogsActivity` trait has been renamed to `activities` @@ -209,151 +215,199 @@ Please use `v3.14.1` instead - this release is breaking because of the new colum - support for PHP 7.0 has been dropped ## 2.8.4. - 2018-09-23 + - improve migration ## 2.8.3 - 2018-09-01 + - add support for L5.7 ## 2.8.2 - 2018-07-28 + - allow `null` to be passed to `causedBy` ## 2.8.1 - 2018-07-28 + - make sure a fresh instance of `ActivityLogger` is used ## 2.8.0 - 2018-07-21 + - add `enableLogging()` and `disableLogging()` ## 2.7.0 - 2018-06-18 + - add ability to ignore changes to attributes specified in `$logAttributesToIgnore` ## 2.6.0 - 2018-04-03 + - add `table_name` config option ## 2.5.1 - 2018-02-11 + - improve support for soft deletes ## 2.5.0 - 2018-02-09 + - allow model to override the default log name ## 2.4.2 - 2018-02-08 + - add compatibility with L5.6 ## 2.4.1 - 2018-01-20 + - use a `text` column for `description` ## 2.4.0 - 2018-01-20 + - add `HasActivity` ## 2.3.2 - 2017-12-13 + - fix bugs concerning `attributesToBeLogged` ## 2.3.1 - 2017-11-13 + - allow nullable relation when using `logChanges` ## 2.3.0 - 2017-11-07 + - add a `log` argument to `activitylog:clean` ## 2.2.0 - 2017-10-16 + - add support for logging all changed attributes using `*` ## 2.1.2 - 2017-09-28 + - fix for logging changes attributes when deleting soft deletable models ## 2.1.1 - 2017-09-12 + - make sure `properties` always is a collection ## 2.1.0 - 2017-09-19 + - added support for logging fillable attributes ## 2.0.0 - 2017-08-30 + - added support for Laravel 5.5, dropped support for older laravel versions - renamed config file from `laravel-activitylog` to `activitylog` - rename `getChangesAttribute` function to `changes` so it doesn't conflict with Laravel's native functionality ## 1.16.0 - 2017-06-28 + - added `enableLogging` and `disableLogging` ## 1.15.5 - 2017-08-08 + - fix model scope ## 1.15.4 - 2017-08-05 + - fix detecting `SoftDeletes` ## 1.15.3 - 2017-06-23 + - fix for when there is no 'web' guard ## 1.15.2 - 2017-06-15 + - fixes errors in `DetectsChanges` ## 1.15.1 - 2017-04-28 + - fixes error in `DetectsChanges` ## 1.15.0 - 2017-04-28 + - add compatibility with L5.1 and L5.2 ## 1.14.0 - 2017-04-16 + - add support array/collection casted attributes when using `logDirtyOnly` ## 1.13.0 - 2017-04-16 + - add `logDirtyOnly` ## 1.12.2 - 2017-03-22 + - fix a bug where changes to a related model would not be logged ## 1.12.1 - 2017-02-12 + - avoid PHP error when dealing with placeholders that cannot be filled ## 1.12.0 - 2017-02-04 + - drop support for L5.2 and lower - add ability to log attributes of related models ## 1.11.0 - 2017-01-23 + - add support for L5.4 ## 1.10.4 - 2017-01-20 + - `Activity` now extends from `Model` instead of `Eloquent` ## 1.10.2 - 2016-11-26 + - fix compatibilty for Laravel 5.1 ## 1.10.1 - 2016-10-11 + - fix `scopeCausedBy` and `scopeForSubject` ## 1.10.0 - 2016-10-10 + - add support for `restored` event ## 1.9.2 - 2016-09-27 + - fixed a bug where the delete event would not be logged ## 1.9.1 - 2016-09-16 + - fixed the return value of `activity()->log()`. It will now return the created `Activity`-model. ## 1.9.0 - 2016-09-16 + - added `Macroable` to `ActivityLogger` ## 1.8.0 - 2016-09-12 + - added `causedBy` and `forSubject` scopes ## 1.7.1 - 2016-08-23 + - Added L5.3 compatibility ## 1.7.0 - 2016-08-17 + - Added `enabled` option in the config file. ## 1.6.0 - 2016-08-11 + - Added `ignoreChangedAttributes` ## 1.5.0 - 2016-08-11 + - Added support for using a custom `Activity` model ## 1.4.0 - 2016-08-10 + - Added support for soft deletes ## 1.3.2 - 2016-08-09 + - This version replaces version `1.3.0` - Dropped L5.1 compatibility ## 1.3.1 - 2016-08-09 + - this version removes the features introduced in 1.3.0 and is compatible with L5.1 ## 1.3.0 - 2016-07-29 @@ -361,10 +415,12 @@ Please use `v3.14.1` instead - this release is breaking because of the new colum **DO NOT USE THIS VERSION IF YOU'RE ON L5.1** Please upgrade to: + - `1.3.1` for Laravel 5.1 - `1.3.2` for Laravel 5.2 and higher Introduced features + - made the auth driver configurable ## 1.3.0 - 2016-07-29 diff --git a/README.md b/README.md index 0c197e5a..1c604ad8 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Activity::all(); ``` Here's a more advanced example: + ```php activity() ->performedOn($anEloquentModel) @@ -38,8 +39,7 @@ $lastLoggedActivity->getExtraProperty('customProperty'); //returns 'customValue' $lastLoggedActivity->description; //returns 'Look, I logged something' ``` - -Here's an example on [event logging](https://docs.spatie.be/laravel-activitylog/v4/advanced-usage/logging-model-events). +Here's an example on [event logging](https://spatie.be/docs/laravel-activitylog/advanced-usage/logging-model-events). ```php $newsItem->name = 'updated name'; @@ -77,7 +77,7 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh ## Documentation -You'll find the documentation on [https://docs.spatie.be/laravel-activitylog](https://docs.spatie.be/laravel-activitylog). +You'll find the documentation on [https://spatie.be/docs/laravel-activitylog/introduction](https://spatie.be/docs/laravel-activitylog/introduction). Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving the activity log? Feel free to [create an issue on GitHub](https://github.com/spatie/laravel-activitylog/issues), we'll try to address it as soon as possible. @@ -85,18 +85,19 @@ Find yourself stuck using the package? Found a bug? Do you have general question You can install the package via composer: -``` bash +```bash composer require spatie/laravel-activitylog ``` The package will automatically register itself. You can publish the migration with: + ```bash php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations" ``` -*Note*: The default migration assumes you are using integers for your model IDs. If you are using UUIDs, or some other format, adjust the format of the subject_id and causer_id fields in the published migration before continuing. +_Note_: The default migration assumes you are using integers for your model IDs. If you are using UUIDs, or some other format, adjust the format of the subject_id and causer_id fields in the published migration before continuing. After publishing the migration you can create the `activity_log` table by running the migrations: @@ -105,6 +106,7 @@ php artisan migrate ``` You can optionally publish the config file with: + ```bash php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-config" ``` @@ -119,7 +121,7 @@ Please see [UPGRADING](UPGRADING.md) for details. ## Testing -``` bash +```bash composer test ``` @@ -133,10 +135,10 @@ If you discover any security related issues, please email freek@spatie.be instea ## Credits -- [Freek Van der Herten](https://github.com/freekmurze) -- [Sebastian De Deyne](https://github.com/sebastiandedeyne) -- [Tom Witkowski](https://github.com/Gummibeer) -- [All Contributors](../../contributors) +- [Freek Van der Herten](https://github.com/freekmurze) +- [Sebastian De Deyne](https://github.com/sebastiandedeyne) +- [Tom Witkowski](https://github.com/Gummibeer) +- [All Contributors](../../contributors) And a special thanks to [Caneco](https://twitter.com/caneco) for the logo and [Ahmed Nagi](https://github.com/nagi1) for all the work he put in `v4`. diff --git a/composer.json b/composer.json index 423704f1..50178313 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "spatie/laravel-activitylog", "description": "A very simple activity logger to monitor the users of your website or application", + "license": "MIT", "keywords": [ "spatie", "log", @@ -8,8 +9,6 @@ "activity", "laravel" ], - "homepage": "https://github.com/spatie/activitylog", - "license": "MIT", "authors": [ { "name": "Freek Van der Herten", @@ -30,28 +29,21 @@ "role": "Developer" } ], + "homepage": "https://github.com/spatie/activitylog", "require": { "php": "^8.0", - "illuminate/config": "^8.0", - "illuminate/database": "^8.53", - "illuminate/support": "^8.0", + "illuminate/config": "^8.0 || ^9.0", + "illuminate/database": "^8.53 || ^9.0", + "illuminate/support": "^8.0 || ^9.0", "spatie/laravel-package-tools": "^1.6.3" }, "require-dev": { "ext-json": "*", - "orchestra/testbench": "^6.0", - "phpunit/phpunit": "^9.3" - }, - "config": { - "sort-packages": true - }, - "extra": { - "laravel": { - "providers": [ - "Spatie\\Activitylog\\ActivitylogServiceProvider" - ] - } + "orchestra/testbench": "^6.23 || ^7.0", + "phpunit/phpunit": "^9.5" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Spatie\\Activitylog\\": "src" @@ -65,8 +57,16 @@ "Spatie\\Activitylog\\Test\\": "tests" } }, - "minimum-stability": "dev", - "prefer-stable": true, + "config": { + "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "Spatie\\Activitylog\\ActivitylogServiceProvider" + ] + } + }, "scripts": { "test": "vendor/bin/phpunit" } diff --git a/docs/_index.md b/docs/_index.md index 6d4710d3..c0c68a9a 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -2,5 +2,5 @@ title: v4 slogan: Log the activities of your users githubUrl: https://github.com/spatie/laravel-activitylog -branch: master +branch: main --- diff --git a/docs/advanced-usage/batch-logs.md b/docs/advanced-usage/batch-logs.md index cbfcb085..d32d6bea 100644 --- a/docs/advanced-usage/batch-logs.md +++ b/docs/advanced-usage/batch-logs.md @@ -98,7 +98,7 @@ You may utilize `LogBatch::setBatch($uuid)` passing `$uuid` or any unique value Here's an example: ```php -use Spatie\Activitylog\LogBatch; +use Spatie\Activitylog\Facades\LogBatch; use Illuminate\Bus\Batch; use Illuminate\Support\Str; @@ -145,7 +145,7 @@ You can also batch activities using closure passed to `LogBatch::withinBatch()`. Here's an example: ```php -use Spatie\Activitylog\LogBatch; +use Spatie\Activitylog\Facades\LogBatch; LogBatch::withinBatch(function(string $uuid) { $uuid; // 5cce9cb3-3144-4d35-9015-830cf0f20691 diff --git a/docs/basic-usage/logging-activity.md b/docs/basic-usage/logging-activity.md index 7941b5c9..d4bb2be9 100644 --- a/docs/basic-usage/logging-activity.md +++ b/docs/basic-usage/logging-activity.md @@ -54,7 +54,7 @@ The `causedBy()`-function has a shorter alias named: `by()` If you're not using `causedBy()` the package will automatically use the logged in user. -If you don't want to associate a model as causer of activity, you can use `causedByAnonynmous()` (or the shorter alias: `byAnonymous()`). +If you don't want to associate a model as causer of activity, you can use `causedByAnonymous()` (or the shorter alias: `byAnonymous()`). ## Setting custom properties diff --git a/src/LogOptions.php b/src/LogOptions.php index 0ebc02c5..f7c7ba94 100644 --- a/src/LogOptions.php +++ b/src/LogOptions.php @@ -43,7 +43,7 @@ public function logAll(): self } /** - * log changes to all the $guarded attributes of the model. + * Log all attributes that are not listed in $guarded. */ public function logUnguarded(): self { diff --git a/src/Traits/LogsActivity.php b/src/Traits/LogsActivity.php index 11d4acf0..a02c834f 100644 --- a/src/Traits/LogsActivity.php +++ b/src/Traits/LogsActivity.php @@ -2,21 +2,21 @@ namespace Spatie\Activitylog\Traits; -use Carbon\CarbonInterval; use DateInterval; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\MorphMany; -use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Pipeline\Pipeline; +use Carbon\CarbonInterval; use Illuminate\Support\Arr; -use Illuminate\Support\Collection; use Illuminate\Support\Str; +use Illuminate\Pipeline\Pipeline; +use Illuminate\Support\Collection; +use Spatie\Activitylog\LogOptions; +use Spatie\Activitylog\EventLogBag; use Spatie\Activitylog\ActivityLogger; -use Spatie\Activitylog\ActivitylogServiceProvider; +use Illuminate\Database\Eloquent\Model; use Spatie\Activitylog\ActivityLogStatus; +use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Activitylog\Contracts\LoggablePipe; -use Spatie\Activitylog\EventLogBag; -use Spatie\Activitylog\LogOptions; +use Spatie\Activitylog\ActivitylogServiceProvider; +use Illuminate\Database\Eloquent\Relations\MorphMany; trait LogsActivity { @@ -48,6 +48,8 @@ protected static function bootLogsActivity(): void $model->activitylogOptions = $model->getActivitylogOptions(); if (! $model->shouldLogEvent($eventName)) { + $model->activitylogOptions = null; + return; } @@ -59,10 +61,14 @@ protected static function bootLogsActivity(): void // Submitting empty description will cause place holder replacer to fail. if ($description == '') { + $model->activitylogOptions = null; + return; } if ($model->isLogEmpty($changes) && ! $model->activitylogOptions->submitEmptyLogs) { + $model->activitylogOptions = null; + return; } @@ -295,7 +301,7 @@ function ($new, $old) { return $new === $old ? 0 : 1; } - // Handels Date intervels comparsons since php cannot use spaceship + // Handles Date interval comparisons since php cannot use spaceship // Operator to compare them and will throw ErrorException. if ($old instanceof DateInterval) { return CarbonInterval::make($old)->equalTo($new) ? 0 : 1;