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