Skip to content

Commit 6b77dfd

Browse files
Updated docs
1 parent c200cc1 commit 6b77dfd

File tree

20 files changed

+226
-36
lines changed

20 files changed

+226
-36
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
11
# Artisan Command
2+
3+
Quite often, when working with actions, it becomes necessary to run one or another console command, and each time you have to write the following code:
4+
5+
```php
6+
use DragonCode\LaravelActions\Action;
7+
8+
return new class () extends Action
9+
{
10+
public function __invoke(): void
11+
{
12+
$this->artisan('some_command', [
13+
// parameters
14+
]);
15+
}
16+
};
17+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
11
# Events
2+
3+
You can also handle events when executing actions:
4+
5+
```
6+
DragonCode\LaravelActions\Events\ActionStarted
7+
DragonCode\LaravelActions\Events\ActionEnded
8+
DragonCode\LaravelActions\Events\ActionFailed
9+
DragonCode\LaravelActions\Events\NoPendingActions
10+
```
11+
12+
If there are no action files to execute, the `NoPendingActions` event will be sent.
13+
14+
In other cases, the `ActionStarted` event will be sent before processing starts, and the `ActionEnded` event will be sent after processing.
15+
16+
For example:
17+
18+
```php
19+
namespace App\Providers;
20+
21+
use App\Listeners\SomeActionsListener;
22+
use DragonCode\LaravelActions\Events\ActionEnded;
23+
use DragonCode\LaravelActions\Events\ActionStarted;
24+
use DragonCode\LaravelActions\Events\NoPendingActions;
25+
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
26+
27+
class EventServiceProvider extends ServiceProvider
28+
{
29+
protected $listen = [
30+
ActionStarted::class => [SomeActionsListener::class],
31+
ActionEnded::class => [SomeActionsListener::class],
32+
ActionFailed::class => [SomeActionsListener::class],
33+
NoPendingActions::class => [SomeActionsListener::class],
34+
];
35+
}
36+
```
37+
38+
```php
39+
namespace App\Listeners;
40+
41+
use DragonCode\LaravelActions\Events\BaseEvent;
42+
43+
class SomeActionsListener
44+
{
45+
public function handle(BaseEvent $event): void
46+
{
47+
$method = $event->method; // `up` or `down` string value
48+
$isBefore = $event->before; // boolean
49+
}
50+
}
51+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Execution Status
2+
3+
You can also override the `success` and `failed` methods, which are called on success or failure processing.
4+
5+
## If Success
6+
7+
```php
8+
use DragonCode\LaravelActions\Action;use Illuminate\Support\Facade\Log;
9+
10+
return new class () extends Action
11+
{
12+
public function up(): void
13+
{
14+
//
15+
}
16+
17+
public function down(): void
18+
{
19+
//
20+
}
21+
22+
public function success(): void
23+
{
24+
Log::info('success');
25+
}
26+
27+
public function failed(): void
28+
{
29+
Log::info('failed');
30+
}
31+
};
32+
```
33+
34+
Call the `php artisan migrate:actions` command.
35+
36+
The log file will contain two `success` entries.
37+
38+
## If Failed
39+
40+
```php
41+
use DragonCode\LaravelActions\Action;
42+
use Exeption;
43+
use Illuminate\Support\Facade\Log;
44+
45+
return new class extends Action
46+
{
47+
public function up(): void
48+
{
49+
throw new Exeption();
50+
}
51+
52+
public function down(): void
53+
{
54+
throw new Exeption();
55+
}
56+
57+
public function success(): void
58+
{
59+
Log::info('success');
60+
}
61+
62+
public function failed(): void
63+
{
64+
Log::info('failed');
65+
}
66+
};
67+
```
68+
69+
Call the `php artisan migrate:actions` command.
70+
71+
The log file will contain two `failed` entries.

docs/getting-started/helpers/execution-statuses.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/getting-started/how-to-use/creating.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ If you do not specify the "name" attribute, then the file name will be generated
2020
```bash
2121
php artisan make:migration:action
2222

23-
### When the git repository is found (`base_path('.git')` directory is exists).
24-
### For example, HEAD branch name is 'qwerty'.
23+
### When the git repository is found (`base_path('.git')` directory is exists) and HEAD branch name is 'qwerty'
2524
# 2022_10_11_225116_qwerty.php
2625
# 2022_10_11_225118_qwerty.php
2726
# 2022_10_11_225227_qwerty.php
2827

2928
### When the git repository is not found (`base_path('.git')` directory doesn't exists).
30-
### For example, HEAD branch name is 'qwerty'.
3129
# 2022_10_11_225116_auto.php
3230
# 2022_10_11_225118_auto.php
3331
# 2022_10_11_225227_auto.php

docs/getting-started/how-to-use/freshing.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/getting-started/how-to-use/refreshing.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/getting-started/how-to-use/resetting.md

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Rolling Back Actions
2+
3+
To roll back the latest action operation, you may use the `rollback` command. This command rolls back the last "batch" of actions, which may include multiple action files:
4+
5+
```
6+
php artisan migrate:actions:rollback
7+
```
8+
9+
You may roll back a limited number of actions by providing the `step` option to the rollback command. For example, the following command will roll back the last five actions:
10+
11+
```
12+
php artisan migrate:actions:rollback --step=5
13+
```
14+
15+
The `migrate:actions:reset` command will roll back all of your application's migrations:
16+
17+
```
18+
php artisan migrate:actions:reset
19+
```
20+
21+
## Roll Back & Action Using A Single Command
22+
23+
The `migrate:actions:refresh` command will roll back all of your migrations and then execute the `migrate:actions` command. This command effectively re-creates your entire
24+
database:
25+
26+
```
27+
php artisan migrate:actions:refresh
28+
```
29+
30+
You may roll back & re-migrate a limited number of migrations by providing the `step` option to the `refresh` command. For example, the following command will roll back &
31+
re-migrate the last five migrations:
32+
33+
```
34+
php artisan migrate:actions:refresh --step=5
35+
```
36+
37+
## Drop All Actions & Rerun Actions
38+
39+
The `migrate:actions:fresh` command will drop all actions records from the actions table and then execute the migrate command:
40+
41+
```
42+
php artisan migrate:actions:fresh
43+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Actions Status
2+
3+
The `migrate:actions:status` command displays the execution status of actions. In it you can see which actions were executed and which were not:
4+
5+
```
6+
php artisan migrate:actions:status
7+
```

0 commit comments

Comments
 (0)