1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace SmoothPhp\LaravelAdapter\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Contracts\Config\Repository; |
7
|
|
|
use SmoothPhp\Serialization\Exception\SerializedClassDoesNotExist; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class RebuildProjectionsCommand |
11
|
|
|
* @package SmoothPhp\LaravelAdapter\Console |
12
|
|
|
* @author Simon Bennett <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
final class RebuildProjectionsCommand extends Command |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The name and signature of the console command. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $signature = 'smoothphp:rebuild {--transactions}'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The console command description. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $description = 'Rebuild all projection'; |
29
|
|
|
|
30
|
|
|
/** @var Repository */ |
31
|
|
|
private $config; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* BuildLaravelEventStore constructor. |
35
|
|
|
* @param Repository $config |
36
|
|
|
*/ |
37
|
|
|
public function __construct(Repository $config) |
38
|
|
|
{ |
39
|
|
|
parent::__construct(); |
40
|
|
|
$this->config = $config; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Execute the console command. |
45
|
|
|
* |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
|
|
public function handle() |
49
|
|
|
{ |
50
|
|
|
foreach ($this->config->get('cqrses.pre_rebuild_commands') as $preRebuildCommand) { |
51
|
|
|
if (is_array($preRebuildCommand)) { |
52
|
|
|
$this->call(key($preRebuildCommand), current($preRebuildCommand)); |
53
|
|
|
} else { |
54
|
|
|
$this->call($preRebuildCommand); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->call( |
59
|
|
|
'smoothphp:project', |
60
|
|
|
[ |
61
|
|
|
'projections' => implode(',', $this->config->get('cqrses.rebuild_projections')), |
62
|
|
|
'--transactions' => $this->option('transactions'), |
63
|
|
|
] |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
foreach ($this->config->get('cqrses.post_rebuild_commands') as $postRebuildCommand) { |
67
|
|
|
if (is_array($postRebuildCommand)) { |
68
|
|
|
$this->call(key($postRebuildCommand), current($postRebuildCommand)); |
69
|
|
|
} else { |
70
|
|
|
$this->call($postRebuildCommand); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|