Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit fceb0f2

Browse files
committed
Merge branch 'release/2.2.0'
2 parents 706ab90 + 615df51 commit fceb0f2

File tree

10 files changed

+51
-135
lines changed

10 files changed

+51
-135
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
.gitattributes export-ignore
66
.gitignore export-ignore
77
.travis.yml export-ignore
8-
gulpfile.js
98
nitpick.json export-ignore
109
phpunit.xml.dist export-ignore

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.1
1+
2.2.0

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
],
1717
"require": {
1818
"php": ">=7.2",
19-
"illuminate/console": "5.5.*|5.6.*|5.7.*|5.8.*",
20-
"illuminate/database": "5.5.*|5.6.*|5.7.*|5.8.*",
21-
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*",
19+
"illuminate/console": "5.5.*|5.6.*|5.7.*|5.8.*|6.0.*",
20+
"illuminate/database": "5.5.*|5.6.*|5.7.*|5.8.*|6.0.*",
21+
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*|6.0.*",
2222
"nesbot/carbon": "~1.20|^2.0",
2323
"psr/log": "^1.0"
2424
},
2525
"require-dev": {
2626
"mockery/mockery": "^1",
2727
"phpunit/phpunit": "~7.0.1|~8.0",
28-
"psy/psysh": "^0.5.1",
29-
"symfony/thanks": "^1.0",
30-
"symfony/var-dumper": "~3.0"
28+
"psy/psysh": "^0.9.9",
29+
"symfony/thanks": "^1.1",
30+
"symfony/var-dumper": "~3.0|^4.2"
3131
},
3232
"autoload": {
3333
"psr-4": {

gulpfile.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

phpunit.xml.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
verbose="true">
2020

2121
<testsuites>
22-
<testsuite name="Library Test Suite">
22+
<testsuite name="Spinen's Laravel Garbage Man">
2323
<directory>./tests/</directory>
2424
</testsuite>
2525
</testsuites>
@@ -32,7 +32,6 @@
3232
<whitelist>
3333
<directory suffix=".php">src/</directory>
3434
<exclude>
35-
<!--<file>src/file.php</file>-->
3635
<directory suffix=".php">src/config</directory>
3736
</exclude>
3837
</whitelist>

readme.md

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# SPINEN's Laravel Garbage Man
22

33
[![Latest Stable Version](https://poser.pugx.org/spinen/laravel-garbage-man/v/stable)](https://packagist.org/packages/spinen/laravel-garbage-man)
4-
[![Total Downloads](https://poser.pugx.org/spinen/laravel-garbage-man/downloads)](https://packagist.org/packages/spinen/laravel-garbage-man)
54
[![Latest Unstable Version](https://poser.pugx.org/spinen/laravel-garbage-man/v/unstable)](https://packagist.org/packages/spinen/laravel-garbage-man)
6-
[![Dependency Status](https://www.versioneye.com/php/spinen:laravel-garbage-man/0.1.1/badge.svg)](https://www.versioneye.com/php/spinen:laravel-garbage-man/0.1.1)
5+
[![Total Downloads](https://poser.pugx.org/spinen/laravel-garbage-man/downloads)](https://packagist.org/packages/spinen/laravel-garbage-man)
76
[![License](https://poser.pugx.org/spinen/laravel-garbage-man/license)](https://packagist.org/packages/spinen/laravel-garbage-man)
87

98
The soft deletes are great in Laravel to make sure that some deleted data can be recovered. This package allows you to configure an array of models with how many days that you want the soft deleted data to stay in the database.
@@ -17,7 +16,7 @@ The soft deletes are great in Laravel to make sure that some deleted data can be
1716

1817
## Prerequisite
1918

20-
#### NOTE: If you need to use < php7.2, please stay with version 1.x
19+
#### NOTE: If you need to use < PHP 7.2, please stay with version 1.x
2120

2221
As side from Laravel >= 5.1.10 (5.1.10 is the first version that had the warn method, so that is the minimum for logging), there is 1 package that is required.
2322

@@ -28,67 +27,67 @@ As side from Laravel >= 5.1.10 (5.1.10 is the first version that had the warn me
2827
Install Garbage Man:
2928

3029
```bash
31-
$ composer require spinen/laravel-garbage-man
30+
$ composer require spinen/laravel-garbage-man
3231
```
3332

34-
### For >= Laravel 5.5, you are done with the Install
33+
### For >= Laravel 5.5, you are done with the installation
3534

36-
The package uses the auto registration feature
35+
The package uses the [auto registration feature](https://laravel.com/docs/5.8/packages#package-discovery) of Laravel 5.
3736

3837
## Upgrading to 2.x from 1.x
3938

40-
As of Laravel 5.4, the `fire()` method on the dispatcher contract [was deprecated](https://laravel.com/docs/5.4/upgrade) in favor of `dispatch()`, and as of 5.8 the `fire()` method has been removed. Therefore, we have updated our code to use `dispatch()`. You will need to change `fire()` to `dispatch()` in your `config/garbageman.php` file.
39+
As of Laravel 5.8 (and deprecated in 5.4), the `fire()` method on the dispatcher contract [was removed](https://laravel.com/docs/5.8/upgrade) in favor of `dispatch()`. Therefore, we have updated our code to use `dispatch()`. You will need to change `fire()` to `dispatch()` in your `config/garbageman.php` file.
4140

4241
## Using the command
4342

4443
The command is registered with laravel as ```garbageman:purge```. You can run it one of 2 ways...
4544

4645
1. from the command line ```php artisan garbageman:purge;```
47-
2. via scheduled task.
46+
2. via a scheduled task.
4847

49-
To automatically run the script as a scheduled job, then add the following to the schedule method of
48+
To automatically run the script as a scheduled job, then add the following to the schedule method of
5049
`App\Console\Kernel.php`:
5150

5251
```php
53-
$schedule->command('garbageman:purge')
54-
->daily();
52+
$schedule->command('garbageman:purge')
53+
->daily();
5554
```
5655

57-
You can use whatever schedule that you need to keep the records purged out. Just review the list at
56+
You can use whatever schedule that you need to keep the records purged out. Just review the list at
5857
[http://laravel.com/docs/master/scheduling#schedule-frequency-options](http://laravel.com/docs/master/scheduling#schedule-frequency-options).
5958

60-
You can also use any of the advanced configuration options of the task scheduler like "Task Output" or "Task Hooks" as
59+
You can also use any of the advanced configuration options of the task scheduler like "Task Output" or "Task Hooks" as
6160
listed on the [Laravel documentation](http://laravel.com/docs/master/scheduling).
6261

6362
## Configuration
6463

6564
Publish the package config file to `config/garbageman.php`:
6665

6766
```bash
68-
$ php artisan vendor:publish
67+
$ php artisan vendor:publish
6968
```
7069

71-
This file is fully documented. You will need to make the changes to that file to suit your needs. There are 3 main configuration items...
70+
This file is fully documented. You will need to make the changes to that file to suit your needs. There are 3 main configuration items...
7271

7372
1. Dispatch purge events - Dispatch events on purge of each record.
7473
2. Logging level - Level to log.
75-
3. Schedule - Models & number of days to allow the soft deleted record to stay.
74+
3. Schedule - Models & number of days to allow the soft deleted record to stay before purging.
7675

7776
### Dispatch purge events (dispatch\_purge\_events)
7877

79-
Allow hook into the purge of each record by throwing events before & after deleting of each record. There are 2 events thrown:
78+
You may hook into the purge of each record by throwing events before & after deleting of each record. There are 2 events thrown:
8079

8180
* garbageman.purging:\<full/model/name\>
8281
* garbageman.purged:\<full/model/name\>
8382

84-
The model is passed with each of the events. The "purging" event is thrown just *before* the actual delete & "purged" is thrown just *after* the actual delete.
83+
The model is passed with each of the events. The "purging" event is thrown just *before* the actual delete & "purged" is thrown just *after* the actual deletion.
8584

86-
This is an expensive operation as it requires a SQL command for each record to delete so that the record can be thrown with the events. Therefore, unless you need to catch the events to preform some other action, leave this false to allow all records per model to get deleted with a single SQL call.
85+
**Please note:** This is an expensive operation as it requires a SQL command for each record to delete so that the record can be thrown with the events. Therefore, unless you need to catch the events to perform some other action, leave this false to allow all records per model to get deleted with a single SQL call.
8786

8887
### Logging level (logging_level)
8988

9089
The level that log messages are generated, which will display information on the console output and in the logs.
91-
90+
9291
| Level | Description |
9392
| :---: | ----------- |
9493
| 0 | Emergency: system is unusable |
@@ -99,14 +98,14 @@ The level that log messages are generated, which will display information on the
9998
| 5 | Notice: normal but significant condition |
10099
| 6 (default) | Info: informational messages |
101100
| 7 | Debug: debug - level messages |
102-
101+
103102
There is a key for the console & one for the log. Here is an example...
104103

105104
```php
106-
'logging_level' => [
107-
'console' => 3,
108-
'log' => 6,
109-
],
105+
'logging_level' => [
106+
'console' => 3,
107+
'log' => 6,
108+
],
110109
```
111110

112111
Alternatively, you can set the levels with environmental variables ```GARBAGEMAN_CONSOLE_LOG_LEVEL``` and ```GARBAGEMAN_LOG_LEVEL```.
@@ -116,9 +115,9 @@ Alternatively, you can set the levels with environmental variables ```GARBAGEMAN
116115
The age is in days for each model. Here is an example...
117116

118117
```php
119-
'schedule' => [
120-
App\ModelOne::class => 14,
121-
App\ModelTwo::class => 30,
122-
],
118+
'schedule' => [
119+
App\ModelOne::class => 14,
120+
App\ModelTwo::class => 30,
121+
],
123122
```
124123
This would purge any ModelOnes that were deleted over 14 days ago and any ModelTwos that were deleted over 30 days ago.

src/Commands/PurgeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected function purgeExpiredRecordsForModel($model, $days)
169169
return false;
170170
}
171171

172-
if (!method_exists($model, 'onlyTrashed') || !method_exists($model, 'forceDelete')) {
172+
if (!method_exists($model, 'forceDelete')) {
173173
$this->recordMessage(sprintf("The model [%s] does not support soft deleting.", $model), 'error');
174174

175175
return false;

tests/Commands/PurgeCommandTest.php

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
use Symfony\Component\Console\Input\InputInterface;
2020
use Symfony\Component\Console\Output\OutputInterface;
2121

22-
class PurgeCommandTests extends TestCase
22+
/**
23+
* Class PurgeCommandTest
24+
*
25+
* @package Spinen\GarbageMan\Commands
26+
*/
27+
class PurgeCommandTest extends TestCase
2328
{
2429
/**
2530
* @var Mockery\Mock
@@ -212,7 +217,7 @@ public function it_writes_a_comment_if_there_are_no_models_configured()
212217
* @test
213218
* @group unit
214219
*/
215-
public function it_warns_on_models_in_the_config_that_does_not_exists()
220+
public function it_warns_on_models_in_the_config_that_do_not_exist()
216221
{
217222
$this->config_mock->shouldReceive('get')
218223
->once()
@@ -290,72 +295,7 @@ public function it_warns_on_models_in_the_config_that_does_not_exists()
290295
* @test
291296
* @group unit
292297
*/
293-
public function it_errors_on_models_in_the_config_that_does_not_have_onlyTrashed()
294-
{
295-
$this->config_mock->shouldReceive('get')
296-
->once()
297-
->withArgs(
298-
[
299-
'garbageman.dispatch_purge_events',
300-
false,
301-
]
302-
)
303-
->andReturn(false);
304-
305-
$this->config_mock->shouldReceive('get')
306-
->once()
307-
->withArgs(
308-
[
309-
'garbageman.logging_level',
310-
[
311-
'console' => 6,
312-
'log' => 6,
313-
],
314-
]
315-
)
316-
->andReturn(
317-
[
318-
'console' => 6,
319-
'log' => 6,
320-
]
321-
);
322-
323-
$this->config_mock->shouldReceive('get')
324-
->once()
325-
->withArgs(
326-
[
327-
'garbageman.schedule',
328-
[],
329-
]
330-
)
331-
->andReturn(
332-
[
333-
'NoOnlyTrashed' => 14,
334-
]
335-
);
336-
337-
$this->log_mock->shouldReceive('error')
338-
->once()
339-
->with('The model [NoOnlyTrashed] does not support soft deleting.')
340-
->andReturnNull();
341-
342-
$this->output_mock->shouldReceive('writeln')
343-
->once()
344-
->withArgs(
345-
$this->checkVerbosity(
346-
'<error>The model [NoOnlyTrashed] does not support soft deleting.</error>'
347-
)
348-
)
349-
->andReturnNull();
350-
351-
$this->command->handle();
352-
}
353-
354-
/**
355-
* @test
356-
* @group unit
357-
*/
358-
public function it_errors_on_models_in_the_config_that_does_not_have_forceDelete()
298+
public function it_errors_on_models_in_the_config_that_do_not_have_forceDelete()
359299
{
360300
$this->config_mock->shouldReceive('get')
361301
->once()
@@ -598,7 +538,6 @@ public function it_deletes_all_expired_records_for_models_with_soft_delete_when_
598538
public function it_deletes_each_expired_record_for_models_and_throws_events_with_soft_delete_when_configured_to_dispatch_events(
599539
)
600540
{
601-
602541
$this->config_mock->shouldReceive('get')
603542
->once()
604543
->withArgs(

tests/GarbageManServiceProviderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
use Mockery;
99
use Spinen\GarbageMan\Commands\PurgeCommand;
1010

11+
/**
12+
* Class GarbageManServiceProviderTest
13+
*
14+
* @package Spinen\GarbageMan
15+
*/
1116
class GarbageManServiceProviderTest extends TestCase
1217
{
1318
/**

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Class TestCase
1414
*
15-
* @package Tests\Spinen\BrowserFilter
15+
* @package Tests\Spinen\GarbageMan
1616
*/
1717
abstract class TestCase extends PHPUnitTestCase
1818
{

0 commit comments

Comments
 (0)